/*
	Gadżety3M - JavaScripts
	gka@emarketingexperts.pl / www.emarketingexperts.pl
	v1.0.0, 24.08.2007
*/

function initInputLabelFromLabel(input_id,label_id) {
	var text = $(label_id).text(); 
	$(input_id).val(text);
	$(input_id).focus( function() {
		if ($(this).val() == text) {
			$(this).val("");
		}
	} );
	  $(input_id).blur( function() {
		if ($(this).val() == '') {
			$(this).val(text);
		}
	} );
}

function initBack() {
	$("#back").click(function() {
		history.back();
		return false;
	});
}

function initPrint() {
	$("#print").click(function() {
		window.print();
		return false;
	});
}

function hideAllProducts(i) {
	$("#products .content").not(i).hide();
	$("#nav-products a").not(i).removeClass();
}

function showNextProduct(i,productsQuantity,delay) {
	i++;
  	hideAllProducts(i);
	$("#products .content").eq(i).animate({ height: 'show', opacity: 'show' }, 1000, function() {
		if (i==productsQuantity-1) i=-1;
		animation = setTimeout("showNextProduct('"+i+"','"+productsQuantity+"','"+delay+"')",delay); 
		$("#nav-products a").click( function() { clearTimeout(animation); });
		$("#products .content p.more a").click( function() { clearTimeout(animation); });
	});
	$("#nav-products a").eq(i).addClass("active");
}

function initProductsInfo() {
	$("#products .content").css("display","none");
	$("#nav-products a").each( function(i) {
		$(this).click( function() {
			hideAllProducts(i);
			$("#products .content").eq(i).show();
			$(this).addClass("active");
			return false;
		});
	});
	var productsQuantity = $("#nav-products a").length;
	var j = -1;
	var delay = 4000;
  	showNextProduct(j,productsQuantity,delay);
}

function initialize() {
	initInputLabelFromLabel("#newsletter","#newsletter_l");
	initProductsInfo();
	initBack();
	initPrint();
}

$(document).ready(initialize);
