function add_favorite(a) { if(document.all) window.external.AddFavorite(document.location.href, document.title); else if (typeof(opera)=="object") { a.rel="sidebar"; a.title=document.title; a.url=document.location.href; return true; } else window.sidebar.addPanel(document.title,document.location.href,""); return false; } 

function getAbsolutePosition(el) {
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent) {
		var tmp = getAbsolutePosition(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}


function rrand()
{
return Math.floor(arguments.length > 1 ? (999999 - 111111 + 1) * Math.random() + min : (111111 + 1) * Math.random());
 
};

    function update_bag()
    {  
    	pro = rrand();
        $.ajax({  
        type: "GET",  
        data: "pro=" + pro,    
        url: "ajax_file/cook.php",
        beforeSend: function(){
         $("#bag").show();
    },
        success: 
             function(data)
            {
      			$('#bag').html(data);
            }
				});
    }
    
    
            function autor_dools(id)
    {  
    	var id = id;
        $.ajax({  
        type: "GET",  
        data: "id=" + id,    
        url: "ajax_file/autor_dools.php",
        beforeSend: function(){
         $("#div_dools").show();
    },
        success: 
             function(data)
            {
      			$('#div_dools').html(data);
            }
				});
    }
    
        function update_zam()
    {  
    	pro = rrand();
        $.ajax({  
        type: "GET",  
        data: "pro=" + pro,    
        url: "ajax_file/zam.php",
        beforeSend: function(){
         $("#zam").show();
    },
        success: 
             function(data)
            {
      			$('#zam').html(data);
            }
				});
    }

$(document).ready(function()
{
	
	$('a.autor').live('click', function () {
		
	    var id = $(this).attr('id');	
	    $('.autor').removeClass('autor_in'); 
	    $(this).addClass('autor_in'); 
	    
	    
	    //alert (id);
		
		
	    autor_dools(id);
    });
	
/*$('#r_photo').oneTime("500ms", function() {	
	alert ("asdf");
	$(this).fadeIn("slow");
});*/
	
	$('#r_photo').fadeIn("slow");
	/*
		$(function() {
	var width = $("#images img").attr("width");
	var height = $("#images img").attr("height");
	   z = width/height;
		$("#slider").slider({
			orientation: "horizontal",
			min: 100,
			max: 666,
			value: 314,
			slide: function(event, ui) {
			y = Math.round(ui.value/z);
				$("#amount").val(ui.value);
				$("#amount2").val(y);
				$('#images img').width(ui.value);
				$('#images img').height(y);
			}
		});
		$("#amount").attr('value',width);
		$("#amount2").attr('value',height);
		
	});
*/
	
	/*
	$('#accordion-2').easyAccordion({ 
						autoStart: true, 
			slideInterval: 5000

	});
	*/


	
	$("#form1_send").hide();
	  	$("#button_send").click(function(){
  				
	  			var name = $("#form1_name").val();
	  			//alert (name.length);
	  			if (name.length == 0)
	  			{
	  				alert ("Поле Имя должно быть заполнено.")
	  				return false;
	  			}
	  			
  				var phone = $("#form1_phone").val();
  				var mail = $("#form1_mail").val();
  				if (mail.length < 3)
	  			{
	  				alert ("Поле E-mail должно быть заполнено.")
	  				return false;
	  			}
		       	var action = $("#action").attr('checked')?1:0;
		       	var post = $("#post").attr('checked')?1:0;
		       	var skidki = $("#skidki").attr('checked')?1:0;
		       	var news = $("#news").attr('checked')?1:0;
		       	
		       	
        $.ajax({  
        type: "GET",  
        data: "name=" + name + "&phone=" + phone + "&mail=" + mail + "&action=" + action + "&post=" + post + "&skidki=" + skidki + "&news=" + news,    
        url: "../ajax_file/send.php",
        beforeSend: function(){
         $("#form1_send").show();
    },
        success: 
             function(data)
            {
      			//$('#zam').html(data);
      			
      			$("#form1_send").show();
            }
				});
$("#form1").hide();		       	
});
	
	
	//PreloadImg();
/*$("#h1").hide();  
$("#home").click(function () {  
$("#h1").show(2000);  
}); */

function start_time(id_e,t)
{
	var pro = "#" + id_e;
	var prot = t + "ms";

	$(pro).oneTime(prot, function() {
      $(this).fadeIn(1000, function () {
});
    	});
	return true;
}
/*
    $(function() {
        $('a.img').lightBox();
    });
*/

/*
	$("#gallery a").lightbox();
    $.Lightbox.construct({
    	"speed": 500,
    	"show_linkback": true,
    	"keys": {
			close:	"q",
			prev:	"z",
			next:	"x"
		},
		"opacity": 0.3,
		text: {
			image:		"Фотография",
			of:			"из",
			close:		"Закрыть",
			closeInfo:	"Закрыть",
			help: {
				close:		"Закрыть",
				interact:	"NONE"
			},
			about: {
				text: 	"NONE",
				title:	"NONE",
				link:	"NONE"
			}
		},
		files: {
			images: {
				prev:		"lightbox_img/prev.gif",
				next:		"lightbox_img/next.gif",
				blank:		"lightbox_img/blank.gif",
				loading:	"lightbox_img/loading.gif"
			}
		}
    });
    */
    
/*
$("#home").oneTime("500ms", function() {
	start_time("h1",300);
	start_time("h2",300);
	start_time("h3",300);
	start_time("h4",300);
	start_time("h5",300);
	start_time("h6",300);
	start_time("text_home",300);
	

});

$("#mail").oneTime("1000ms", function() {
	start_time("m1",300);
	start_time("m2",300);
	start_time("m3",300);
	start_time("m4",300);
	start_time("m5",300);
	start_time("m6",300);
	start_time("text_mail",300);
});

$("#map").oneTime("1500ms", function() {
	start_time("mp1",300);
	start_time("mp2",300);
	start_time("mp3",300);
	start_time("mp4",300);
	start_time("mp5",300);
	start_time("mp6",300);
	start_time("text_map",300);
});
*/
/*
$("#fon_header").oneTime("3000ms", function() {
$(this).show("slide", { direction: "down" }, 1000);

});

$("#mag1").oneTime("4000ms", function() {
$(this).slideDown();
});

$("#main_menu").oneTime("5000ms", function() {
$(this).slideDown();
});


$("#content").oneTime("6000ms", function() {
$(this).slideDown();
});

$("#footer").oneTime("7000ms", function() {
$(this).slideDown();
});


$("#id_eng").click(function(){
$("#mag_eng").oneTime("500ms", function() {	
	$(this).hide("fast"); 
});

$("#mag_eng_eng").oneTime("1000ms", function() {	
	$(this).show("fast"); 
});
});


$("#id_mag_r").click(function(){
$("#mag_eng_eng").oneTime("500ms", function() {	
	$(this).hide("fast"); 
});

$("#mag_eng").oneTime("1000ms", function() {	
	$(this).show("fast"); 
});
});
*/


	/*
	$("ul#topnav li").hover(function() { //Hover over event on list item
	$(this).css({ 'background' : '#1376c9 url(topnav_active.gif) repeat-x'}); //Add background color + image on hovered list item
	$(this).find("span").show(); //Show the subnav
} , function() { //on hover out...
	$(this).css({ 'background' : 'none'}); //Ditch the background
	$(this).find("span").hide(); //Hide the subnav
});
*/
	
	/*menu*/
		$("#main_page").mouseover(
	function(){
		$(this).css("background-image","url(../img/back_td2c.png)");
	});
	$("#main_page").mouseout(
	function(){
				var id_page = $("#id_page").val();
		       if (id_page == '1')
		       {
		       	$(this).css({"background-image":"url(../img/back_td2c.png)"});
		       }
		       else
		       {
		       	$(this).css({"background-image":"url(../img/back_td2.png)"});
		       }
	});
	
	
	
	$("#big").mouseover(
	function(){
		$(this).css("background-image","url(../img/back_td2c.png)");
		$("#big_sub").show();
	});
	$("#big").mouseout(
	function(){
		
		$("#big_sub").hide();
				       var id_page = $("#id_page").val();
		       if (id_page == '16')
		       {
		       	$(this).css({"background-image":"url(../img/back_td2c.png)"});
		       }
		       else
		       {
		       	$(this).css({"background-image":"url(../img/back_td2.png)"});
		       }
	});
	
	$("#big_sub").mouseover(function(){
		       $("#big_sub").show();
		       
		       $("#big").css({"background-image":"url(../img/back_td2c.png)"});
});
	$("#big_sub").mouseout(function(){
		       $("#big_sub").hide();
		       var id_page = $("#id_page").val();
		       if (id_page == '16')
		       {
		       	$("#big").css({"background-image":"url(../img/back_td2c.png)"});
		       }
		       else
		       {
		       	$("#big").css({"background-image":"url(../img/back_td2.png)"});
		       }
});
	
	
	
		$("#ngel").mouseover(
	function(){
		$(this).css("background-image","url(../img/back_td2c.png)");
	});
	$("#ngel").mouseout(
	function(){
		$(this).css({"background-image":"url(../img/back_td2.png)"});
	});
	
		$("#mark").mouseover(
	function(){
		$(this).css("background-image","url(../img/back_td2c.png)");
		$("#marki").show();
	});
	$("#mark").mouseout(
	function(){
		
		$("#marki").hide();
				       var id_page = $("#id_page").val();
		       if (id_page == '18')
		       {
		       	$(this).css({"background-image":"url(../img/back_td2c.png)"});
		       }
		       else
		       {
		       	$(this).css({"background-image":"url(../img/back_td2.png)"});
		       }
	});
	
	$("#marki").mouseover(function(){
		       $("#marki").show();
		       
		       $("#mark").css({"background-image":"url(../img/back_td2c.png)"});
});
	$("#marki").mouseout(function(){
		       $("#marki").hide();
		       var id_page = $("#id_page").val();
		       if (id_page == '18')
		       {
		       	$("#mark").css({"background-image":"url(../img/back_td2c.png)"});
		       }
		       else
		       {
		       	$("#mark").css({"background-image":"url(../img/back_td2.png)"});
		       }
});
	
	
		$("#photo").mouseover(
	function(){
		$(this).css("background-image","url(../img/back_td2c.png)");
	});
	$("#photo").mouseout(
	function(){
		$(this).css({"background-image":"url(../img/back_td2.png)"});
	});
	
		$("#news").mouseover(
	function(){
		$(this).css("background-image","url(../img/back_td2c.png)");
	});
	$("#news").mouseout(
	function(){
		$(this).css({"background-image":"url(../img/back_td2.png)"});
	});
	
			$("#cont").mouseover(
	function(){
		$(this).css("background-image","url(../img/back_td2c.png)");
	});
	$("#cont").mouseout(
	function(){
		$(this).css({"background-image":"url(../img/back_td2.png)"});
	});
	/*menu*/

	
	$("#bag").show();
	update_bag();
	update_zam();
	/*
	$("#l_monna").mouseover(
	function(){
		$(this).css("background-position","left top")
		       .css("background-repeat","no-repeat")
		       .css("background-image","url(../img/monna_c.gif)");
	});
	$("#l_monna").mouseout(
	function(){
		$(this).css({"background-repeat":"no-repeat","background-position":"left top","background-image":"url(../img/monna_g.gif)"});
	});
	
			$("#kvart_make").mouseover(
	function(){
		$(this).css("background-image","url(img/home_make.gif)");
	});
	$("#kvart_make").mouseout(
	function(){
		$(this).css({"background-image":"url(img/home_make_in.gif)"});
	}
	);
	
	$("#home_make").mouseover(
	function(){
		$(this).css("background-image","url(img/home_make.gif)");
	});
	$("#home_make").mouseout(
	function(){
		$(this).css({"background-image":"url(img/home_make_in.gif)"});
	}
	);
	
		$("#comm_make").mouseover(
	function(){
		$(this).css("background-image","url(img/home_make.gif)");
	});
	$("#comm_make").mouseout(
	function(){
		$(this).css({"background-image":"url(img/home_make_in.gif)"});
	}
	);
	
	
		$("#main").mouseover(
	function(){
		$(this).css("background-image","url(img/main_menu_in.gif)");
	});
	$("#main").mouseout(
	function(){
		$(this).css({"background-image":"url(img/main_menu.gif)"});
	}
	);
	
			$("#cat").mouseover(
	function(){
		$(this).css("background-image","url(img/main_menu_in.gif)");
	});
	$("#cat").mouseout(
	function(){
		$(this).css({"background-image":"url(img/main_menu.gif)"});
	}
	);
	
			$("#cont").mouseover(
	function(){
		$(this).css("background-image","url(img/main_menu_in.gif)");
	});
	$("#cont").mouseout(
	function(){
		$(this).css({"background-image":"url(img/main_menu.gif)"});
	}
	);
	
	$("#about").mouseover(
	function(){
		$(this).css("background-image","url(img/main_menu_in.gif)");
	});
	$("#about").mouseout(
	function(){
		$(this).css({"background-image":"url(img/main_menu.gif)"});
	}
	);
	*/
	
	        /*del_bag*/
    $('a.del_bag').live('click', function () {
    var id = $(this).attr('id');	
    //alert (id);
	$.cookie(id, null);
    
    
    update_bag();
    });
    /*del_bag*/
	
    /*bag*/
    $('a.plus').live('click', function () {
    var id = $(this).attr('id');    
    var kol_vo = $("input#k_" + id).val();    
    var getid = $.cookie(id);
    if (getid != null)
    {
        var getid = Number(getid);
        var kol_vo = Number(kol_vo);
        var all_kol_vo = eval(getid + kol_vo);
        $.cookie(id, all_kol_vo);
    }
    
    if (getid == null)
    {
        $.cookie(id, kol_vo);
    }
    //jAlert('Товар успешно добавлен в Вашу корзину!', 'Интернет-магазин www.boilerheat.ru');
    update_bag();
    });
    /*bag*/
    
    
    
    /*zam*/
    $('a.plus_zam').live('click', function () {
    var id = $(this).attr('id');   
    $.cookie("plus_zam_" + id, id);
    $(this).css({"display":"none"});
    $("#zam_" + id).css({"color":"#FFCD00"});
    update_zam();
    });
    /*zam*/
	
	
	$("#search_all").click(function(){
	var y = getAbsolutePosition(this).y;
	var x = getAbsolutePosition(this).x + 150;
	//alert(x + ":" + y);
			$("#his_make_win").css("top",y)
		       .css("left",x);
		       $("#his_make_win").show();
});


    $("#sort").change(function () {
          var sort = $("select#sort").val();
          $.cookie("sort", sort);
          
    });
    
        $("#sort_type").change(function () {
          var sort_type = $("select#sort_type").val();
          $.cookie("sort_type", sort_type);
          
    });
  /* $('#scrollDown').cycle('scrollDown');

    $('#fade').cycle({ 
    fx:      'fade', 
    speed:    1000, 
    timeout:  3000
});*/
 

});     

