/* Easing */
jQuery.easing['easeout'] =function (x, t, b, c, d) {
	if (t==0) return b;
	if (t==d) return b+c;
	if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
	return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
} 


// get querystring ftom url
function queryString(parameter) { 
  var loc = location.search.substring(1, location.search.length);
  var param_value = false;
  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
      param_name = params[i].substring(0,params[i].indexOf('='));
      if (param_name == parameter) {
          param_value = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  if (param_value) {
      return param_value;
  }
  else {
      return false; //Here determine return if no parameter is found
  }
}


$(function() {
	
	$('#naslovna li:last').addClass('last'); // zadnji element liste nema margine

	/* CAROUSEL */
	$("#carousel").jCarouselLite({
		btnNext: ".naprijed",
		btnPrev: ".nazad",
		visible: 1,
		scroll: 1,
		speed: 1200,
		auto: 6000,
		circular: true,
		easing: 'easeout' 
	});
	
	/* NEWSLETTER */
	$('#newsletter .open').live("click", function () {
		$(this).removeClass('open').addClass('close');									 
		$('#container').animate({opacity: "0.1"}, 600 );
      $(this).parent().animate({ 
        marginLeft: "-550px"
      }, 1200, 'easeout' );
	  
    });
	
	$('#newsletter .close').live("click", function () {
		$(this).removeClass('close').addClass('open');	
		$(this).parent().animate({ 
        marginLeft: "-29px"
      }, 1200, 'easeout' );
		$('#container').animate({opacity: "1"}, 1000 );
    });
	
	
	/* MAIL */
	$("#contactform").submit(function() {
		$.post("/plugins/mail/anyform.php", $(this).serialize(), function(data){
   			$("#contactform span.msg").html(data);
 			});
  		return false;
	});
	
	
	//	Smooth scrolling to top
	$('.top a').click(function() {
		$('html, body').animate({
		scrollTop: $("body").offset().top
		}, 1000);
		return false;
		});
	
	// Highlight active liks
	var page = location.pathname.substring(4);
   getid = queryString('id') ;
   
   if ( page == "index.php" ){
	   $("#header li:first a").addClass("active");
   } else {
	    $('#navigacija li a[href$="' + "?id="+ getid + '"], #header li a[href$="' + "?id="+ getid + '"]').attr('class', 'active');
   
   }
   
   

});    








