var main_title = document.title;
var aboutLink = new Array();
var change_bottom = true;
var Opera = navigator.userAgent.indexOf('Opera')>=0;
var removeScript = false;

$(document).ready(function(){
select_active();
				var id;
				hash = location.hash.slice(1);
				//masAct = hash.split('/');
				//len = masAct.length - 1;
				//name = masAct[len];
				
				if ((hash != "") && (hash != "Home"))
				{
					$.get("/../process/get_data.php", {hash: hash}, function(data){
						id = data;
						if ((id != "1") & (id != ""))
						{
							change_page(id);
							$(" .scrollpane .scroll").jScrollPane({scrollbarWidth:6});
						}

					});
				}

});


function select_active(){
	$("#left_menu a").click(function() {
		$("#top_menu .active").removeClass("active");
		$("#left_menu .active").removeClass("active");
		$(this).addClass("active");
	});
		$("#top_menu a").click(function() {
		$("#left_menu .active").removeClass("active");
		$("#top_menu .active").removeClass("active");
		$(this).addClass("active");
	});
}
function drop_active(){
		$("#top_menu .active").removeClass("active");
		$("#left_menu .active").removeClass("active");
}



function change_main_link(obj)
{
	$(".scrl li").removeAttr("class");
	$($(obj).parent("li")).attr("class","active");
	linkText = $($(obj).find("a")).text();
	change_title(linkText);
}

function change_child_link(obj)
{
	$(".scrl li li li").removeAttr("class");
	$(obj).attr("class","active");
	linkText = $($(obj).find("a")).text();
	change_title(linkText);
}

function change_title(linkText)
{
	title = linkText+" :: "+main_title;
	document.title = title;
}

function change_page_main()
{
	$("#main").hide("slow", function(){
		$("#bottom_content").fadeOut("slow", function(){
				$("#bottom_content").load("/process/loading_bottom_content.php", {type: 'main'}, function(){$("#bottom_content").fadeIn("slow");});
			});
	});
	change_bottom = true;
}

function change_page(id)
{
	$("#dynamic_page").hide("slow", function(){
		$("#dynamic_page").load("/process/loading_content.php", {id: id}, function(){
			$("#dynamic_page").slideDown("slow");
			$(document).ready(function(){
				$("#content").jScrollPane({scrollbarWidth:6});
			});
		
		
		if (change_bottom)
		{
			$("#bottom_content").fadeOut("slow", function(){
				$("#bottom_content").load("/process/loading_bottom_content.php", {type: 'subpage'}, callback_bottom_content);
			});
			change_bottom = false;
		}
		
		});
	});
}
/*
function callback_change_page()
{
	$("#dynamic_page").slideDown("slow");
	$(document).ready(function(){
		$("#content").jScrollPane({scrollbarWidth:6});
	});
}
*/


function check_width(obj)
{
	$(obj).css("border","2px solid #000");
	var value = $(obj).attr("value");
	if (value == 'ширина')
	{
		$(obj).attr("value","");
	}
	if (value == '')
	{
		$(obj).attr("value","ширина");
	}
}

function check_heigth(obj)
{
	$(obj).css("border","2px solid #000");
	var value = $(obj).attr("value");
	if (value == 'высота')
	{
		$(obj).attr("value","");
	}
	if (value == '')
	{
		$(obj).attr("value","высота");
	}
}

function calculator_submit()
{
	var id = $("#id_el").attr("value");
	var all_valid = true;
	var width = $("#calc_type").find("#width");
	var widthMas = new Array();
	for (i=0;i<width.length;i++)
	{
		if ($(width[i]).attr("value") == "ширина")
		{
			$(width[i]).css("border","2px solid red");
			all_valid = false;
		}
		else
		{
			widthMas[i] = $(width[i]).attr("value");
		}
	}
	
	var heigth = $("#calc_type").find("#heigth");
	var heigthMas = new Array();
	for (i=0;i<heigth.length;i++)
	{
		if ($(heigth[i]).attr("value") == "высота")
		{
			$(heigth[i]).css("border","2px solid red");
			all_valid = false;
		}
		else
		{
			heigthMas[i] = $(heigth[i]).attr("value");
		}
	}
	
	if (all_valid)
	{
		type = $("#calc_type_value").attr("value");
		mark = $("#calc_mark").attr("value");
		$("#calc_display").load("/process/loading_calculator_summ.php", {id: id, width: widthMas, heigth: heigthMas, type: type, mark: mark});
	}
}

