﻿function memotest(i, imagen){
	if( $(".s-"+imagen).hasClass('seleccionada')){
		$(".c-"+imagen).removeClass("abierto");
		$(".s-"+imagen).addClass("encontrada");
		$(".c-"+imagen).addClass("trabado");
		var w = $(".encontrada");
		if(w.length == 16){
			$.timer(600, function (timer) {										    
				$("#win").jqm().jqmShow();						    
				timer.stop();					
			});				
		}			
	}else if( $(".ficha-cover").hasClass("abierto") ){
		$("#s-"+i).addClass("seleccionada");
		$("#c-"+i).addClass("abierto");
		$.timer(400, function (timer) {															
			$(".ficha").removeClass("seleccionada");
			$(".ficha-cover").removeClass("abierto"); 									    
			timer.stop();				
		});			
	}else{
		$("#s-"+i).addClass("seleccionada"); 	
		$("#c-"+i).addClass("abierto");
	}		 
}

function showBasketInfo() {	
	$.ajax({
		url:'/showbasket',
		type: 'GET',
		success: function(data){
			$("div.baskettooltip").css({
				height: 'auto'
			}).show(100, function(){
				$('.baskettooltip-content').html(data);
			});
			$('.baskettooltip').hide();
			//alert('q');
		}
	});
	$('.baskettooltip').hide();
}
/*
function hideBasketInfo () {
	$("div.baskettooltip").hide();
}
*/
function theRotator() {
  $('div#rotator div').css({opacity: 0.0});
  $('div#rotator div:first').css({opacity: 1.0});
  setInterval('rotate()',5000);
}
/*
function theRotator2() {
  $('div#rotator2 div').css({opacity: 0.0});
  $('div#rotator2 div:first').css({opacity: 1.0});
  setInterval('rotate2()',5000);
}

function headerRotator() {
  $('div#header_rotator div').css({opacity: 0.0});
  $('div#header_rotator div:first').css({opacity: 1.0});
  setInterval('header_rotator()',11000);
}
 
function header_rotator() {  
  var current = ($('div#header_rotator div.show')? $('div#header_rotator div.show') : $('div#header_rotator div:first'));
  var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#header_rotator div:first') :current.next()) : $('div#header_rotator div:first'));  
  next.css({opacity: 0.0})
  .addClass('show')
  .animate({opacity: 1.0}, 2000);
  current.animate({opacity: 0.0}, 2000)
  .removeClass('show');
}

function rotate2() {  
  var current = ($('div#rotator2 div.show')? $('div#rotator2 div.show') : $('div#rotator2 div:first'));
  var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator2 div:first') :current.next()) : $('div#rotator2 div:first'));  
  next.css({opacity: 0.0})
  .addClass('show')
  .animate({opacity: 1.0}, 2000);
  current.animate({opacity: 0.0}, 2000)
  .removeClass('show');
}*/
function rotate() {  
  var current = ($('div#rotator div.show')? $('div#rotator div.show') : $('div#rotator div:first'));
  var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator div:first') :current.next()) : $('div#rotator div:first'));  
  next.css({opacity: 0.0})
  .addClass('show')
  .animate({opacity: 1.0}, 2000);
  current.animate({opacity: 0.0}, 2000)
  .removeClass('show');
}

 
$(document).ready(function(){
	$(".colorbox").colorbox({rel:'group3', transition:"none", width:"90%", height:"90%"});

	$(".change_item_image").live('click',function(){
        $('.cloud-zoom').CloudZoom();
    });
	$("#colortabs-0").hover(function() {
		$('.cloud-zoom').CloudZoom();
	});
	$("#colortabs-1").hover(function() {
		$('.cloud-zoom').CloudZoom();
	});
	$("#colortabs-2").hover(function() {
		$('.cloud-zoom').CloudZoom();
	});
	
	$("#basket-popup-submit").live('click',function(){
		$( "#basketsuccess_dialogmodal" ).dialog({
			height: 130,
			modal: true
		});
	});
	
	$("#sendttt").live('click',function(){
		var email_element = $("#bo-email-element #email").val();
		var name_element = $("#bo-name-element #name").val();
		var kod_element = $("#bo-kod-element #kod").val();
		var city_element = $("#bo-city-element #city").val();
		var target_element = $("#bo-target-element #target").val();
		if((email_element.length<1) || (name_element.length<1) || (kod_element.length<1) || (city_element.length<1)) {
			alert("Не все обязательные поля заполнены.");
			return false;
		}
	}); 
	$tabs = $("#tabs").tabs();
	$tabs.tabs('select', 2);
	$( "#colortabs" ).tabs();
	$( ".tabs-bottom .ui-tabs-nav, .tabs-bottom .ui-tabs-nav > *" )
		.removeClass( "ui-corner-all ui-corner-top" )
		.addClass( "ui-corner-bottom" );

	$(".hideSpan, .showSpan").live('click',function(){
		var container = $(this).parent().parent().find("#filtershhd");
		if (container.is(":visible")) {
			container.hide();
			$(this).addClass("showSpan").removeClass("hideSpan");
		} else {
			container.show();
			$(this).addClass("hideSpan").removeClass("showSpan");
		}
	}); 
	
	$('ul.viewmenu a').each(function(i) { 
		$(this).click(function() {
			$(this).parent().parent().find('a').each(function(){
				$(this).removeClass('seli').addClass('deseli');
			});	
			$(this).removeClass("deseli").addClass("seli");
		});
	});
	theRotator();
	//theRotator2();
	//headerRotator();
	$("#teflon").live('click',function(){
		$(".teflondialog").dialog({
			title: 'Покрытие DuPont Teflon детской одежды Deux par Deux',
			width: 600
		});
		return false;
	});
	$("#ykk").live('click',function(){
		$(".ykkdialog").dialog({
			title: 'Фурнитура YKK для одежды Deux par Deux',
			width: 600
		});
		return false;
	});
	$(function () { 
		$(window).scroll(function () { 
			if ($(this).scrollTop() > 350) { 
				$('#back-top').fadeIn(); 
			} else { 
				$('#back-top').fadeOut(); 
			} 
		});
	}); 
	$('#adressdelivery #sendttt').live('click',function(){
		var ad_name = $('#adressdelivery #name').val();
		var ad_lastname = $('#adressdelivery #lastname').val();
		var ad_email = $('#adressdelivery #kod').val();
		var ad_phone = $('#adressdelivery #phone').val();
		var ad_city = $('#adressdelivery #city').val();
		var ad_address = $('#adressdelivery #address').val();
		if((ad_name.length<1) || (ad_lastname.length<1) || (ad_email.length<1) || (ad_phone.length<1)|| (ad_city.length<1) || (ad_address.length<1)) {
			alert("Не все обязательные поля заполнены.");
			return false;
		}
	});
	
});


