var delay;
var current_appr = 4;
var close_timeout;
var lang_timeout;
$.cookie('started','yes');
$(document).ready(function(){
checkNavi();
if ($('.line_onright').size() > 0) {
setTimeout(function(){
var index_width = 0;
$('.line_onright').each(function(){
index_width = 280 - $(this).prev().width();
if (index_width > 15)
$(this).css({'width' : index_width + 'px'});	
});
},10);
}


if ($('#navigation').size() > 0) {
$('.topmenucont').eq(0).append($('#navigation'));	
}
$('.site').fadeIn();
$('a').not('.windownew,.lightbox').click(function(){
obj = $(this);
$('body').css({'height' : $(window).height()+2});
$('body').css({'backgroundImage' : 'url(/images/gido_logo_load.gif)'});
$('body').css({'backgroundPosition' : 'center'});
$('body').css({'backgroundRepeat' : 'no-repeat'});
$('body').css({'backgroundColor' : '#000'});
$('.site').fadeOut('slow',function(){
document.location = obj.attr('href');	
});
if ($('#login_center_block').size() > 0) $('#login_center_block').fadeOut('slow');
return false;	
});

$('.chosen_option1').each(function(){					  
$(this).html($('#'+$(this).next().attr('id')+' option:selected').text());								  
});
	/// product view image navigation
	$('#main_image').mouseover(function(event){
		clearTimeout(close_timeout);
		$('#arrow_open').parent().hide();
		$('#additional_pictures_navigation_relative').stop(true).animate({
		left: 0	
		}, 1000);
	});
	
	$('#main_image').mouseout(function(){
		close_timeout = setTimeout(function(){
		$('#additional_pictures_navigation_relative').stop(true).animate({
			left: -123	
		}, 1000, function() {$('#product_arrow_open').fadeIn('fast');});
		},10);
	});
	
	$('#additional_pictures_navigation_relative').mouseover(function(){
		clearTimeout(close_timeout);
		$('#arrow_open').parent().hide();
		if (!$('#additional_pictures_navigation_relative').is(':animated'))
		$('#additional_pictures_navigation_relative').animate({
		left: 0	
		}, 1000);		
	});
	
	$('#additional_pictures_navigation_relative').mouseout(function(){
		$('#main_image').trigger('mouseout');
	});
	
	$('#product_image_zoom').mouseover(function(){
		$('#main_image').trigger('mouseover');	
	});
	
	$('#product_image_zoom').mouseout(function(){
		$('#main_image').trigger('mouseout');	
	});
	
	/*
	
	$('.product_div a').hover(function(){
		$(this).find('span').stop(true).animate({
		top: 111
		},400);
	},function(){
		$(this).find('span').stop(true).animate({
		top: 140
		},200);
	});
	
	*/
	
	/* $('#list_products div a').hover(function(){
		$(this).find('span').stop(true).animate({
		top: 110
		},400);
	},function(){
		$(this).find('span').stop(true).animate({
		top: 140
		},200);
	});
	
	*/
	
	
	
	$('#product_image_zoom img').click(function(){
		$('#main_image_a').trigger('click');	
	});
	
	
	$('#product_additional_pictures a').hover(
		function(){
	clearTimeout(delay);
	if ($('#additional_pictures_navigation_relative').css('left') == '0px') {
	$('#main_image').attr('src',$(this).attr('rel'));
	}
	},
		function(){
	delay = setTimeout(function(){
	$('#main_image').attr('src',$('#main_image_a').attr('rel'));
	},100);
	});
	
	$('#arrow_right').click(function(){
		current_appr++;
		animateAppr();
		checkNavi();
		return false;
	});
	
	$('#arrow_left').click(function(){
		current_appr = current_appr - 1;
		animateAppr();
		checkNavi();
		return false;
	});
	///// eof image navigation
	$("div.changelang").hover(function() {
		clearTimeout(lang_timeout);
		$("div.changelang").stop(true).animate({
			right: 0
			},1000);
			}, function() {
		lang_timeout = setTimeout(function(){
			$("div.changelang").stop(true).animate({
			right: -75
			},1000);
			},200);
	});
	
	
	$("div.changelang").click(function() {
		$(this).stop(true).animate({
			right: -75
			},1000);
	});
	
	
	// Slider
	var sliderPointer = 9;	
	function sliderGo(key) {
		if(key < 0 || key > (sliderImages.length - 1)) key = 0;
		if(sliderImages[key] != "" && sliderUrls[key] != "" && key != sliderPointer && !$("div#display").is(':animated')) {
			if($("div#display").css("display") != "none")
			{
				$("div#display").fadeOut(400);
				setTimeout(function() {
					$("div#display").html("<img src='"+sliderImages[key]+"' width='975' height='425' />").fadeIn(800);
					$("div#urlarea").html("<a href='"+sliderUrls[key]+"' target='_blank'><div class='imageProtector'></div></a>");
				}, 401);
			} else {
				$("div#display").html("<img src='"+sliderImages[key]+"' width='975' height='425' />").fadeIn(800);
				$("div#urlarea").html("<a href='"+sliderUrls[key]+"' target='_blank'><div class='imageProtector'></div></a>");
			}
			
			$("div.nav_bar img").attr('src', 'images/slider_dot.png');
			$("div.nav_bar img#"+(key+1)).attr('src', 'images/slider_dot_active.png');
			sliderPointer = key;
		}
		to = setTimeout(function() {
			clearTimeout(to);
			sliderGo(sliderPointer+1);
		}, 10000);
	}
	
	$("img.nav_bar_pointer").click(function() {
		clearTimeout(to);
		var index = $(this).attr("id")*1-1;
		sliderGo(index);
	});
	
	$("div.leftArrow").click(function() {
		clearTimeout(to);
		var index = sliderPointer-1;
		if(sliderPointer == 0) index = sliderImages.length-1;
		sliderGo(index);
	});
	
	$("div.rightArrow").click(function() {
		clearTimeout(to);
		var index = sliderPointer+1;
		sliderGo(index);
	});
	
	// run slider on document ready
	if ($('div#display').size() > 0) sliderGo(0);
	// End slider
	
	$("div.buttons ul li a img").hover(
		function() {
			if($(this).attr('id') != "act") {
				var arr = $(this).attr('src').split(".");
				var newImg = arr[0]+"_active."+arr[1];
				$(this).attr('src', newImg);
			}
		},
		function() {
			if($(this).attr('id') != "act") {
				var arr = $(this).attr('src').split("_active");
				var ext = $(this).attr('src').split(".");
				var newImg = arr[0]+"."+ext[1];
				$(this).attr('src', newImg);
			}
		}
	);
	
});


// functions

function checkNavi() {
if (current_appr <= 4) {
	$('#arrow_left').hide();
} else {
	$('#arrow_left').show();
}
if (current_appr >= $('#list_products div.hold').size()) {
	$('#arrow_right').hide();
} else {
	$('#arrow_right').show();
}
}

function animateAppr() {
$('#list_products').animate(
{
left : (current_appr - 4)*(-214)
},400);	
}
