
// добавляем тегу html id=jst
document.documentElement.id = "jst";


/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

(function ($) {

$.fn.hint = function (blurClass) {
  if (!blurClass) {
    blurClass = 'blur';
  }

  return this.each(function () {
    // get jQuery version of 'this'
    var $input = $(this),

    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = $(this.form),
      $win = $(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) {
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title

      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

})(jQuery);



$(function() {


// Подсказка в полях
$('input[title!=""]').hint();


$('.shipZones tr:odd').addClass('odd');

$(".salonList .slide").before("<a href=\"#\" class=\"controls prev\" title=\"назад\">назад</a>").after("<a href=\"#\" class=\"controls next\" title=\"вперед\">вперед</a>");
$(".salonList .controls").hover(function(){$(this).fadeTo(150, .3)}, function(){$(this).fadeTo(300, 1)});


$('#footer .banners').css({'opacity' : '0.6'});


});


$(window).load(function(){

// Телефоны в шапке
$('.salonList .slide').cycle({
fx: 'fade',
prev: '.prev',
next: '.next',
speed: 400,
timeout: 0,
activePagerClass: 'active',
cleartypeNoBg: true
});


});



// Функция обратного вызова для AddIntoCart

function callbackfunction_AddIntoCart(responseJS)

{

	// Результат принят

	sended_request = false;



	if (typeof responseJS != 'undefined')

	{

		// Данные.

		if (typeof responseJS.cart != 'undefined')

		{

			html = responseJS.cart;



			var little_cart = document.getElementById('little_cart');



			if (little_cart)

			{

				little_cart.innerHTML = html;

			}

			else

			{

				alert('Ошибка! Краткая корзина не найдена');

			}

		}

	}

}



function AddIntoCart(shop_path, item_id, item_count)

{

	//location.href = shop_path + 'cart/?ajax_add_item_id=' + item_id + '&count=' + item_count;

	cmsrequest = shop_path + 'cart/?ajax_add_item_id=' + item_id + '&count=' + item_count;



	// Отправляем запрос backend-у

	sendRequest(cmsrequest, 'get', callbackfunction_AddIntoCart);



	return false;

}



// Анимация для добавления в корзину

(function(a){a.extend({noticeAdd:function(c){var f={inEffect:{opacity:"show"},inEffectDuration:600,stayTime:3000,text:"",stay:false,type:"notice"};var c,g,e,d,b;c=a.extend({},f,c);g=(!a(".notice-wrap").length)?a("<div></div>").addClass("notice-wrap").appendTo("body"):a(".notice-wrap");e=a("<div></div>").addClass("notice-item-wrapper");d=a("<div></div>").hide().addClass("notice-item "+c.type).appendTo(g).html("<p>"+c.text+"</p>").animate(c.inEffect,c.inEffectDuration).wrap(e);b=a("<div></div>").addClass("notice-item-close").prependTo(d).html("x").click(function(){a.noticeRemove(d)});if(navigator.userAgent.match(/MSIE 6/i)){g.css({top:document.documentElement.scrollTop})}if(!c.stay){setTimeout(function(){a.noticeRemove(d)},c.stayTime)}},noticeRemove:function(b){b.animate({opacity:"0"},600,function(){b.parent().animate({height:"0px"},300,function(){b.parent().remove()})})}})})(jQuery);

function addtocart(id, count) {
	AddIntoCart('/shop/', id, count);
	var img = jQuery('#img_'+id), pos = img.offset();
	var tr = $('<div class="effect-transfer"/>').appendTo('body').append(img.clone())
		.css({ top: pos.top, left: pos.left, height: img.outerHeight(), width: img.outerWidth() });

	var cart = jQuery('.littleCart'), pos = cart.offset();
	tr.animate({ top: pos.top, left: pos.left, height: cart.outerHeight(), width: cart.outerWidth()	}, 1000, function() {
		jQuery.noticeAdd({
			text: '<h5>\u041A\u043E\u0440\u0437\u0438\u043D\u0430</h5>\u0422\u043E\u0432\u0430\u0440 \u0434\u043E\u0431\u0430\u0432\u043B\u0435\u043D \u0432 \u043A\u043E\u0440\u0437\u0438\u043D\u0443!<br /><a href="/shop/cart"><b>\u041F\u0435\u0440\u0435\u0439\u0442\u0438</b></a>&nbsp;&nbsp;\u0434\u043B\u044F \u043E\u0444\u043E\u0440\u043C\u043B\u0435\u043D\u0438\u044F \u0437\u0430\u043A\u0430\u0437\u0430.',
			stay: false,
			inEffectDuration: 250,
			stayTime: 4000
		});
		$(this).remove();
	});
	return!1;
}



