$(document).ready(function() {

setTimeout( function() {
	$('a.line_1')
	.animate({ 
	    left: "15px"
	}, 800 );
}, 100);

setTimeout( function() {
	$('a.line_2')
	.animate({ 
	    left: "15px"
	}, 800 );
}, 1500);

//Non-Plugin Function
var doBlink = function(obj,start,finish) { jQuery(obj).fadeOut(500).fadeIn(500); if(start!=finish) { start=start+1; doBlink(obj,start,finish); } }

//jQuery Blink Plugin
jQuery.fn.blink = function(start,finish) { return this.each(function() { doBlink(this,start,finish) }); }


//Example: Without Plugin (Will Blink Eight Times)
doBlink("#myObject",1,8);

setTimeout( function() {
	doBlink('a.line_2',1,5);
}, 2500);


/*
    if ($.browser.msie) {
        $('option').click(function () {
            $(this).blur();
            $(this).focus();
        });
    }
*/

/*
	$("#qtranslate-chooser li").eq(6).css("display","none");
	$("#qtranslate-chooser li").eq(7).css("display","none");
*/

/*
  	$('.anythingSlider').anythingSlider({
        easing: "easeInOutExpo",
        autoPlay: true,                 
        delay: 5000,
        startStopped: false,
        animationTime: 1000,
        hashTags: true,
        buildNavigation: false,
    	pauseOnHover: false
    });
*/

	$('#slider_1 ul, #slider_2 ul').roundabout()
	.hover(
		function() {
			clearInterval(interval);
		},
		function() {
			interval = startAutoPlay();
		}
	);

	interval = startAutoPlay();
	
	function startAutoPlay() {
		return setInterval(function() {
			$('#slider_1 ul, #slider_2 ul').roundabout_animateToNextChild();
		}, 3000);
	}
				
				
	$('#slider').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		slices:10, 
		animSpeed:1000, //Slide transition speed
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
      	controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});

	setTimeout(function(){ 
	$(".content_description_category").each(function(index) {
    	height_txt = $(this).children(".category_description").height();
    	height_img = $(this).children("img").height();
    	height_box = $(this).height();
    	if(height_box < height_txt){
    		$(this).height(height_txt);
    	}else{
    		$(this).height(height_img);
    	}
 	});
	}, 500);
	
	$("#press div:last-child").css("border","none");

	$("#category_select_list_category_waranty select, #category_select_list_country select").bind("change", function(){
		waranty_onchange();
	});	
	
	$("#category_select_list_category_waranty_2 select, #category_select_list_country_2 select").bind("change", function(){
		waranty2_onchange();
	});
	
	$("#category_select_list").children('select').change(function(){
        $(this).blur();
        $(this).focus();	
		element = $(this).children('option:selected');		
		if(!element.hasClass('list_cat')){
			id = element.attr("id");
			//var id = $(this).attr("id");
			mySplitResult = id.split("_");
			myID =  mySplitResult[1];
			$(".product_select_list").hide();
			$("#product_"+myID).fadeIn('slow');
			$("#arrow").fadeIn('slow');
			if($("#desctiption_owners_manuals").is(":hidden")){
			}else{
				$("#desctiption_owners_manuals").fadeOut('slow');
			}
		}else{
			$("#desctiption_owners_manuals").fadeOut('slow');
			$(".product_select_list").fadeOut('slow');
			$("#arrow").fadeOut('slow');		
		}
	});
	
	$(".product_select_list select").change(function(){
		var id = $(this).children('option:selected').attr("id");
		var mySplitResult = id.split("_");
		var myID =  mySplitResult[1];
		get_product(myID);
	});
	
	$(".product_select_list_for_consumables select").change(function(){
		var id = $(this).children('option:selected').attr("id");
		var mySplitResult = id.split("_");
		var myID =  mySplitResult[1];
		get_consumables(myID);
	});
	
	$("#category_select_list_consumables").children('select').change(function(){
        $(this).blur();
        $(this).focus();	
		element = $(this).children('option:selected');		
		if(!element.hasClass('list_cat')){
			id = element.attr("id");
			//var id = $(this).attr("id");
			mySplitResult = id.split("_");
			myID =  mySplitResult[1];
			$(".product_select_list_for_consumables").hide();
			$("#product_"+myID).fadeIn('slow');
			$("#arrow").fadeIn('slow');
			if($("#description_consumables").is(":hidden")){
			}else{
				$("#description_consumables").fadeOut('slow');
			}
		}else{
			$("#description_consumables").fadeOut('slow');
			$(".product_select_list_for_consumables").fadeOut('slow');
			$("#arrow").fadeOut('slow');		
		}
	});
	
	
	$(document).pngFix();
	
	$('.menu li li:last-child').css("border","none");
	$('.dropdownCountry dd ul li:last-child').css("padding-bottom","7px");
	$('.dropdownLanguage dd ul li:last-child').css("padding-bottom","7px");
	$('#faq .faq_block_content:last-child').css("border-bottom","1px solid #CACACA");

	
	$("ul.sf-menu").superfish({ 
	    delay:       1000,
	    animation:   {height:'show'},
	    speed:       200,
	    autoArrows:  true,
	    dropShadows: false
	});  
	
	/* $("ul.sf-menu").supersubs({ 
	    minWidth:    16,   // minimum width of sub-menus in em units 
	    maxWidth:    35,   // maximum width of sub-menus in em units 
	    extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
	                       // due to slight rounding differences and font-family 
	}).superfish({ 
	    delay:       1000,
	    animation:   {height:'show'},
	    speed:       200,
	    autoArrows:  true,
	    dropShadows: false
	}); */ 
	
	$(".dropdownLanguage dt a").hover(function() {
	    $(".dropdownLanguage dd ul").slideDown('normal', function(){
	    	$(this).mouseleave(function(){
	    		$(this).slideUp();
	    	});
	    });
		//setTimeout(function(){ $(".dropdownLanguage dd ul").slideUp(); }, 4000);
	});
	            
	$(".dropdownLanguage dd ul li a").click(function() {
	    $(".dropdownLanguage dd ul").slideUp();
	    var value = $(this).html();
	    $(".dropdownLanguage dt a").html(value);
	});
	            
	function getSelectedValue(id) {
	    return $("#" + id).find(".dropdownLanguage dt a span.value").html();
	}
	
	$(document).bind('click', function(e) {
	    var $clicked = $(e.target);
	    if (! $clicked.parents().hasClass("dropdownLanguage"))
	        $(".dropdownLanguage dd ul").hide();
	});
		
	$(".dropdownCountry dt a").hover(function() {
	    $(".dropdownCountry dd ul").slideDown('normal', function(){
	    	$(this).mouseleave(function(){
	    		$(this).slideUp();
	    	});
	    });	
	});
	            
	$(".dropdownCountry dd ul li a").click(function() {
	    $(".dropdownCountry dd ul").slideUp();
	    var value = $(this).html();
	    $(".dropdownCountry dt a").html(value);
	});
	            
	function getSelectedValue(id) {
	    return $("#" + id).find(".dropdownCountry dt a span.value").html();
	}
	
	$(document).bind('click', function(e) {
	    var $clicked = $(e.target);
	    if (! $clicked.parents().hasClass("dropdownCountry"))
	        $(".dropdownCountry dd ul").hide();
	});
		
	$("#page_content h3").eq(0).css('margin-top', '0px');
	$("#tabs-1 h3").eq(0).css('margin-top', '0px');
	$("#tabs-2 h3").eq(0).css('margin-top', '0px');
	$("#tabs-3 h3").eq(0).css('margin-top', '0px');

	$("li.page-item-38 a").eq(0).attr('href', '#');
	$("li.page-item-41 a").eq(0).attr('href', '#');
	$("li.page-item-655 a").eq(0).attr('href', '#');
	$("li.page-item-2942 a").eq(0).attr('href', '#');
	
	$('.menu').corner("round top 7px").parent().css('padding', '1px').corner("round top 7px");
	$('#title_available_now').corner("round top 7px").parent().css('padding', '1px').corner("round top 7px");
	$('#imageHome').corner("bottom 7px");
	$('.vicks_gentle_touch').corner("bottom 7px");
	$('.dropdownLanguage dd ul li:last-child').corner("bottom 7px");
	$('.dropdownLanguage dd ul li:last-child a').corner("bottom 7px");
	$('.dropdownLanguage dd ul li:last-child a span').corner("bottom 7px");
	$('.dropdownCountry dd ul li:last-child').corner("bottom 7px");
	$('.dropdownCountry dd ul li:last-child a').corner("bottom 7px");
	$('.dropdownCountry dd ul li:last-child a span').corner("bottom 7px");
	$('#tagImageHome').corner("tr bl 7px");
	$('#vicksBraun').corner("7px");
	$('#honeywell').corner("7px");
	$('#vicksBraun_2').corner("7px");
	$('#honeywell_2').corner("7px");
	$('#lifestyle_background').corner("7px").parent().css('padding', '1px').corner("7px");
	$('#product_content').corner("7px").parent().css('padding', '1px').corner("7px");
	$('h3#product_title').corner("tl 7px");
	$('#product_visual').corner("bl 7px");
	$('#product_info').corner("br tr 7px");
	$('#tabs #ulTabs').corner("top 7px");
	$('h1#page_title').corner("top 7px");
	$('#product_info #ulTabs').corner("tr 7px");
	$('.tab_section').corner("bottom 7px").parent().css('padding', '1px').corner("bottom 7px");
	$('#page_content').corner("bottom 7px").parent().css('padding', '1px').corner("bottom 7px");
	$('h3.sidebar_block_title').corner("top 7px");
	$('.sidebar_block_content_1').corner("bottom 7px").parent().css('padding', '1px').corner("bottom 7px");
	$('.sidebar_block_content_2').corner("bottom 7px").parent().css('padding', '1px').corner("bottom 7px");
	$('.sidebar_block_content_3').corner("bottom 7px").parent().css('padding', '1px').corner("bottom 7px");
	$('.sidebar_block_content_4').corner("bottom 7px").parent().css('padding', '1px').corner("bottom 7px");
	$('.sidebar_block_content_5').corner("bottom 7px").parent().css('padding', '1px').corner("bottom 7px");
	$('#focused_products h3').corner("top 7px");
	$('div.focused_product_content').corner("bottom 7px").parent().css('padding', '1px').corner("bottom 7px");
	$('#tradmarks').corner("top 7px");
	//$('#faq h3:first-child').corner("top 7px");
	$('#focused_products li').corner("7px");
	$('#page_title_category').corner("7px");
	$('.title_category').corner("top 7px").parent().css('padding', '1px').corner("top 7px");
	$('.content_description_category').corner("bottom 7px").parent().css('padding', '1px').corner("bottom 7px");
	$('#page_title_good_to_know').corner("top 7px");
	$('#sendbutton').corner("7px"); 
	$('.cform').corner("7px"); 
	$('#lifestyle_background_404').corner("7px").parent().css('padding', '1px').corner("7px");
	$('#focused_products_1 li').corner("7px");
	$('#focused_products_1 h3').corner("top 7px");
	$('#focused_products_2 li').corner("7px");
	$('#focused_products_2 h3').corner("top 7px");
	$('#focused_products_3 li').corner("7px");
	$('#focused_products_3 h3').corner("top 7px");
	$('#focused_products_4 li').corner("7px");
	$('#focused_products_4 h3').corner("top 7px");
	
	$('#focused_products').innerfade({ speed: 'slow', timeout: 6000, type: 'sequence', containerheight: '356px'}); 
	$('#focused_products_1').innerfade({ speed: 'slow', timeout: 6000, type: 'sequence', containerheight: '356px'}); 
	$('#focused_products_2').innerfade({ speed: 'slow', timeout: 6000, type: 'sequence', containerheight: '356px'}); 
	$('#focused_products_3').innerfade({ speed: 'slow', timeout: 6000, type: 'sequence', containerheight: '356px'}); 
	$('#focused_products_4').innerfade({ speed: 'slow', timeout: 6000, type: 'sequence', containerheight: '356px'}); 
	
		
	var address_url = document.location;
	var active = QueryString('active');
	if(active == 1){
		$("#accordion").accordion({
			autoHeight: false,
			active: 1
		});
	}else{
		$("#accordion").accordion({
			autoHeight: false
		});
	}

		
	$("#tabs_container").accordion({
			autoHeight: false,
			active: 'none'
		});
		
	$(".faq_container").accordion({
			autoHeight: false,
			active: 'none'
		});
	 	
	$("#all_about_button, #know_more").click(function () {
		$("#intro_category_product").slideUp();
		$("#faq").slideUp();
		$("#tabs").slideDown();
		setTimeout(function(){ $(document).scrollTo( '570px', 1200, {easing:'easeOutBack'} ); }, 500);
	});
	
	$("#faq_button").click(function () {
		$("#tabs").slideUp();
		$("#intro_category_product").slideUp();
		$("#faq").slideDown();
		setTimeout(function(){ $(document).scrollTo( '570px', 1200, {easing:'easeOutBack'} ); }, 500);
	});
	
	$("#print_icon").click( function() {
        $('#elements_to_print').jqprint();
        return false;
    });

	
	var product_image_height = $("#product_visual img.image").height();
	var product_image_semi_height = product_image_height / 2;
	var product_image_width = $("#product_visual img.image").width();
	var product_image_semi_width = product_image_width / 2;
	
	$("#product_visual img.image").css("height", product_image_height);
	$("#product_visual img.image").css("margin-top", -product_image_semi_height+15);
	
	$("#product_visual img.image").css("width", product_image_width);
	$("#product_visual img.image").css("margin-left", -product_image_semi_width);
	
	$(".focused_product_content").each(function(){
		var element = $(this).children("a").children("img");
		focused_product_image_height = element.attr("height");
		focused_product_image_semi_height = focused_product_image_height / 2;
		focused_product_image_width = element.attr("width");
		focused_product_image_semi_width = focused_product_image_width / 2;
		
		element.css("height", focused_product_image_height);
		element.css("margin-top", -focused_product_image_semi_height);
		
		element.css("width", focused_product_image_width);
		element.css("margin-left", -focused_product_image_semi_width);
	});
	
	$("#product_visual a, .img_consumable").fancybox({
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack'
	});
	
	$("#page_content a:has(img.alignnone), #page_content a:has(img.alignright), #page_content a:has(img.alignleft), #tabs #tabs_content a:has(img)").each(function(){
		href = $(this).attr('href');
		tokens = href.split('.');
		ext = tokens[tokens.length-1];
		if(ext == 'jpg' || ext == 'gif' || ext == 'png'){
			if ($(this).children("img").length>0) {
				$(this).fancybox({ 
					'titleShow'     : false,
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'elastic',
					'easingIn'      : 'easeOutBack',
					'easingOut'     : 'easeInBack'
				});
			}
		}
	});
	
	$("#tabs-informations h3").eq(0).hide();
	$("#tabs-informations h3").eq(1).hide();
	$("#tabs-informations h3").eq(1).nextAll().hide();
	
	$("#specifications_button").click(function () {
		$("#tabs-specifications h3").eq(0).hide();
		$("#tabs-specifications h3").eq(0).nextAll().hide();
		$("#tabs-specifications h3").eq(1).hide();
		$("#tabs-specifications h3").eq(1).next("ul").show();
	});
	
	$("#various").fancybox({
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'height'		: '600',
		'width'			: '200',
		'modal': false,
		'hideOnContentClick': false
	});
	
	$(".various_a").fancybox({
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'height'		: '600',
		'width'			: '200'

	});
	
	$("#various_a").fancybox({
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'height'		: '600',
		'width'			: '200'

	});
	
	$("#other_categories_menu li.page-item-41 a").eq(0).attr('href', '#');
	$("#other_categories_menu li.page-item-38 a").eq(0).attr('href', '#');
	
	var addressbar_url = document.location; 		
	$("a.product_link").each(function(index) {
		var current_url = $(this).attr("href");
		if (addressbar_url == current_url) {
			$(this).css("font-weight","bold");
		} else {}
	});

 });