$(document).ready(function(){
	var qwe ='2';
	$(".search_input").focus(function() {
		this.value='';
	});
	$(".search_input").blur(function() {
		if (this.value != '') {
			this.onfocus = function(){this.value='';};
		} 
		else 
			this.value='Поиск...';
	});
	
	$(".search-btn").live('click', function() {
		document.getElementById('newsearch').submit(); return false;
	});
	
	$("#searchform").live('click', function() {
		$("#searchgoods").attr("action","/searchgoods");
		$('#searchgoods').submit();
		$("#searchgoods").attr("action","");
		return false;
	});
	$("#mainsearchform").live('click', function() {
		$("#mainsearchgoods").attr("action","/searchgoods");
		//$(".searchselect").removeAttr("disabled");
		$('#mainsearchgoods').submit();
		$("#mainsearchgoods").attr("action","");
		return false;
	});
	$("#selectpol").live('change', function() {
		var val = $("#selectpol option:selected")[0].value;
		$("#selecttovar option").hide();
		$("#selecttovar option.defaultoption").attr('selected', 'selected');
		if(val=="девочка") {
			$("#selecttovar option.dev").show();
		} else if (val=="малыши до 36 мес") {
			$("#selecttovar option.mal").show();
		} else if(val=="мальчик") {
			$("#selecttovar option.mak").show();
		}
	});
	$("#selectodezhda").live('change', function() {
		var od_val = $("#selectodezhda option:selected")[0].value;
		if((od_val != '--------------') && (od_val != '' )) {
			$("#selecttovar").attr('disabled', 'disabled');
		} else {
			$("#selecttovar").removeAttr('disabled');
		}
	});
	$("#selecttovar").live('change', function() {
		var od_val = $("#selecttovar option:selected")[0].value;
		if((od_val != '--------------') && (od_val != '' )) {
			$("#selectodezhda").attr('disabled', 'disabled');
		} else {
			$("#selectodezhda").removeAttr('disabled');
		}
	});
	/*$(".searchselect").live('change', function() {
		var id = this.id;
		if($("#"+id+" .defaultoption").attr("selected") == true) {
			$(".searchselect").removeAttr("disabled");
		} else {
			$(".searchselect").attr("disabled","disabled");
			$(this).removeAttr("disabled");
		}

		//return false;
	})
	;*/
	/*$(".read_more").live('click', function() {
		if($(".read_more_text").css("display") == "none") {
			$(".read_more_text").show();
		} else {
			$(".read_more_text").hide();
		}
	});
	*/
	if($(".locator").length > 0) {
	  $("select.locator").change(function () {
          var str = "";
		  var value = "";
          $("select.locator option:selected").each(function () {
                value = $(this).attr("value");
				if((value == 'all') || (value == '')) {
					$(".city").each(function () {
						 $(this).show();
					});
				} else {
					$(".city").each(function () {
						 $(this).hide();
					});
					
					$("."+value).each(function () {
						 $(this).show();
					});
				}
              });
        })
        .change();
	}

	if ( $('#cat_icon_register').length ) {
		$('#cat_icon_register').tooltip();
	}
	if ( $('#cat_icon_video').length ) {
		$('#cat_icon_video').tooltip();
	}
	if ( $('#cat_icon_price').length ) {
		$('#cat_icon_price').tooltip();
	}
	if ( $('#cat_icon_size').length ) {
		$('#cat_icon_size').tooltip();
	}
	if ( $('#cat_icon_press').length ) {
		$('#cat_icon_press').tooltip();
	}
	if ( $('#cat_icon_photo').length ) {
		$('#cat_icon_photo').tooltip();
	}
	if ( $('#cat_icon_pdf').length ) {
		$('#cat_icon_pdf').tooltip();
	}
	if ( $('#cat_icon_otzyv').length ) {
		$('#cat_icon_otzyv').tooltip();
	}
});


