$(document).ready(function(){
	//-- hide the GB site for now. 
	$("a[href='/gb']").hide();

	//-- autoform validation
	if($(".autoform").size()>0){
		$(".autoform").validate({ignore: ":hidden"});
		if($('.datepickers').size()){
			$('.datepickers').datepicker();
		}
	}

	//	if($('#home_flickr_image').size()){
	//		$('#home_flickr_image').flickrshow({
	//			autoplay:true,
	//			interval:5000,
	//			license:null,
	//			tags:'kazmok',
	//			user:'59031456@N07',
	//			hide_buttons:true,
	//			onLoad:function(){
	//				$('#home_flickr_image').css("backgroundImage","");
	//			}
	//		});
	//	}
	if($('#home_flickr_image').size()){
		$('#home_flickr_image').cycle({
			fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
	}
	if($(".product_category_menu").size()){
		var url = document.location.href.replace(document.location.protocol+"//"+document.location.host,"");
		$(".product_category_menu a[href$='"+url+"']").removeClass("selected");
		if($(".product_category_menu a[href$='"+url+"']").size()==1){
			$(".product_category_menu a[href$='"+url+"']").addClass("selected");
		}

	}

	//-- image carousel
	if($("#carousel").size()){
		$("#carousel .thumb:first").addClass("selected");
		CarTimeOut = setTimeout(function(){
			rotate();
		},CarSpeed);
		$("#carousel .thumb").bind("click",function(){
			CurrentIndex  = $("#carousel .thumb").index($(this));
			if($(this).hasClass("selected")){
				return false;
			}
			if($("#product_large_image img:animated").size()){
				return false;
			}
			$("#carousel .thumb").removeClass("selected");
			$(this).addClass("selected");
			//			var img = new Image();
			var imgCurrent = $("#product_large_image img:first");
			var imgCurrentFile = $(this).attr("href");
			imgCurrent.fadeOut("slow",function(){
				var img = new Image();
				$(img)
				.load(function () {
					imgCurrent.attr("src",imgCurrentFile).fadeIn("slow");
				})
				.error(function () {})
				.attr("src",imgCurrentFile);
			});

			return false;
		}).hover(
			function(){
				clearTimeout(CarTimeOut);
			},
			function(){
				rotate();
			}
			);
	}
	$("#customers_shipping").bind("change",function(){
		$("#shipping_adres").toggle("slow");
	});
	if($('#shipping_adres').size()){
		if($('#customers_shipping').attr('checked')==true){
			$('#shipping_adres').css('display','block');
		}else{
			$('#shipping_adres').css('display','none');
		}
	}

	//-- AJAX shoppingcart
	$(".product_details_info .btn_order").bind("click",function(){
		var $elm = $(this);

		$("html").animate({scrollTop:"0px"}, "slow",function(){ doRequest($elm.attr("name")+"="+$elm.val())});
		$("#shopping_bastket_top").prepend($('<span class="loader"/>'));
		return false;
	}
	);
	function doRequest(strData){
		
		$.ajax(
				{
					url:document.location.href,
					cache: false,
					async: false,
					data: strData,
					type: "POST",
					dataType: "html",
					success: function(data){
						var htmlFiltered = $("#shopping_bastket_top span",data).html();
						$("#shopping_bastket_top span").html(htmlFiltered);
						$("#shopping_bastket_top .loader").remove();
						$("#shopping_bastket_top span").css({color:"#ff0000"});
						window.ShoppingaskerProcessing =false;
					}
				});
	}
});


var CurrentIndex =0;
var CarTimeOut;
var CarSpeed = 4000;
function rotate(){
	if(CurrentIndex-1 == $("#carousel .thumb").index($("#carousel .thumb:last"))){
		CurrentIndex=0;
	}
	$("#carousel .thumb:eq("+ CurrentIndex +")").trigger("click");
	CarTimeOut = setTimeout(function(){
		rotate();
	},CarSpeed);
	CurrentIndex++;
}