$(function() {
		$("#tabs").tabs();
		$("#product_info").tabs();
});

function get_product(id){
    	data_string = "id="+id+"&current_iso="+$("#current_language").text();
    	$.ajax( {
		    type : 'POST',
		    url : 'http://www.kaz-europe.com/getProductInformations.php',
		    data : data_string,
		    success : function(msg) {
		    $("#desctiption_owners_manuals").fadeOut('slow',function(){
		    	$("#desctiption_owners_manuals").html(msg);
		    	$("#desctiption_owners_manuals").fadeIn('slow');
		    });
		    }
		 	});  
    }
    
function get_consumables(id){
    	data_string = "id="+id+"&current_iso="+$("#current_language").text();
    	$.ajax( {
		    type : 'POST',
		    url : 'http://www.kaz-europe.com/getConsumablesInformations.php',
		    data : data_string,
		    success : function(msg) {
		    $("#description_consumables").fadeOut('slow',function(){
		    	$("#description_consumables").html(msg);
		    	$("#description_consumables").fadeIn('slow');
		    });
		    }
		 	});  
    }
    
var currentTabId = 'imageTab';    
function showTab( tabId, top, left ) {
        if( document.getElementById( tabId ) ) {
		hideTab( currentTabId );
                document.getElementById( tabId ).style.display = 'block';
				document.getElementById( tabId ).style.top=top;
				document.getElementById( tabId ).style.left=left;
                currentTabId = tabId;
        }
        return false;
}
function hideTab( tabId ) {
        if( document.getElementById( tabId ) ) {
                document.getElementById( tabId ).style.display = 'none';
        }
        return false;
}

