$(function(){
	
	var gl_color = $('#gl_color').val();
	
	// -------------------------------- ЛОГО --------------------------------
	$('#logo1,#logo2').click(function(){
		location.href = '/';
	});
	// -------------------------- INPUT выравнивание ------------------------
	var isIE = $.browser.msie;
	if(isIE)
	{
		$('.pole').css("padding","6px 10px 0 10px");
		$('.pole1').css("padding","2px 7px 0 7px");
		$('.pole2').css("padding","2px 5px 0 5px");
		$('textarea').css("padding","6px 0 6px 10px");
	}
	else
	{
		$('.pole').css("padding","0 10px");
		$('.pole1').css("padding","0 7px 3px 7px");
		$('.pole2').css("padding","0 5px 0 5px");
		$('textarea').css("padding","7px 0 7px 10px");
	}
	// ------------------------------ КНОПКИ -------------------------------- 
	$('.btn').css({
		'height': '30px',
		'cursor': 'pointer'		
	});
	$('.btn th').css({
		'width': '10px',
		'background': 'url(/img/'+gl_color+'/btn_l.gif) no-repeat',
		'padding': '0'
	});
	$('.btn td').css({
		'background': 'url(/img/'+gl_color+'/btn_r.gif) no-repeat right',
		'font': 'bold 14px Arial, Helvetica, sans-serif',
		'color': '#FFF',
		'white-space': 'nowrap',
		'padding': '0 10px 0 0'
	});
	$.preloadImg('/img/'+gl_color+'/btn_hover_l.gif','/img/'+gl_color+'/btn_hover_r.gif');
	$('.btn').hover(
		function(){
			$(this).find('th').css("background","url(/img/"+gl_color+"/btn_hover_l.gif) no-repeat");
			$(this).find('td').css("background","url(/img/"+gl_color+"/btn_hover_r.gif) no-repeat right");
		},
		function(){
			$(this).find('th').css("background","url(/img/"+gl_color+"/btn_l.gif) no-repeat");
			$(this).find('td').css("background","url(/img/"+gl_color+"/btn_r.gif) no-repeat right");
		}
	);
	//
	$('.back').click(function(){
		history.back();
		return false;
	});
	//
	$.preloadImg('/img/'+(gl_color=='orange'?'orange/':'')+'rb_hover.gif');
	$('.rb').hover(
		function(){
			$(this).css("background","url(/img/"+(gl_color=='orange'?'orange/':'')+"rb_hover.gif) no-repeat");
		},
		function(){
			$(this).css("background","url(/img/"+(gl_color=='orange'?'orange/':'')+"rb.gif) no-repeat");
		}
	);
	// --------------------- информация о товаре -------------------------
	$.preloadImg('/img/gi_lu.png','/img/gi_u.png','/img/gi_ru.png','/img/gi_l.png','/img/gi_r.png','/img/gi_lb.png','/img/gi_b.png','/img/gi_rb.png');
	$('.good_info').click(function(){ 
		
		$('body').blackout({z:50,opacity:60});
		$('#blackout').show();
		
		mas = this.id.split('_');
		id = mas[1];
		
		var gi_block = $('#gi_'+id);
		
		gi_block.css("height",Math.round(BodySize().height*0.7) + 'px');
		gi_block.css("top",Math.round((BodySize().height/2) - (gi_block.height()/2) + document.body.scrollTop) + 'px');
		gi_block.css("left",Math.round((BodySize().width/2) - (gi_block.width()/2)) + 'px');
		gi_block.find('.gi_content').height(gi_block.height()-80);
		
		setTimeout(function(){ gi_block.slideDown(400) },100);

	});
	$.preloadImg('/img/'+gl_color+'/app_close_hover.gif');
	$('.gi_close').hover(
		function(){
			$(this).css("background","url(/img/"+gl_color+"/app_close_hover.gif) no-repeat");
		},
		function(){
			$(this).css("background","url(/img/"+gl_color+"/app_close.gif) no-repeat");
		}
	);
	
	function gi_close(block)
	{
		if(block.size())
		{
			if($.browser.msie)
				block.animate({ height: 0 }, 400, "linear", function(){ block.hide(); $('#blackout').fadeOut('fast'); });
			else
				block.slideUp(400,function(){ $('#blackout').fadeOut('fast'); });
		}
	}	
	$('.gi_close').click(function(){ gi_close($(this).parents('div:first')) });
	$(window).keypress(function(e){ if(e.keyCode==27) { gi_close($('.gi_block:visible')) } });
	$('body').keypress(function(e){ if(e.keyCode==27) { gi_close($('.gi_block:visible')) } });
	//
	$(document).pngFix();
});

jQuery.fn.blackout = function(settings){
	
	// Settings
	settings = $.extend({
		color : '#000',
		opacity : 80,
		z : 50
	}, settings);
	
	var opacity = parseInt(settings.opacity)*0.01;

	var blackout = document.createElement('DIV');
	$(blackout).attr('id','blackout');
	$(blackout).css({
		'width' : document.body.clientWidth + 'px', 
		'height' : document.body.scrollHeight + 'px',
		'position' : 'absolute',
		'left' : '0',
		'top' : '0',
		'background-color' : settings.color,
		'-moz-opacity' : opacity,
		'filter' : 'alpha(opacity: '+settings.opacity+')',
		'opacity' : opacity,
		'padding' : '0',
		'z-index' : settings.z,
		'display' : 'none'
	});
	
	var blackout_iframe = document.createElement('iframe');
	$(blackout_iframe).attr('id','blackout_frame');
	$(blackout_iframe).css({
		'width' : '100%', 
		'height' : '100%',
		'-moz-opacity' : '0',
		'filter' : 'alpha(opacity: 0)',
		'opacity' : '0',
		'background' : 'none',
		'border' : 'none',
		'margin' : '0'
	});
	
	$(blackout).prepend(blackout_iframe);
	$(this).prepend(blackout);
	
	//alert($('#blackout').attr('id'));
	
	//$(blackout).css("height",document.body.scrollHeight + 'px');
	//$(blackout).css("width",document.body.clientWidth + 'px');
	
}

function toCart(id, kol)
{
	if(kol*1 < 1) kol = 1;
	toajax("/show_cart.php?action=tocart&id="+id+"&kol="+kol);	
}
