var site_url = "http://marmelad.perm.ru/";
var openPrd = false;
/*================ max-width, min-width for ie6 ================*/

var d = document;
var winIE = (navigator.userAgent.indexOf("MSIE 6.0") != -1 && (d.getElementById && d.documentElement.behaviorUrns)) ? true : false;
//alert(navigator.userAgent);

function bodySize(){
	if(winIE && d.documentElement.clientWidth) {
		sObj = d.getElementsByTagName("body")[0].style;
		sObj.width = (d.documentElement.clientWidth<1000) ? "1000px" : "100%";
	}
	if(winIE && $(".smallPictures")) {
		sObj = d.getElementsByTagName("body")[0].style;
		$(".smallPictures").width(($(".smallPictures").width()>600) ? "660" : "100%");
		$(".icons").width(($(".icons").width()>797) ? "797" : "");
	}
}

function init(){
	if(winIE) { bodySize(); }
}
onload = init;
if(winIE) { onresize = bodySize; }


$(document).ready(function(){
	// Index picture slow hide
    $(".indexMenu .small").hover(function() {
		switch ($(this).attr("id")) {
			case "b1": if ($(".indexImage #index_img").attr("src") != site_url+"images/index-pic-room.jpg") reviewPic(1); break;
			case "b2": if ($(".indexImage #index_img").attr("src") != site_url+"images/index-pic-cafe.jpg") reviewPic(2); break;
			case "b3": if ($(".indexImage #index_img").attr("src") != site_url+"images/index-pic-extras.jpg") reviewPic(3); break;
			case "b4": if ($(".indexImage #index_img").attr("src") != site_url+"images/index-pic-health.jpg") reviewPic(4); break;
			case "b5": if ($(".indexImage #index_img").attr("src") != site_url+"images/index-pic-contact.jpg") reviewPic(5); break;
		}
    }, function() {
		$(".indexMenu").hover(function() {}, function() {
			reviewPic(0);
		})
	});
	
	function reviewPic(n) {
		$(".indexImage #index_img").fadeOut(100, function() {
			switch (n) {
				case 1: $(this).attr("src", site_url+"images/index-pic-room.jpg"); break;
				case 2: $(this).attr("src", site_url+"images/index-pic-cafe.jpg"); break;
				case 3: $(this).attr("src", site_url+"images/index-pic-extras.jpg"); break;
				case 4: $(this).attr("src", site_url+"images/index-pic-health.jpg"); break;
				case 5: $(this).attr("src", site_url+"images/index-pic-contact.jpg"); break;
				default: $(this).attr("src", site_url+"images/index-pic-default.jpg");
			}
			$(this).fadeIn(200);
		});
	}
	
	$(".smallPictures img").click(function() {
		var jpg = $(this).attr("alt");
		var id = $(this).parent("div").parent("li").parent("ul").parent("td").children("input").val();
		$(".smallPictures div").css("border-color", "#fff");
		$(this).parent("div").css("border-color", "#ff0000");
		//alert($(this).parent("div").parent("li").parent("ul").parent("td").parent("tr").children("td.bigPicture img").html());
		$(this).parent("div").parent("li").parent("ul").parent("td").parent("tr").children("td.bigPicture").children("img").fadeOut(500, function() {
			$(this).attr("src", site_url+"images/gallery/medium/"+id+"/"+jpg+".jpg");
			$(this).load( function() {				
				$(this).fadeIn(1000);
			})
			
		})
	})
	
	//bottom on bottom browser
	browHeight = document.documentElement.clientHeight;
	if ($(".page").height() < browHeight) {
		$(".page").height(browHeight-$("bottom").height());
		$(".bottom").css({
						position: "absolute",
						bottom: "0",
						width: "100%"
						});
		$(".page").css("position", "relative");
	}
	
	//small select
	$(".selectSmall span, .strelka").click(function() {
		$(".selectSmall ul").slideDown(300, function() {
			$(this).css("display","block")
			$(".selectSmall ul li").click(function() {
				$(".selectSmall span#bronName").html($(this).html());
				$("#reserv :input").val($(this).children(":input").val());
				$(".selectSmall ul").css("display","none");	
				switch ($(this).attr("class")) {
					case "colorOrange": var color="Orange"; break; 
					case "colorRed": var color="Red"; break; 
					case "colorGreen": var color="Green"; break; 
					case "colorBlue": var color="Blue"; break; 
						
				}
				$(".actionMenu").attr("class", "actionMenu "+color);
				$(".selectSmall").attr("class", "selectSmall color"+color);
				$(".strelka").attr("class", "strelka bgr"+color);
			})
		})
	});
	
	$(".selectSmall ul li").hover(function() {
		$(this).css("background", "#E4F6FD");
	}, function() {
		$(this).css("background", "#fff");
	})
	
	$(".selectSmall ul").hover(function() {
	//*****
	}, function() {
		$(this).slideUp(300, function() {
			$(this).css("display","none");
		})
	})
	
	$("p.bron").click(function(){
		$("#reserv").submit();
	})
	
	//big select
	$(".contenner p.bigStr").click(function() {
		$(this).parent("div").children("ul").slideDown(300, function() {
			$(this).css("display","block")
			$(".contenner ul li").click(function() {
				$(this).parent("ul").parent("div").children("p.select").html($(this).html());
				$(this).parent("ul").parent("div").children("input").val($(this).html());
				$(this).parent("ul").parent("div").children("a").attr("href", $(this).children("span").html());
				$(".contenner ul").css("display","none");				
			})
		})
	});
	
	$(".contenner ul li").hover(function() {
		$(this).attr("class", "sel");
	}, function() {
		$(this).attr("class", "");
	})
	
	$(".contenner ul, .contenner p.select").hover(function() {
	//*****
	}, function() {
		$(".contenner ul").slideUp(300, function() {
			$(".contenner ul").css("display","none");
		})
	})	
		
	
	
	//===============================================================================
	
	
	$(".cafeSmallImage img").click(function() {
		var jpg = $(this).attr("alt");				
		$(".cafeBigImage img").fadeOut(500, function() {
			$(this).attr("src", site_url+"images/gallery/medium/cafe/"+jpg+".jpg");
			$(this).load( function() {				
				$(this).fadeIn(1000);
			})
			
		})
	})
	//================================================================================
	//====== Weather ====
	$(".weatherBlock .WB2 p, .weatherBlock .WB1 p").click(function(){
		var hour = $(".weatherBlock .WB2 p.WBActive").attr("id");
		var day = $(".weatherBlock .WB1 p.WBActive").attr("id");
		if ($(this).parent("div").attr("class") == "WB1") day = $(this).attr("id");
		if ($(this).parent("div").attr("class") == "WB2") hour = $(this).attr("id");
		$("#weather").load('/index.php', {action: "weather", subAction: "getWeather", day: day, hour: hour});
	})
		
	
	
	
	setInterval("pikpik()", 500);
	
	
	
	
	/*$("#menuAdminType").validate({
  		submitHandler: function(form) {
			$(form).submit();
	    },
	    rules: {
	      type: {
	      	required: true,
	      },
	      url: {
	      	required: true,
	      }
	    },
	    messages: {
			type: {
				required: "Введите наименование вида блюд"
			},
			url: {
				required: "Введите имя в адресной строке (только латиница)"
			}
	    }
	    ,errorPlacement: function(error, element) {
                var er = element.attr("name");
                $('#'+er+"Response").html(error.html());
            }
	})*/	
	
	$(":input.checkbox").click(function(){
		if ($(this).attr("checked") == true) {
			$(this).parent("td").parent("tr").children("td.inp").css("background","#ccc");
			$(this).parent("td").parent("tr").children("td.inp").css("visibility","visible");
			$(this).parent("td").parent("tr").children("td.inp").children("input").val("0");
		}
		else {
			$(this).parent("td").parent("tr").children("td.inp").css("background","none");
			$(this).parent("td").parent("tr").children("td.inp").css("visibility","hidden");
			$(this).parent("td").parent("tr").children("td.inp").children("input").val("");
		}
	})
	/*$("td.inp :input").keypress(function (event){
		alert(event.which);
		if (event.which <= 48 && event.which >= 57) event.keyCode = 0;
	});*/
	
	$(".thirdMenu li").hover(function(){
		var thss = $(this);
		
			$(this).children("div.alt_menu").css("left",$(this).children("a").width());
			$(this).children("div.alt_menu").css("display","block");
		
				
	}, function(){
		$(this).children("div.alt_menu").css("display","none");
	})

	$(".wifi").hover(			
		function(){
			var right = $(window).width() - $(this).offset().left;
			var bottom = $(window).height() - $(this).offset().top;
			//var width = $(this).parent("li").children("span").width();
			$(".alt_menu").css({bottom:bottom+10, right:right, display:"block"});
		},
		function(){
			$(".alt_menu").css({display:"none"});
		}
	);
	
	$(".wifiq").hover(			
		function(){
			var left = $(this).offset().left;
			var bottom = $(window).height() - $(this).offset().top;
			//var width = $(this).parent("li").children("span").width();
			$(".alt_menuq").css({bottom:bottom+10, left:left+35, display:"block"});
		},
		function(){
			$(".alt_menuq").css({display:"none"});
		}
	);
	
	
});
function loadTime () {$(".greenwichBlock").load('/index.php', {action: "weather", subAction: "getTime"})};


var sek = 0;
function pikpik () {
	if ($(".timeTown span").attr("style") == "") $(".timeTown span").attr("style","color:#fff");
	else $(".timeTown span").attr("style","");
	sek++;
	if (sek == 60) {
		loadTime();
		sek = 0;
	}
}


