/* Specifications are hidden */
$(document).ready(function(){
	$(".catalogProductImageLargeContainer").hide();	
	$(".showSpecifications").show().click(function(){
		$(this).hide();
		$(".hideSpecifications").show();
		$(".catalogProductImageLargeContainer").show();
		$(".catalogProductDetails .catalogProductImageBox").redrawShadow();
		return false;
	});
	$(".hideSpecifications").click(function(){
		$(this).hide();
		$(".showSpecifications").show();
		$(".catalogProductImageLargeContainer").hide();
		$(".catalogProductDetails .catalogProductImageBox").redrawShadow();
		return false;
	});
	$("#callbackform label + input, #callbackform label + textarea").each(function (i) {
		var newLabel = $(this).prev().clone();
		newLabel.find('span').remove();
		$(this).watermark(newLabel.html());
	});
	$("#callbackform input + span.captcha_text").each(function (i) {
		var newLabel = $(this).clone();
		newLabel.find('span').remove();
		$(this).prev().watermark(newLabel.html());
	});
	$("callbackform label.watermark + input.captcha").prev().addClass("captcha_text");
	if ( $("p.error").length > 0 ) {
		
		$("p.error").click(function(){
			$(this).fadeOut('slow');
		}).bind("mouseleave", function(){
			$(this).fadeOut('slow');
		});
		$.scrollTo('p.error');
	}

});

/* menu IE6 functionality */
$(document).ready(function(){
	$("#mainNavigation").bind("mouseenter", function(){
		$(this).css('zIndex', '99999');
	});
	$("#mainNavigation li").bind("mouseenter", function(){
		$(this).addClass('hover');
	});
	$("#mainNavigation li").bind("mouseleave", function(){
		$(this).removeClass('hover');
	});
});

/* popular products */
$(document).ready(function(){
	$("#popularProducts .tabSwitch p").click(function(){
		togglePopularProducts();
		return false;
	});
	
	$("#hideProducts").click(function(){
		togglePopularProducts();
		return false;
	});
});

function togglePopularProducts() {
	if ($("#popularProducts").hasClass('shown')) {
		// hide
		$("#popularProducts").removeClass('shown');
		$("#popularProducts .content").animate({height:"0"}, 300).hide();
		$("#popularProducts .tabSwitch h1").css('position', 'absolute').animate({fontSize:"12px", opacity: 1, marginTop: "0"}, 300);
		$("#popularProducts .tabSwitch p").fadeIn(1000);
	} else {
		// show
		$("#popularProducts").addClass('shown');
		$("#popularProducts .tabSwitch h1").css('position', 'absolute').animate({fontSize:"90px", opacity: 0.05, marginTop: "16px"}, 300);
		$("#popularProducts .content").show().animate({height:"96px"}, 300);
		$("#popularProducts .tabSwitch p").fadeOut('normal');
	}
}

/* Shadows */
$(document).ready(function(){
	$(".catalogProductDetails .catalogProductImageBox").dropShadow({left: 0, top: 2, opacity: 0.8, blur: 2, color: "#000"});
	$(".catalogProductList .catalogProductImageBox").dropShadow({left: 0, top: 1, opacity: 0.2, blur: 1, color: "#000"});
/*	$("#documentContainer").dropShadow({left: 0, top: 3, opacity: 1.0, blur: 1, color: "#000"});	*/
});

/* lightbox functionality */
$(document).ready(function(){
	$("a[rel*=lightbox]").lightbox();
});

/* weird back buttons fix */
$(document).ready(function(){
	var browserName = navigator.userAgent.toLowerCase(); 
	if (
		( history.length == 0 ) ||
		( (browserName.indexOf('firefox') > -1) && (history.length <= 1) ) ||
		( (browserName.indexOf('chrome') > -1) && (history.length < 2) )
		) {
		$("p.back").hide();
	} else {
		$("p.back a").click(function(){
			history.back();
			return false;
		});
	}
});

/* active menu */
var delay = 1;
var setMenuTimer = null;
var menuItem = null;
$(document).ready(function(){
	$("#mainNavigation .trail").addClass('originalTrail');
	$("#mainNavigation .active").addClass('originalActive');
	$("#mainNavigation .level_1 > li").bind("mouseenter", function(){
		clearTimeout(setMenuTimer);
		if ($(this).hasClass('originalTrail') || $(this).hasClass('originalActive')) {
			resetMenu();
		} else {
			menuItem = $(this);
			if ( delay == 1 ) {
				delay = 0;
				setMenuTimer = setTimeout("setMenu()", 300);
			} else {
				setMenu();
			}
		}
	});
	$("#mainNavigation").bind("mouseleave", function(){
		if ($(".originalTrail").hasClass('trail') || $(".originalActive").hasClass('active')) {
			clearTimeout(setMenuTimer);
			resetMenu();
		} else {
			setMenuTimer = setTimeout("resetMenu()", 3500);
		}
		delay = 1;
	});
});

function setMenu() {
	$("#mainNavigation .trail").removeClass('trail');
	$("#mainNavigation .active").removeClass('active');
	menuItem.addClass('active');
}

function resetMenu() {
	$("#mainNavigation .trail").removeClass('trail');
	$("#mainNavigation .active").removeClass('active');
	$("#mainNavigation .originalTrail").addClass('trail');
	$("#mainNavigation .originalActive").addClass('active');
}

/* active portfolio */
var apCycle = '';
var apZindex = 800;
function activePortfolioNext(timeout) {
	if ( apZindex > 990 ) {
		apZindex = 800;
	}
	
	var current = $('#activePortfolio .menu .active');
	var next = $('#activePortfolio .menu .active').next();
	if ( next.length > 0 ) {
		next.addClass('active');
	} else {
		next = $('#activePortfolio .menu li:first').addClass('active');
	}
	current.removeClass('active');
	$('#' + next.attr('id') + 'Contents').css('zIndex', apZindex++).css('marginLeft', '-500px').animate({marginLeft:'0px'},'slow');
	
	clearTimeout(apCycle);
	apCycle = setTimeout("activePortfolioNext(6000)", timeout);

}

function setActivePortfolio(portfolioItemId) {
	if ( apZindex > 990 ) {
		apZindex = 800;
	}
	
	var current = $('#activePortfolio .menu .active');
	var next = $('#' + portfolioItemId);
	if ( (current.attr('id') != next.attr('id')) && (next.length > 0) ) {
		clearTimeout(apCycle);
		current.removeClass('active').css('zIndex', apZindex);
		next.addClass('active');
		$('#' + next.attr('id') + 'Contents').css('zIndex', apZindex++).css('marginLeft', '-500px').animate({marginLeft:'-1px'},'slow');
	}	
}

$(document).ready(function(){
	if ( $('#activePortfolio').length > 0 ) {
		$("#activePortfolio .contents .block").bind("mouseenter", function(){
			clearTimeout(apCycle);
		});
		$("#activePortfolio .contents .block").bind("mouseleave", function(){
			apCycle = setTimeout("activePortfolioNext(9000)", 9000);
		});
		$('#activePortfolio .menu li').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		});
		$('#activePortfolio .menu li').click(function(){
			clearTimeout(apCycle);
			setActivePortfolio($(this).attr('id'));
			apCycle = setTimeout("activePortfolioNext(9000)", 9000);
		});
		$('#activePortfolio .contents .block:first').css('zIndex', apZindex++);
		clearTimeout(apCycle);				
		apCycle = setTimeout("activePortfolioNext(9000)", 9000);
	}
});

