(function($){$.InFieldLabels=function(b,c,d){var f=this;f.$label=$(b);f.label=b;f.$field=$(c);f.field=c;f.$label.data("InFieldLabels",f);f.showing=true;f.init=function(){f.options=$.extend({},$.InFieldLabels.defaultOptions,d);if(f.$field.val()!=""){f.$label.hide();f.showing=false};f.$field.focus(function(){f.fadeOnFocus()}).blur(function(){f.checkForEmpty(true)}).bind('keydown.infieldlabel',function(e){f.hideOnChange(e)}).change(function(e){f.checkForEmpty()}).bind('onPropertyChange',function(){f.checkForEmpty()})};f.fadeOnFocus=function(){if(f.showing){f.setOpacity(f.options.fadeOpacity)}};f.setOpacity=function(a){f.$label.stop().animate({opacity:a},f.options.fadeDuration);f.showing=(a>0.0)};f.checkForEmpty=function(a){if(f.$field.val()==""){f.prepForShow();f.setOpacity(a?1.0:f.options.fadeOpacity)}else{f.setOpacity(0.0)}};f.prepForShow=function(e){if(!f.showing){f.$label.css({opacity:0.0}).show();f.$field.bind('keydown.infieldlabel',function(e){f.hideOnChange(e)})}};f.hideOnChange=function(e){if((e.keyCode==16)||(e.keyCode==9))return;if(f.showing){f.$label.hide();f.showing=false};f.$field.unbind('keydown.infieldlabel')};f.init()};$.InFieldLabels.defaultOptions={fadeOpacity:0.5,fadeDuration:300};$.fn.inFieldLabels=function(c){return this.each(function(){var a=$(this).attr('for');if(!a)return;var b=$("input#"+a+"[type='text'],"+"input#"+a+"[type='password'],"+"textarea#"+a);if(b.length==0)return;(new $.InFieldLabels(this,b[0],c))})}})(jQuery);

var mod = '';
var dost = 0;

function func()
{
	$(".height_div").height($(".height_td").height());
}

$(document).ready(function() {
	$(".timg").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition'	: 'inside'
	});

	$(".tovimg").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition'	: 'inside',
		'cyclic'		: 'true'
	});
			
	$(".windows").fancybox({
		'padding' 		: 0,
		'type'      	: 'iframe',
		'autoDimensions': false,
		'scrolling'		: 'no',
		'width'			: 890,
		'height'		: 400,
		'overlayShow'	: true,

		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'speedIn'		: '10',
		'speedOut'		: '10',
		'changeSpeed'	: '100'

	});

	$(".winpodarok").fancybox({
		'padding' 		: 0,
		'type'      	: 'iframe',
		'autoDimensions': false,
		'scrolling'		: 'no',
		'width'			: 890,
		'height'		: 400,
		'overlayShow'	: true,

		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'speedIn'		: '10',
		'speedOut'		: '10',
		'changeSpeed'	: '100'

	});

	$(".pricef").fancybox({
		'padding' 		: 0,
		'type'      	: 'iframe',
		'autoDimensions': false,
		'scrolling'		: 'yes',
		'width'			: 890,
		'height'		: 400,
		'overlayShow'	: true,

		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'speedIn'		: '10',
		'speedOut'		: '10',
		'changeSpeed'	: '100'

	});

	if (mod == 'kupit')
		showDostSpoiler(dost);

	$("label").inFieldLabels();

	setInterval("func();", 100); /* Ресайз картинок */

	imagePreview(); /* Ресайз картинок */

	//$(".btnPrint").printPage(); /* Вызов окна при нажатии купить */

	$(".btnPrint").click(function() {
		var rnd = Math.round(Math.random()*1000)+"_"+Math.round(Math.random()*1000)+"_"+Math.round(Math.random()*1000);
		//alert(this.id);
		$("body").append("<div id='printMessageBox_"+rnd+"' class='winkupit'>Спасибо! Товар успешно добавлен в корзину.</div>");
		$("#printMessageBox_"+rnd).animate({opacity:1}, 300);
		$("#printMessageBox_"+rnd).delay(1000).animate({opacity:0}, 700, function() { $(this).remove(); });
	});

	theRotator(); /* Слайдшоу текста в ноуте */


$(window).resize(function(e) {
	func();
});


/* Спойлер для прайса */
$('.splLink').click(function(){
$(this).parent().children('div.splCont').toggle('normal');
return false;
});
/* Спойлер для прайса END */


});



/* Каталог товаров при наведении картинка */
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 0;
		yOffset = -280;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt=''>"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

function changeAmount(id, amount)
{
	var callback = function(content)
	{
		window.location.reload(true);
	}

	xhr.option.url = '';
	xhr.post('/aj_amount', "id="+id+"&amount="+amount, callback);
}

function changeSpecAmount(id, amount)
{
	var callback = function(content)
	{
		window.location.reload(true);
	}

	xhr.option.url = '';
	xhr.post('/aj_amount&spec', "id="+id+"&amount="+amount, callback);
}

