var activeProduct, newProduct, numproducts;

function resetSlidey() {
	if ($(".scroll").html() != null) {
		if ($(".scroll").scrollLeft() > 0) {
			$(".scroll").scrollLeft(0);
		}
	}
	if ($(".scroll .wrapper").html() != null) {
		if ($(".scroll .wrapper").scrollLeft() > 0) {
			$(".scroll .wrapper").scrollLeft(0);
		}
	}
}

/*--------------------------- Product Pop ----------------------------*/

function prodPop(defaultParam, thisProduct) {

	if(thisProduct){
	} else {
		thisProduct = $(this);
	}
		
	// id is in the form "productboxpop_[product]"
	newProduct = thisProduct.children(".container").attr("id").substring(5);

	// Only kick off billboard slidey if selecting a non-active product;
	if(newProduct == activeProduct)
		return true;
	
	var productboxpop, continutpachet;
	
	numproducts = thisProduct.parent("div").hasClass("four") && 4 || thisProduct.parent("div").hasClass("three") && 3 || 	thisProduct.parent("div").hasClass("two") && 2 || 5;

	
	// Reset active productboxpop display and functionality
	if(activeProduct) {
		productboxpop = $("#prod_" + activeProduct).parent("div");
		
		productboxpop.removeClass("PachetHostingHov");
		productboxpop.find(".fs-mini").addClass("fs-minuscul").removeClass("fs-mini");
		productboxpop.find(".fs-mic").addClass("fs-mini").removeClass("fs-mic");
		productboxpop.find(".fs-normal").addClass("fs-mic").removeClass("fs-normal");
		productboxpop.find(".fs-maimare").addClass("fs-mare").removeClass("fs-maimare");
		productboxpop.find(".fs-fmare").addClass("fs-maimare").removeClass("fs-fmare");
		productboxpop.find(".lh-normal").addClass("lh-mic").removeClass("lh-normal");
		productboxpop.find(".lh-mare").addClass("lh-normal").removeClass("lh-mare");
	}
	
	productboxpop = thisProduct;	
	prodActivate(productboxpop, newProduct);
	
}
function prodUnPop() {
	
};

function prodActivate(productboxpopId, newProduct) {

	productboxpop = $(productboxpopId);
	activeProduct = newProduct;

	productboxpop.addClass("PachetHostingHov");	

	if (productboxpop.hasClass("initial")) {
		productboxpop.removeClass("initial");
		
		// Assign dynamic height to shadows
		$(".PachetHosting .shadow .ml, .PachetHosting .shadow .mr").height($(productboxpop).height()-7);
		$(".PachetHosting .shadow .tc, .PachetHosting .shadow .bc").width($(productboxpop).width()-18);
		
		// find position of the product within the billboard and adjust 
		// (no slide on initial load)
		var container = $(".billboard");
		$.each( container.find(".section"), function(i, n){
			$(n).attr("rel",i);
		});
		var width = container.width();
		var z = $("#bb_" + newProduct).attr("rel");
		var cnt = - (width*z);
		if (isNaN(cnt)) cnt = 0;
		if(cnt != 0) $(".billboard .content").css("left",cnt);
	} else {
		$(".billboard").slideTo("#bb_" + newProduct);
	}
	
	numproducts = productboxpop.parent("div").hasClass("four") && 4 || productboxpop.parent("div").hasClass("three") && 3 || 	productboxpop.parent("div").hasClass("two") && 2 || 5;

	productboxpop.children("div.shadow").show();
	productboxpop.find(".lh-normal").addClass("lh-mare").removeClass("lh-normal");	
	productboxpop.find(".lh-mic").addClass("lh-normal").removeClass("lh-mic");
	productboxpop.find(".fs-maimare").addClass("fs-fmare").removeClass("fs-maimare");
	productboxpop.find(".fs-mare").addClass("fs-maimare").removeClass("fs-mare");
	productboxpop.find(".fs-mic").addClass("fs-normal").removeClass("fs-mic");	
	productboxpop.find(".fs-mini").addClass("fs-mic").removeClass("fs-mini");
	productboxpop.find(".fs-minuscul").addClass("fs-mini").removeClass("fs-minuscul");

	return true;
}

/*-------------------------- Image Preload -----------------------------*/
/*
*jQuery.preloadImages = function() {
*	var prefix = "";
*	//only use akamai for http
*	if(location.protocol == 'http:')
*		prefix = "http://http://www.hostzilla.ro/imagini/gazduire/pachete";
*	
*	for(var i = 0; i<arguments.length; i++)	{
*		jQuery("<img>").attr("src", prefix + arguments[i]);
*	}
*}
*/
/*-------------------------- Flippy ----------------------------*/

jQuery.fn.setFlippy = function(body_height) {
	var container = jQuery(this);
	container.find("li").addClass("flip");
	container.find("li").not(".active").children(".body").css("height", "0px").css("overflow","hidden").hide();
	container.find("li.active").children(".body").css("height",body_height);
	container.find(".title").hoverIntent({
   sensitivity: 25, 
   interval: 100, 
   over: function() {
		var target = $(this).parent();
		var target_parent = target.parent();
		if (!target.hasClass("active")) {
			if (target_parent.find(".active_old").html() != null) {
				target_parent.find(".active").children(".body").stop();
				target_parent.find(".active_old").children(".body").height(0).hide();
				target_parent.find(".active").children(".body").height(body_height);
				target_parent.find(".active_old").removeClass("active_old");				
			}
			target_parent.find(".active").addClass("active_old").removeClass("active");
			target.addClass("active");	
			target.children(".body").animate({height:body_height}, {
				step: function(now, fx) {
					target_parent.find(".active_old").children(".body").height(body_height - (now));
				},
				duration: 300,
				complete: function() {
					target_parent.find(".active_old").children(".body").hide();
					target_parent.find(".active_old").removeClass("active_old");
				}
			});
		}		
	 }, 
   timeout: 100, 
   out: function() {} 
	});	
}


/*-------------------------- Slidey ----------------------------*/

jQuery.fn.slideTo = function(target_id, settings) {
	settings = jQuery.extend({
     easeTime: 400
  }, settings);
	var container = jQuery(this);
	$.each( container.find(".section"), function(i, n){
		$(n).attr("rel",i);
	});
	var width = container.width();
	var z = $(target_id).attr("rel");
	var cnt = - (width*z);
	if (isNaN(cnt)) cnt = 0;

	container.find(".itab_content").animate({left:cnt}, {
		duration: 600,
		easing: "easeInOutQuint",
		complete: function() {
			var left = $(this).css("left");
			var distance = left.split("px");
			if (distance[0] > -500) $(this).css("left",0);
		}
	});		
}