function QueryString(param){
    var strParam = new String(param);
    var position = window.location.search.indexOf('&' + strParam + '=');
    if (position==-1)
        position = window.location.search.indexOf('?' + strParam + '=');
    if (position==-1)
        return '';
    return (window.location.search.indexOf('&', position + strParam.length + 2)==-1) ? window.location.search.substr(position + strParam.length + 2) : window.location.search.substr(position + strParam.length + 2, window.location.search.indexOf('&', position + strParam.length + 2) - (position + strParam.length + 2));
}

function waranty_onchange(){
	id_cat = $("#category_select_list_category_waranty select").children('option:selected').attr("id");
	id_cat_class = $("#category_select_list_category_waranty select").children('option:selected').attr("class");
	id_pays = $("#category_select_list_country select").children('option:selected').attr("id");
	if(id_pays != null){
		if(id_cat == null){
			$('#waranty').html('');
		}else if(id_cat == 'post_36' || id_cat == 'post_37'){
			adresse = $("#datas").children('.'+id_pays).children('.adresse').html();
			$('#waranty').html(adresse);
		}else if(id_cat != 'post_36' && id_cat != 'post_37'){
			if(id_cat_class == "others_brands"){
				// AUTRES MARQUES
				$('#waranty').html('');
			}else{
				email = $("#datas").children('.'+id_pays).children('.email').html();
				$('#waranty').html(email);
			}
			
		}
	}else{
		$('#waranty').html('');
	}
}

function waranty2_onchange(){
	id_cat_2 = $("#category_select_list_category_waranty_2 select").children('option:selected').attr("id");
	id_cat = id_cat_2.substr(0,id_cat_2.length-2);
	id_pays_2 = $("#category_select_list_country_2 select").children('option:selected').attr("id");
	id_pays = id_pays_2.substr(0,id_pays_2.length-2);
	if(id_pays != null){
		if(id_cat == null){
			$('#waranty_2').html('');
		}else if(id_cat == 'post_36' || id_cat == 'post_37'){
			adresse = $("#datas_2").children('.'+id_pays).children('.adresse').html();
			$('#waranty_2').html(adresse);
		}else{
			email = $("#datas_2").children('.'+id_pays).children('.email').html();
			$('#waranty_2').html(email);
		}
	}else{
		$('#waranty_2').html('');
	}
}
