$(function(){
	$('a.add2basket').click(function(){
		var itemId 		= $(this).attr('item-id');
		var countEl 	= $(this).parent('').parent().find('input.eshop-text');
		var itemCount	= countEl.val();
		if (!itemId) return false;
		if (itemCount <= 0){
			alert('Укажите кол-во товара для добавления в корзину');
			countEl
				.css('borderColor', 'red')
				.focus();
			return false;
		}
		$.ajax({
			type: 'POST',
			url : path + '/ajax/add2basket.php',
			data: 'itemId=' + itemId + '&count=' + itemCount,
			success: function( data ){
				try
				{
					data = eval('('+ data +')')
					countEl.css('borderColor', '#80C3EC');
					$('#basketPrice').html( data.amount )
					alert('Товар успешно добавлен в корзину');
				} catch (e){}
			}
		});
		return false;
	})
})


if (!window.getComputedStyle) {
    window.getComputedStyle = function(el, pseudo) {
        this.el = el;
        this.getPropertyValue = function(prop) {
            var re = /(\-([a-z]){1})/g;
            if (prop == 'float') prop = 'styleFloat';
            if (re.test(prop)) {
                prop = prop.replace(re, function () {
                    return arguments[2].toUpperCase();
                });
            }
            return el.currentStyle[prop] ? el.currentStyle[prop] : null;
        }
        return this;
    }
}
function fixPNG(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
	
    if (element.tagName=='IMG')
    {
      if (/\.png$/.test(element.src))
      {
        src = element.src;
        element.src = path+"/images/blank.gif";
      }
    }
    else
    {
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src)
      {
        src = src[1];
        element.runtimeStyle.backgroundImage="none";
      }
    }
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
  }
}
function openw(res,title) {
   rand=Math.random().toString().substring(2,15);
   window.open(path + "/lib/show_pic.php?src="+res+"&title="+title, 'new_'+rand, "top=50, left=50, width=50, height=50, channelmode=no, toolbar=no, location=no, status=no, directories=no, menubar=no, resizable=yes");
}


function menu_on(ob,id)
{
	document.getElementById("menu_"+ob).className = "left_menu_"+id+"_on";
	document.getElementById("a_"+ob).className = "left_menu_on";
}
function menu_off(ob,id)
{
	document.getElementById("menu_"+ob).className = "left_menu_"+id;
	document.getElementById("a_"+ob).className = "left_menu";
}
function menu_link(link)
{
	window.location = link;
}

var pl_white = new Image;
pl_white.src = path+"/images/pl_white.png";

var pl_white_on = new Image;
pl_white_on.src = path+"/images/pl_white_on.png";

var pl_blue = new Image;
pl_blue.src = path+"/images/pl_blue.png";

var pl_blue_on = new Image;
pl_blue_on.src = path+"/images/pl_blue_on.png";

function index_menu_on(ob,id)
{
	el = document.getElementById(ob)
	el.src = eval("pl_"+id+"_on.src");
	document.getElementById("a_"+ob).className = "left_menu_on";
	fixPNG(el);
}
function index_menu_off(ob,id)
{
	el = document.getElementById(ob)
	el.src = eval("pl_"+id+".src");
	document.getElementById("a_"+ob).className = "left_menu";
	fixPNG(el);
}
/*--- begin special scrolling ---*/
$(function(){
	el = document.getElementById("spoff_container");
	if (el) {
		var spoff_cont_width = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.scrollWidth;
		$(".spoff_bolide").css( "left", (spoff_cont_width) + "px" );
		setInterval("SpoffMove()",1);
	}
});
function SpoffMove() {
	var last_bolide = $(".spoff_bolide").get($(".spoff_bolide").size()-1);
	if ( last_bolide.offsetLeft + last_bolide.offsetWidth < 0 ) {
		el = document.getElementById("spoff_container");
		var spoff_cont_width = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.scrollWidth;
		$(".spoff_bolide").css( "left", (spoff_cont_width) + "px" );
	}
	var cur_left = $(".spoff_bolide").css( "left" );
	cur_left = parseInt(cur_left) - 1;
	$(".spoff_bolide").css( "left", cur_left + "px" );
	//$(".spoff_bolide").animate( { left:0 }, 25000 );
}
/*--- end special scrolling ---*/
function popupWindow( id ){
	w = 640; h = 480;
	
	var elMask = $(document.createElement('div'))
					.css({
						background	: '#000000',
						left		: 0,
						top			: 0,
						width		: $(document.body).outerWidth(),
						height		: $(document.body).outerHeight(),
						position	: 'absolute',
						opacity		: '0.5'
					});

	var elClose = $(document.createElement('img'))
					.css({
						position: 'absolute',
						right	: 5,
						top		: 5,
						width	: 17,
						height	: 22,
						cursor	: 'pointer'
					})
					.attr('src', path + '/images/close.gif')
	
	var elCont = $(document.createElement('div'))
					.css({
						position	: 'absolute',
						width		: w,
						height		: h,
						padding		: '27px 10px 10px 10px',
						overflow	: 'hidden',
						background	: '#FFFFFF',
						left		: ($(document.body).outerWidth() / 2) - (w / 2),
						top			: ($(document.body).outerHeight() / 2) - (h / 2),
						border		: '5px solid #008AD7',
						display		: 'none'
					})
					.append(elClose)
					.append( '<div>'+ $('#content_' + id).html() +'</div>' );

	var fnClose = function(){
		elMask.fadeOut(500, function(){
			$(this).remove();
		});
		elCont.fadeOut(300, function(){
			$(this).remove();
		})
	};
	elMask.click(fnClose);
	elClose.click(fnClose);
	
	$(document.body)
		.append(elMask)
		.append(elCont);
	
	elMask.fadeIn(300);
	elCont.fadeIn(500);
	
	return false;
}
