$(document).ready(function(){
	Shadowbox.init({
		overlayColor: "#172d5f"	
	});
	
	$("#secondarymenu li:last").addClass("last");
	
	
	Cufon.replace('#mainmenu li a,h1,h2, .tabs li a', { fontFamily: 'univers' });
	
	$update = false;
	$('#mainmenu li a').hover(function(){
		Cufon.replace('#mainmenu li a', { fontFamily: 'univers' });
		$update=true;
	});
	
	$('.tabs li a').hover(function() {
		Cufon.replace('.tabs li a', { fontFamily: 'univers' });
		$update=true;
	});
	
	if ($('#impressionSlider').length) {
		$('#impressionSlider').nivoSlider({
			effect: 'fade',
			animSpeed: 500,
			pauseTime: 5000,
			controlNav: false,
			directionNavHide: false,
			prevText: '', 
			nextText: ''
		});
	}
	
	/* MARK tabjes detail page */
	
	$('.three-column .content-two-column .tabs li').click(function() {
		$(".three-column .content-two-column .tabs li.active").removeClass("active");
		$(this).addClass("active");
		
		setActive();
	});
	
	if($('.three-column .content-two-column .tabs').length > 0) {
		setActive();
	};
	
	if($('.acc_container').length > 0) {
		//Set default open/close settings
		$('.acc_container').hide(); //Hide/close all containers
		$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container
		
		//On Click
		$('.acc_trigger').click(function(){
			if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
				$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
				$(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
			}
			return false; //Prevent the browser jump to the link anchor
		});
	};	
	
	function setActive() {
		$('.content-table .productdetails').each(function() {
			if($(this).hasClass("coated-table")) {
				if ( $(".three-column .content-two-column .tabs li.active").text() == 'Gecoat' || $(".three-column .content-two-column .tabs li.active").text() == 'Coated') {
					
					$(this).show();
					
				} else {
					
					$(this).hide();
					
				}
			} else if ($(this).hasClass("uncoated-table")) {
				if ($(".three-column .content-two-column .tabs li.active").text() == 'Ongecoat' || $(".three-column .content-two-column .tabs li.active").text() == 'Uncoated') {
					
					$(this).show();
					
				} else {
					
					$(this).hide();
					
				}
			}
		});
		
		$('.xls-extra-line').each(function() {
			if ($(this).hasClass("coated-table")) {
				if ( $(".three-column .content-two-column .tabs li.active").text() == 'Gecoat' || $(".three-column .content-two-column .tabs li.active").text() == 'Coated') {
					
					$(this).show();
					
				} else {
					
					$(this).hide();
					
				}
			}
			else if ($(this).hasClass("uncoated-table")) {
				if ($(".three-column .content-two-column .tabs li.active").text() == 'Ongecoat' || $(".three-column .content-two-column .tabs li.active").text() == 'Uncoated') {
					
					$(this).show();
					
				} else {
					
					$(this).hide();
					
				}
			}
		})
	}
	
	
	$("body").mousemove(function(e){
		if($update==true){
			Cufon.replace('#mainmenu li a', { fontFamily: 'univers' });
			Cufon.replace('.tabs li a', { fontFamily: 'univers' });
		}
	});
	
	/*$('.slides').before('<ul id="nav">').cycle({ 
		fx:     'scrollHorz', 
		speed:  'slow', 
		timeout: 0, 
		prev:	 ".previous",
		next:	 ".next"
	});*/
	
	if($("#slider").length){
		$("#slider").easySlider({
			auto: true,
			continuous: true,
			pause: 7000,
			prevId: 'previous',
			prevText: '&nbsp;',
			nextId: 'next',
			nextText: '&nbsp;'
		});
	}
	
	/*$i = 0;
	$("#teaser .slides img").each(function(){
		$image = $(this).attr("src").match(/[^\.]+/);
		$alt = $(this).attr("alt");
		$("#teaser .overlay ul").append('<li><a href="javascript:void(0);" rel="'+$i+'" style="background-image:url('+$image+'-small-vf1.jpg);"><img src="'+$image+'-small-vf0.jpg" alt="'+$alt+'" /></a></li>');
		$i=$i+1;
	});*/
	
	$("#teaser .overlay ul a").click(function(){
		$number = parseInt($(this).attr("rel"));
		$('.slides').cycle($number);
	});
	
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName('a');
	for (var i = 0; i < anchors.length; i++) {
	 var anchor = anchors[i];
	 if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
		anchor.target = "_blank";
	 }
	}
	
	if($(".productDetailGallery").length){
		
		// Set number of slides
		var slides = $(".productDetailPaging a").size();
		
		// Set active on click
		$(".productDetailPaging a").click(function(){
			$(".productDetailPaging a").removeClass("activeImagePage");
			$(this).addClass("activeImagePage");
		});
		
		// Go one slide back
		$(".controls .prev").click(function(){
			var x = parseInt($(".productDetailPaging a.activeImagePage").attr("id").replace("paging", ""));
			if(x <= 1){
				var goTo = slides;
			} else {
				var goTo = x-1;
			}
			$(".productDetailPaging a#paging"+goTo).trigger('click');
		});
		
		// Go one slide forward
		$(".controls .next").click(function(){
			var x = parseInt($(".productDetailPaging a.activeImagePage").attr("id").replace("paging", ""));
			if(x >= slides){
				var goTo = 1;
			} else {
				var goTo = x+1;
			}
			$(".productDetailPaging a#paging"+goTo).trigger('click');
		});
		
		// Show zoom bubble
		$(".productDetailPaging .zoom").hover(function(){
			$(".productDetailPaging .zoomHover").css("display", "block");
		}, function(){
			$(".productDetailPaging .zoomHover").css("display", "none");
		});
		
	}
  
});

function setLink(t){
	$(".overlay").live("click", function(){
		var href = $("#slider ul li:eq("+(t+1)+") a").attr("href");
		window.location.href = href;
	});
}