$("div.colltooltip").hide();
function collection_tooltip (text, type) {
	if($("div.colltooltip").css("display") != "none") {
		if(type == 0) {
			$("div.colltooltip").hide();
		}
		return;
	} else {
		
		if(type == 1) {
			var pCoords = 455;
			var cCoords = 500;
		} else if(type == 2) {
			var pCoords = 455;
			var cCoords = 710;
		} else if(type == 3) {
			var pCoords = 455;
			var cCoords = 850;
		} else if(type == 4) {
			var pCoords = 455;
			var cCoords = 1000;
		}  else if(type == 0) {
			$("div.colltooltip").hide();
			return;
		} 
		$("div.colltooltip").css({ top: pCoords , left:cCoords }).show(400, 
			function(){
				$(this).html('<div style="display: block; left: 360px; top: 227px; ">'+text+'</div>');
		});
	}
/*	<div id="fleche" style="display: block; left: 388px; top: 262px; "></div> */
	
}
  $(function() {
    $('img.image1').data('ad-desc', 'Whoa! This description is set through elm.data("ad-desc") instead of using the longdesc attribute.<br>And it contains <strong>H</strong>ow <strong>T</strong>o <strong>M</strong>eet <strong>L</strong>adies... <em>What?</em> That aint what HTML stands for? Man...');
    $('img.image1').data('ad-title', 'Title through $.data');
    $('img.image4').data('ad-desc', 'This image is wider than the wrapper, so it has been scaled down');
    $('img.image5').data('ad-desc', 'This image is higher than the wrapper, so it has been scaled down');
    var galleries = $('.ad-gallery').adGallery();
    $('#switch-effect').change(
      function() {
        galleries[0].settings.effect = $(this).val();
        return false;
      }
    );
    $('#toggle-slideshow').click(
      function() {
        galleries[0].slideshow.toggle();
        return false;
      }
    );
    $('#toggle-description').click(
      function() {
        if(!galleries[0].settings.description_wrapper) {
          galleries[0].settings.description_wrapper = $('#descriptions');
        } else {
          galleries[0].settings.description_wrapper = false;
        }
        return false;
      }
    );
  });
 
