function ControlTopMenu() {
	var height = $('#top_menu .content').css('height');
	if (height == "0px") {
		$("#top_menu .content").animate({"height": "+=440px"}, "slow");
	} else {
		$("#top_menu .content").animate({"height": "-=440px"}, "slow");		
	}
	
	return;
}

function show_basket(url, method, div, data) {
	sendAjaxRequest(url, method, div, data);
	document.getElementById("basket_show").style.display = "block";

}

function ajax_add_to_shoping_cart(data) {
	data.action = 'ajax_add';
 	$.ajax({
 		type: "POST",
 		url: 'shoping_cart.php',
 		data: data,
 		dataType: 'json', 
 		beforeSend: function () {
			showOverlay();
			showLoad();	
 		},
 		success: function(data) {
	 		if (data.total_price) {
	 			if (data.wheels_count) {
	 				var price_row = '';
	 				$('.shoping-cart .wheels-count').empty().append(data.wheels_count);
					$.each(data.wheels_total_price, function(i, val) {
						price_row += '<span style="color: red;"> ' + i + '</span>' + val + ' ';
					});
					$('.shoping-cart .wheels-total-price').empty().append(price_row);
	 			}
	 			if (data.tires_count) {
		 			var price_row = '';
					$('.shoping-cart .tires-count').empty().append(data.tires_count);
					$.each(data.tires_total_price, function(i, val) {
						price_row += '<span style="color: red;"> ' + i + '</span>' + val + ' ';
					});
					$('.shoping-cart .tires-total-price').empty().append(price_row);
	 			}
	 			var price_row = '';
				$.each(data.total_price, function(i, val) {
					price_row += '<span style="color: red;"> ' + i + '</span>' + val + ' ';
				});
				$('.shoping-cart .total-price').empty().append(price_row);			
			} 
			$('div.jqmAlert .jqmClose').click(function(){
				$('#model_description').fadeOut("slow");
				hideOverlay();
			});
			setTitle('Сообщение');
			setContent('Товар успешно добавлен в Вашу корзину.');
			hideLoad();
			$('#model_description').fadeIn("slow");
 		}
 	});
 	 
 	return;
}

 
function shoping_cart_update(url, div, data) {
	data.count = document.getElementById(data.id).value;
	var url = url + '?action=' + data.action;
 	$.ajax({
	   type: "POST",
	   url: url,
	   data: data,
	   success: function(html){
			$('#' + div).html(html);
	   }
 	});
 	 
 	 return;
}

function model_select_change() {
	url = document.getElementById('model_select').value;
	sendAjaxRequest(url,'GET', 'news_info', '');

}

/**********************************************************************************/
/* DIALOG */
/*********************************************************************************/

function setTitle(title) {
	$('.jqmAlertTitle  h1').empty().append(title);
}

function setContent(html) {
	$('div.jqmAlertContent').empty().append(html)
	
	return;
}

/***************************************************************************************************/
/* DESIGN MANIPULATION*/
/***************************************************************************************************/
function showOverlay() {
	$('#overlay').fadeTo(200, 0.8);
	$('#overlay').fadeIn("slow");
	
	return;
}

function hideOverlay() {
	$('#overlay').fadeOut("slow");	
}

function showLoad() {
	var loader = $('#overlay img');
	loader.center();
	loader.fadeIn("fast");

	return;
}

function hideLoad() {
	$('#overlay img').fadeOut("slow");	
}
/***************************************************************************************************/

function wheels_model_show_description(data) {
	data['action'] = 'ajax_get_description';
	$.ajax({
		url: 'wheels_model_page.php',
		method: 'POST',
		data: data,
		beforeSend: function() {
			showOverlay();
			showLoad();	
		},
		success: function (html) {
			$('div.jqmAlert .jqmClose').click(function(){
				$('#model_description').fadeOut("slow");
				hideOverlay();
			});
			setTitle('Описание');
			setContent(html);
			hideLoad();
			$('#model_description').fadeIn("slow");
		}
	});
	
	return;
}

function tires_model_show_description(data) {
	data['action'] = 'ajax_get_description';
	$.ajax({
		url: 'tires_model_page.php',
		method: 'POST',
		data: data,
		beforeSend: function() {
			showOverlay();
			showLoad();
		},
		success: function (html) {
			$('div.jqmAlert .jqmClose').mousedown( function(){
				$('#model_description').fadeOut("fast");
				hideOverlay();
			});
			setTitle('Описание');
			setContent(html);
			hideLoad();
			$('#model_description').fadeIn("slow");
			
		}
	});
	
	return;
}


function imgopen(imgf,tit){
	rand_id='image'+(Math.round(Math.random()*1000));

	outf="<html>"
	 +"<head>"
	 +"<title>"+tit+"</title>"
	 +"<style>body{margin:0px}</style>"
	 +"</head>"
	 +"<body leftmargin=0 topmargin=0>"
	 +"<img src=\""+imgf+"\">";

	iopen="iwin=self.open('"+imgf+"', '"+rand_id+"', 'width='+(img1.width)+',height='+(img1.height)+',top=0,left=0');"
	 +"iwin.document.write('"+outf+"');"
	 +"iwin.focus();";

	img1=new Image();
	img1.src=imgf;

	if(img1.width!=0) eval(iopen);

	else{
	iwin = self.open('about:blank', 'f'+rand_id, 'width=100,height=100,top=0,left=0');
	iwin.document.write("<html>"
	+"<body>Загрузка...<br>"
	 +"<"+"script>"
	  +"function imo(img1){"+iopen
	  +"self.close();"
	 +"}<"+"/script>"
	 +"<img src='"+imgf+"' onload='imo(this);'>");
	 }
	}
/*********************************************************************************/
/* jQUERY*/
/*********************************************************************************/

jQuery.fn.center = function() 
{
	var w = $(window);
	this.css("position","absolute");
	this.css("top",(w.height()-this.height())/2+w.scrollTop() + "px");
	this.css("left",(w.width()-this.width()-150)/2+w.scrollLeft() + "px");
	
	return this;
}

