function set_size() {
	document.getElementById('png').style.height=document.getElementById('container').offsetHeight + 'px';
	document.getElementById('png').style.width=document.getElementById('container').offsetWidth + 'px';
}

function show(i) {
	document.getElementById(i).style.display='block';
}

function hide(i) {
	document.getElementById(i).style.display='none';
}

function initGallery(n) {
	


	$('#'+n+"_back").click(function() {
		
		var id = $(this).parent().attr("id");
		
		//alert(id);
		var w = $("#"+id+" .list_items .item").width();
		$('#'+id+"_next").show();
		var v = $("#"+id+" .list_items .list_body").css("margin-left").replace("px","");
		if (v=="auto") {
			v = $("#"+id+" .list_items .list_body").position().left;
		}
		v = (v*1+w*1);
		$("#"+id+" .list_items .list_body").css("margin-left",v+"px");
		//alert(v);
		if (v>=0) {
			$('#'+id+"_back").hide();
		}
		return false;


	});
	$('#'+n+"_next").click(function() {
		
		var id = $(this).parent().attr("id");
		var w = $("#"+id+" .list_items .item");
		if (!w.size())
			return false;
		//alert($(w.get(0)).css("width"));
		w = $(w.get(0)).width();
		
		$('#'+id+"_back").show();
		var v = $("#"+id+" .list_items .list_body").css("margin-left").replace("px","");
		if (v=="auto") {
			v = $("#"+id+" .list_items .list_body").position().left;
		}
		v = (v*1-w*1);
		
		$("#"+id+" .list_items .list_body").css("margin-left",v+"px"); 
		/*var v = $("#"+id+" .list_items .list_body").scrollLeft()+w;
		$("#"+id+" .list_items .list_body").scrollLeft(v);*/
		//alert($("#"+id+" .list_items .item").last().left());

		var c = $("#"+id+" .list_items .list_body .item");
		c = $(c.get(c.size()-1));
		//alert(c.position().left+" "+c.width()+" = "+v);
		if (c.position().left*1+c.width()*1<=-1*v) {
			$('#'+id+"_next").hide();
		}
		//alert(id+" "+v);


		//alert(v+" "+$("#"+id+" .list_items .list_body").scrollLeft());
		return false;
		
	});
}




/* from index */

function forumTheme() {
		
	}

	function is_array(input){
		    return typeof(input)=='object'&&(input instanceof Array);
	  }

	  function myIndexOf(a,v) {
	  	/*if (a.indexOf) {
	  		return a.indexOf(v);
	  	} else {*/
	  		for (var i = 0;i<a.length;i++)
	  			if (a[i]==v) {
	  				return i;
	  			}
	  		return -1;
	  	//}
	  }

	
	function saveChecked(checkbox) {
			var c  = $.cookie('productscompare')+"";
			
			if (c+""=="null") {
				c = "";
			}
			
			var a = c.split(',');


			
			if ((!is_array(a))||(myIndexOf(a,checkbox.value)==-1)) {
				a[a.length] = checkbox.value;
				checkbox.checked = "checked";
			} else {
				var b = [];
				for (var i = 0;i<a.length;i++)
					if ((a[i]!=checkbox.value)&&(a[i]*1>0))
						b[b.length]=a[i];
				a = b;
				checkbox.checked = false;
			}
			$.cookie('productscompare', a.join(','));
			//alert(c+" "+a.join(',')+"|"+$.cookie('productscompare'));
	}
	
	function removeChecked(v) {
			var c  = $.cookie('productscompare')+"";
			if (c+""=="null") {
				c = "";
			}
			
			var a = c.split(',');
			//alert(a[1]+" = "+v + " ("+myIndexOf(a,v*1));
			
			
			
			if (myIndexOf(a,v)!=-1) {
				
				var b = [];
				for (var i = 0;i<a.length;i++)
					if ((a[i]!=v)&&(a[i]*1>0))
						b[b.length]=a[i];
				a = b;
				$("#selected_checkBox_"+v).attr("checked","");
				//checkbox.checked = false;
			}
			
			$.cookie('productscompare', a.join(','));
	}
	
	function showCompare(f,b) {
		showPopup("popup_compare",f,b);
	}
	
	
	function showPopup(o,f,b) {
		
		show('png');	
		//if (o=="popup_compare")
		$('#popup_body').html("<h3>Подождите, идёт загрузка</h3>");
			
		show("popup");

		/*var iMyWidth;
		var iMyHeight;
		iMyWidth = (window.screen.width/2) - ($("#"+o).width());
		iMyHeight = (window.screen.height/2) - ($("#"+o).height());
		d.style.top = iMyHeight+'px';
		d.style.left = iMyWidth+'px';*/
		$("#popup").css("top", ( $(window).height() - $("#popup").height() -400) / 2+$(window).scrollTop() + "px");

		$('#popup_body').load((serverRoot?serverRoot:"")+"ajax.php?a="+o+"&FOLDER="+f+"&BLOCK="+b);
		document.getElementById('container').className='noselect';
		set_size();

	}
	function show_popup(o) {
		show('png');
		show(o);
		$("#"+o).css("top", ( $(window).height() - $("#"+o).height() -400) / 2+$(window).scrollTop() + "px");
		document.getElementById('container').className='noselect';
		set_size();
		
	}
	
	window.onresize = function(){
		set_size();
	}
	
	$(function(){
		var options = {
			target: "#popup_info_div",
			url: "ajax.php",
			success: function(data) {
			}
		};
		
		$("#popup_order_callForm").submit(function () { 
			$(this).ajaxSubmit(options);
			return false;
			} );
		var options_test = {
			target: "#popup_test_info_div",
			url: "ajax.php",
			success: function(data) {
			}
		};
		
		$("#popup_order_testForm").submit(function () { 
			$(this).ajaxSubmit(options_test);
			return false;
			} );
		var options_answer = {
			target: "#forum_answer_resutl_div",
			url: "ajax.php",
			success: function(data) {
				
			}
		};	
		$("#forum_anwser_form").submit(function () { 
			$(this).ajaxSubmit(options_answer);
			return false;
		} );
		
		var options_theme = {
			target: "#forum_theme_resutl_div",
			url: "ajax.php",
			success: function(data) {
				
			}
		};	
		$("#forum_theme_form").submit(function () { 
			$(this).ajaxSubmit(options_theme);
			return false;
		} );
			
	});



	

function addSubmitToForm(formData, jqForm, options) {
    formData.push ({ "name": "web_form_submit", "value": "Отправить" });
    alert(formData.length);
 
    return true;
}


function disableAddToCompare(elementId, text)
{
	var	element = document.getElementById(elementId);
	if (!element)
		return;

	$(element)
		.removeClass("catalog-item-compare").addClass("catalog-item-compared")
		.text(text)
		//.unbind('click').removeAttr("href")
		//.css("cursor", "default");

	return false;
}

function addToCompare(element, text)
{
	if (!element || !element.href) 
		return;

	var href = element.href;
	var button = $(element);

	//button.removeClass("catalog-item-compare").addClass("catalog-item-compared").unbind('click').removeAttr("href").css("cursor", "default");

	$.get(
		href + '&ajax_compare=1&backurl=' + decodeURIComponent(window.location.pathname),
		$.proxy(
			function(data) {

				var compare = $("#compare");
				compare.html(data);
				
				this.text(text);

				if (compare.css("display") == "none") {
					compare.css({ "display": "block", "height": "0" });
					compare.animate({ "height": "22px" }, 300);
				}
			}, button
		)
	);
	
	return false;
}