function putInCart(id, cat_type)
{
	var callback = function(content)
	{
		var nd = document.getElementById("cart_num_cont");
		if (nd.innerHTML.indexOf("пусто") != -1)
		{
			nd.innerHTML = "Сейчас <a href='/kupit' id='cart_num'></a> товаров";
			document.getElementById('cart_num_cont_1').innerHTML = "<a href='/kupit'>МОЯ КОРЗИНА</a>";
			document.getElementById('cart_num_cont_2').style.display = "block";
			document.getElementById('cart_num_cont_3').style.display = "none";
		}

		document.getElementById('cart_num').innerHTML = content;
	}

	xhr.option.url = '';
	xhr.post('/aj_buy&cat_type='+cat_type, "id="+id, callback);
}

function putSpecInCart(id, reloc)
{
	var callback = function(content)
	{
		if (reloc == true)
			window.location.reload(true);
		else
		{
			var nd = document.getElementById("cart_num_cont");
			if (nd.innerHTML.indexOf("пусто") != -1)
			{
				nd.innerHTML = "Сейчас <a href='/kupit' id='cart_num'></a> товаров";
				document.getElementById('cart_num_cont_1').innerHTML = "<a href='/kupit'>МОЯ КОРЗИНА</a>";
				document.getElementById('cart_num_cont_2').style.display = "block";
				document.getElementById('cart_num_cont_3').style.display = "none";
			}

			document.getElementById('cart_num').innerHTML = content;
		}
	}

	xhr.option.url = '';
	xhr.post('/aj_buy&spec', "id="+id, callback);
}

function showDostSpoiler(id)
{
	if (id == 0)
		return;

	if (document.getElementById('dost_1') != null && document.getElementById('dost_'+id) != null)
	{
		document.getElementById('dost_1').style.display = 'none';

		if (document.getElementById('dost_2') != null)
			document.getElementById('dost_2').style.display = 'none';

		if (document.getElementById('dost_3') != null)
			document.getElementById('dost_3').style.display = 'none';

		if (document.getElementById('dost_4') != null)
			document.getElementById('dost_4').style.display = 'none';

		if (document.getElementById('dost_5') != null)
			document.getElementById('dost_5').style.display = 'none';

		if (document.getElementById('dost_6') != null)
			document.getElementById('dost_6').style.display = 'none';

		if (document.getElementById('dost_7') != null)
			document.getElementById('dost_7').style.display = 'none';


		document.getElementById('dost_'+id).style.display = 'block';
	}
}

function showDostSpoiler2(id)
{
	if (id == 0)
		return;

	if (document.getElementById('dost2_1') != null)
	{
		document.getElementById('dost2_1').style.display = 'none';
		document.getElementById('dost2_2').style.display = 'none';
		document.getElementById('dost2_3').style.display = 'none';
		document.getElementById('dost2_'+id).style.display = 'block';
	}
}

function choosePresent(id, cat_type)
{
	var callback = function(content)
	{
		parent.document.getElementById("choose_present_link").innerHTML = content;
		parent.$.fancybox.close();
	}

	xhr.option.url = '';
	xhr.post('/aj_present&cat_type='+cat_type, "id="+id, callback);
}

/* Каталог товаров при наведении картинка *

/* Клик при нажатии купить  */

(function( $ ){
  $.fn.printPage = function(options) {
    // EXTEND options for this button
    var pluginOptions = {
      attr : "href",
      url : false,
      message: "Спасибо! Товар успешно добавлен в корзину." 
    };
    $.extend(pluginOptions, options);

    this.live("click", function(){  loadPrintDocument(this, pluginOptions); return false; });
    
    function loadPrintDocument(el, pluginOptions){
      $("body").append(components.messageBox(pluginOptions.message));
      /*$("#printMessageBox").css("opacity", 0);*/
      $("#printMessageBox").animate({opacity:1}, 300);

      unloadMessage();
    }
    function unloadMessage(){
      $("#printMessageBox").delay(1000).animate({opacity:0}, 700, function() { $(this).remove(); });
    }
    var components = {
      messageBox: function(message){
        return "<div id='printMessageBox' class='winkupit'>\
          "+message+"</div>";
      }
    }
  };
})( jQuery );

/* Клик при нажатии купить END  */



/* Меняющиеся текст на главной странице в баннере */

function theRotator() {
	// Устанавливаем прозрачность всех картинок в 0
	$('.shapka .slide .img .text #rotator div').css({opacity: 0.0});
 
	// Берем первую картинку и показываем ее (по пути включаем полную видимость)
	$('.shapka .slide .img .text #rotator div:first').css({opacity: 1.0});
 
	// Вызываем функцию rotate для запуска слайдшоу, 5000 = смена картинок происходит раз в 5 секунд
	setInterval('rotate()',5000);
}
 
function rotate() {	
	// Берем первую картинку
	var current = ($('.shapka .slide .img .text #rotator div.show')?  $('.shapka .slide .img .text #rotator div.show') : $('.shapka .slide .img .text #rotator div:first'));
 
	// Берем следующую картинку, когда дойдем до последней начинаем с начала
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('.shapka .slide .img .text #rotator div:first') :current.next()) : $('.shapka .slide .img .text #rotator div:first'));	
 
	// Расскомментируйте, чтобы показвать картинки в случайном порядке
	// var sibs = current.siblings();
	// var rndNum = Math.floor(Math.random() * sibs.length );
	// var next = $( sibs[ rndNum ] );
 
	// Подключаем эффект растворения/затухания для показа картинок, css-класс show имеет больший z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
 
	// Прячем текущую картинку
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};
 
/* Меняющиеся текст на главной странице в баннере END */