function loading_calculator(id)
{
	$("#main").hide("slow", function(){
		$("#main").load("/process/loading_calculator.php", {id: id} , callback_change_page);
	});
}

function callback_bottom_content()
{
	$("#bottom_content").fadeIn("slow");
	$(document).ready(function(){
	//slider_bottom
			var pos=0;
			var li=$("#slider_bottom ul").children();
			var liWidth=76;
			$("#slider_bottom ul").css("width",(li.length*liWidth));
			$("#slider_bottom div.right").click(function(){
				if(pos<li.length-12)
				{
					li.animate({left: -liWidth*(pos+1)},400);
					pos+=1;
				}
				else
				{
					li.animate({left: 0},400);
					pos=0;
				}
			});
			$("#slider_bottom div.left").click(function(){
				if(pos>0)
				{
					li.animate({left: -liWidth*(pos-1)},400);
					pos-=1;
				}
				else
				{
					li.animate({left: -liWidth*(li.length-10)},400);
					pos=li.length-10;
				}
			});
	});
}


function show_cancel()
{
	$("#loading_div").fadeOut();
}

function getValue(id)
{
	return document.getElementById(id).value;
}

function getDocumentHeight()
{
    return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}

function send_form(name, surname, email, phone, address, other)
{
	if (check())
	{
		$("#feedback_send").load("/process/feedback_send.php", {name: name, surname: surname, email: email, phone: phone, address: address, other: other},callback_send_form);
	}
}

function callback_send_form()
{
	$("#feedback_send").fadeIn("slow").delay(2000).fadeOut("slow");
	$("#name").attr("value","");
	$("#surname").attr("value","");
	$("#email").attr("value","");
	$("#phone").attr("value","");
	$("#address").attr("value","");
	$("#other").attr("value","");
}

function check() {

	var idname = document.getElementById('name');
	var idphone = document.getElementById('phone');
	
	if(!idname.value) {
		alert('Введите имя');
		idname.focus();
		return false;
	}
	
	if(!idphone.value) {
		alert('Введите телефон');
		idphone.focus();
		return false;
	}
	return true;
}
var aboutLink = new Array();

function getPage(str)
{
	switch (str)
	{
		case "#index":
			aboutLink['page'] = str;
			break;
		case "#services":
			aboutLink['page'] = str;
			aboutLink['pid'] = "0";
			aboutLink['order'] = "2";
			break;
		case "#price":
			aboutLink['page'] = str;
			aboutLink['pid'] = "0";
			aboutLink['order'] = "3";
			break;
		case "#for_visitors":
			aboutLink['page'] = str;
			aboutLink['pid'] = "0";
			aboutLink['order'] = "4";
			break;
		case "#about":
			aboutLink['page'] = str;
			aboutLink['pid'] = "0";
			aboutLink['order'] = "5";
			break;
		case "#for_professionals":
			aboutLink['page'] = str;
			aboutLink['pid'] = "0";
			aboutLink['order'] = "6";
			break;
		case "#contact":
			aboutLink['page'] = str;
			aboutLink['pid'] = "0";
			aboutLink['order'] = "7";
			break;
		default:
			aboutLink['page'] = "#index";
			break;
	}
}
/*$(document).ready(function(){
	var act = location.hash.split('/');
	if (act[0] != "")
	{
		getPage(act[0]);
	}
	else
	{
		aboutLink['page'] = "#index";
	}
	if (aboutLink['page'] != "#index")
	{
		var object = document.getElementById(act[0]);
		change_active_bookmark(object);
		if (act[1] == null)
		{
			act[1] = aboutLink['pid'];
		}
		if (act[2] == null)
		{
			act[2] = aboutLink['order'];
		}
		change_page(act[1], act[2]);
	}
	else
	{
		var object = document.getElementById("#index");
		change_active_bookmark(object);
		change_page_main();		
	}
});*/
