// JavaScript Document

jQuery(document).ready(function(){
		jQuery(".attention .one-pumpkins:last").addClass("last-pump");
	});

jQuery(document).ready(function(){
		jQuery(".media .one-media:last").addClass("last-media").removeClass("one-media");
	});

jQuery(document).ready(function(){
		jQuery(".news .one-new:first .one-new-top").hide();
	});

jQuery(document).ready(function(){
	    jQuery("._blank a").click(function(){
	        window.open(this.href);
	        return false;
	    });
	});

$(function() {
	$("#bnr_area").draggable();
});
	
jQuery(document).ready(function(){
	$('.adder').submit(function() {
		var form = $(this);
		if (addAction == 'cart') { // Просто отправляем форму
			return true;
		}
		if (addAction == 'mark' || addAction == 'show') { // Фоновое изменение корзины
			$.get(
				'/_ajax2cart.php', 
				{item:$(this).find('input[name=item]').val(),value:$(this).find('input[name=value]').val()},
				function (data) {
					var newData = data.split('|');
					$('#cart_num').text(newData[0]);
					$('#cart_sum').text(newData[1]);
					if (addAction == 'show') { // Дополнительное информационное окошко
						var offset = form.offset();
						$('body').append('<div id="cart_informer" style="position:absolute;z-index:1000;left:'+(offset.left-(view=='cards'?28:133))+'px;top:'+(offset.top-23)+'px;border:3px solid green;background-color:white;"><h3 style="margin:0;padding:10px;white-space:nowrap;color:green;text-align:center;">Товар добавлен<br>в корзину!</h3></div>');
						setTimeout(function() {
							$('#cart_informer').fadeOut('fast',  function() {
								$(this).remove();
							});
						},2000);
					}
				}
			);
		}
		return false;
	})
});

function getClientWidth() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
function getClientHeight() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

$(function() {
	var offset_left = Math.ceil((getClientWidth()-$('#bnr_area').width())/2);
	var offset_top =  Math.ceil((getClientHeight()-$('#bnr_area').height())/2);
	$('#bnr_area').css('left',offset_left);
	$('#bnr_area').css('top',offset_top);
	$('#bnr_area').fadeIn('fast');
})
function hideBnr() {
	$('#bnr_area').fadeOut('fast');
}

function getCookie(name) {
	var start = document.cookie.indexOf( name + '=' );
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) {
		return null;
	}
	if (start == -1) return null;
	var end = document.cookie.indexOf(';',len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}

function setCookie(name, value, expires, path, domain, secure) {
	var today = new Date();
	today.setTime(today.getTime());
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date(today.getTime() + (expires));
	document.cookie = name+'='+escape( value ) + ((expires) ? ';expires=' +expires_date.toGMTString() : '' ) +
	//expires.toGMTString()
	((path) ? ';path=' + path : '') + ((domain) ? ';domain=' + domain : '') + ((secure) ? ';secure' : '' );
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) document.cookie = name + '=' + ((path) ? ';path=' + path : '') +
	((domain) ? ';domain=' + domain : '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function MapWindow() {
	window.open("/google.html","","height=450,width=750,status=no,location=no,toolbar=no,directories=no,menubar=no");
}

function showSubcats(item_id,status) {
	var parent_pos = $('#c_'+item_id).offset();
	if (status == 1) {
		$('#s_'+item_id).css({'left':parent_pos.left-12,'top':parent_pos.top+$('#c_'+item_id).height()+1}).show();
	}
	else {
		$('#s_'+item_id).hide();
	}
}
