
// JQuery
$(document).ready(function(){
	// DEFAULT
	Cufon.replace('h1');
	if ( $("#home").length > 0 ) {	
		Cufon.replace('h2');
		Cufon.replace('h3');
		
	}
	if ( $("#company").length > 0 ) {	
		Cufon.replace('h2');
	}
	if ( $("#design").length > 0 ) {	
		Cufon.replace('h2');
	}
	if ( $("#catalogue").length > 0 ) {	
		Cufon.replace('h2');
	}
	if ( $("#slideshow").length > 0 ) {	
		Cufon.replace('#slideshow .caption h2');
	}
	if ( $("#notice").length > 0 ) {	
		Cufon.replace('#notice h2');
	}
	if ( $("#list").length > 0 ) {	
		Cufon.replace('#list h2');
	}
	if ( $("#product").length > 0 ) {	
		Cufon.replace('#product h2');
		Cufon.replace('#others_products h3');
	}
	if ( $("#bag").length > 0 ) {	
		Cufon.replace('h2');
	}
	if ( $("#buy").length > 0 ) {	
		Cufon.replace('h2');
		Cufon.replace('#content h3');
		
		$("#forgot_password a").click(function() {
			$("#send_password").slideToggle(500);
			return false;
		});
		$("#df_b_login, #df_b_continue").click(function() {
			$("#user_login").fadeOut(300, function(){
				$("#buy_data").slideDown(700);
			});
			return false;
         }); 
		$("#cvc").click(function() {
			var t = $(this).attr("title");  
			var url = $("#"+$(this).attr('rel'));
			$.fn.colorbox({maxHeight: "500", title: t,  inline:true, href:url});
			return false;
         }); 
	}
	if ( $("#pro").length > 0 ) {
		Cufon.replace('h2');
		Cufon.replace('#content h3');
		
		$("#forgot_password a").click(function() {
			$("#send_password").slideToggle(500);
			return false;
		});
		$("#df_b_continue").click(function() {
			$("#user_login").fadeOut(300, function(){
				$("#user_register").slideDown(700);
			});
			return false;
         }); 
	}
	if ( $("#newsletter").length > 0 ) {	
		Cufon.replace('h2');
		Cufon.replace('#content h3');
		
	}
	if ( $("#contact").length > 0 ) {	
		Cufon.replace('h2');
		Cufon.replace('#content h3');
		Cufon.replace('#content h4');
	}
	if ( $("#events").length > 0 ) {	
		Cufon.replace('h2');
		Cufon.replace('#content h3');
		Cufon.replace('#content h4');
		Cufon.replace('#events #content .date_events a', {hover:true});
	}
	if ( $("#others").length > 0 ) {	
		Cufon.replace('h2');
		Cufon.replace('#content h3');
		Cufon.replace('#content h4');
		Cufon.replace('#content #article ul li a', {hover:true});
		Cufon.replace('#content #article ul li ul li a');
	}
	if ( $("#confirm").length > 0 ) {	
		Cufon.replace('h2');
		Cufon.replace('#content h3');
	}
	if ( $("#aboutus").length > 0 ) {	
		Cufon.replace('h2');
		Cufon.replace('#content h3');
	}
	
	// Window identification & lng
	$(".sharethis").click( function() {
		if ( $("#win_lng").is(":visible") ) {
			$("#win_lng").fadeOut(300);
		}
		$(this).prev(".win").slideToggle(300);
		return false;
	});
	$(".lngs").click( function() {
		if ( $("#win_sharethis").is(":visible") ) {
			$("#win_sharethis").fadeOut(300);
		}
		$(this).prev(".win").slideToggle(300);
		return false;
	});
	// Win Close
	$(".win .close").click( function() {
		$(this).parent().parent(".win").fadeOut(300);
		return false;
	});
	
	
	// WIDNOWS RESIZE
	$(window).resize(function(){
		// Body OFF
		if ( $("#body_off").length > 0 ) {
			$("#body_off").css({'width': $(window).width()});
			$("#body_off").css({'height': $(document).height()});	
		}

	});
	
	if ( $("#df_bag").length > 0 ) {
		$("#df_bag").hover(
		  function () {
			$("#df_bag #expanded").stop(true,true).fadeIn(300);
		  }, 
		  function () {
			$("#df_bag #expanded").stop(true,true).fadeOut(300);
		  });
	}
	
	// ESHOP  LIST
	if ( $("#list").length > 0 ) {
		//Colores y ref.
		$(".colors li a").click( function() {
			var url = $(this).attr("urlImg");
			var id_img = $(this).attr("id_img");
			var urlFicha = $(this).attr("urlFicha");
			var itemCode = $(this).attr("itemCode");
			
			$("#"+id_img).stop(true,true).fadeOut(300, function () {
				var image = new Image();
				image.src = url;
				
				if (image.complete) {
					$("#"+id_img).attr("src", url);
					$("#"+id_img).fadeIn(400);
					$(".photo a").attr("href", urlFicha);
				} else {
					image.onload = function() {
						$("#"+id_img).attr("src", url);
						$("#"+id_img).fadeIn(400);
						$(".photo a").attr("href", urlFicha);
					};
				}
			});
			
			var currentItemCode = $(this).closest("div").closest("li").children('input:hidden[id*="currentItemCode"]');
			currentItemCode.val(itemCode);
			
			return false;
		});
		//Composion y medidas
		$(".df_b_comp1, .df_b_size1").click( function() {
			$(this).parent().next(".box").slideToggle(300);
			if ( $(this).is(".active") ) {
				$(this).removeClass("active");
			}else {
				$(this).addClass("active");
			}
			return false;
		});
	}
	// ESHOP PRODUCT
	if ( $("#product").length > 0 ) {
		//Colores y ref.
		$(".colors li a").click( function() {
			var url = $(this).attr("urlImg");
			var urlZoom = $(this).attr("urlZoom");
			var baseUrl = $(this).attr("baseUrl");
			var baseZoomUrl = $(this).attr("baseZoomUrl");
			var itemCode = $(this).attr("itemCode");
			
			$(".thumb li a").each(function(index) {
				$(this).children('img').attr("src", "");
			});
			
			 $("#photo").stop(true,true).fadeOut(300, function () {
				var image = new Image();
				image.src = url;
				
				if (image.complete) {
					$("#photo").attr("src", url);
					$("#photo").fadeIn(400);
					$(".photo a").attr("href", urlZoom);
					$(".thumb li a").each(function(index) {
						var i = "0" + (index + 1);
						$(this).attr("urlImg", baseUrl + i + "/ficha");
						$(this).attr("urlZoom", baseZoomUrl + i);
						$(this).children('img').attr("src", baseUrl + i + "/ficha_small");
					});
				} else {
					image.onload = function() {
						$("#photo").attr("src", url);
						$("#photo").fadeIn(400);
						$(".photo a").attr("href", urlZoom);
						$(".thumb li a").each(function(index) {
							var i = "0" + (index + 1);
							$(this).attr("urlImg", baseUrl + i + "/ficha");
							$(this).attr("urlZoom", baseZoomUrl + i);
							$(this).children('img').attr("src", baseUrl + i + "/ficha_small");
						});
					};
				}
			});
			
			var currentItemCode = $(this).closest("#form_product").children('input:hidden[id*="currentItemCode"]');
			currentItemCode.val(itemCode);
			
			return false;
		});
		//Composion y medidas
		$(".df_b_comp1, .df_b_size1, .df_b_desc1").click( function() {
			$(this).parent().next(".box").slideToggle(300);
			if ( $(this).is(".active") ) {
				$(this).removeClass("active");
			}else {
				$(this).addClass("active");
			}
			return false;
		});
		
		// Zoom product
		$(".photo a").colorbox({iframe:true, innerWidth:510, innerHeight:416});
		
		// Gallery Thumbs
		$(".thumb li a").click(function() {
			var url = $(this).attr("urlImg");
			var urlZoom = $(this).attr("urlZoom");
			$("#photo").stop(true,true).fadeOut(300, function () {
				var image = new Image();
				image.src = url;
				
				if (image.complete) {
					$("#photo").attr("src", url);
					$("#photo").fadeIn(400);
					$(".photo a").attr("href", urlZoom);
				} else {
					image.onload = function() {
						$("#photo").attr("src", url);
						$("#photo").fadeIn(400);
						$(".photo a").attr("href", urlZoom);
					};
				}
			});
		});
	}
	//Init
	// Body OFF
	if ( $("#body_off").length > 0 ) {
		$("#body_off").css({'width': $(window).width()});
		$("#body_off").css({'height': $(document).height()});	
	}
	//SLIDESHOW
	if ( $("#slideshow .slides").length > 0 ) {
		$('#slideshow').slides({
			container: 'slides',
			//pagination: false,
			generatePagination: false,
			//paginationClass: 'buttons',
			generateNextPrev: false,
			effect: 'slide',
			/*crossfade: true,
			fadeSpeed: 1000,*/
			slideSpeed: 500,
			preload: false,
			//preloadImage: '../i/df_loading1.gif',
			play: 5000,
			pause: 3000,
			hoverPause: true,
			animationStart: function(){
					$('.caption').animate({
						left: 40,
					},400);
				},
				animationComplete: function(current){
					//$('.caption').css({'top': 150, 'left': -100});
					$('.caption').animate({
						left: 50,
					},400);
					if (window.console && console.log) {
						// example return of current slide number
						console.log(current);
					};
				}
		});
	}
	if ( $("#others_slideshow .slides").length > 0 ) {
		$('#others_slideshow').slides({
			container: 'slides',
			//pagination: false,
			generatePagination: false,
			//paginationClass: 'buttons',
			generateNextPrev: false,
			effect: 'slide',
			/*crossfade: true,
			fadeSpeed: 1000,*/
			slideSpeed: 1000,
			preload: false,
			// preloadImage: '../i/df_loading1.gif',
			play: 10000,
			pause: 10000,
			hoverPause: true
		});
	}		
	
	/* PNG fix IE6 */
    jQuery.each(jQuery.browser, function(i, val) {
	if(i=="msie" && jQuery.browser.version.substr(0,3)=="6.0"){
                $("head").append("<script src='js/DD_belatedPNG.js'></script>, <script>DD_belatedPNG.fix('#logo a img , #home #container img');</script>");
			}
	});
    
});
