$(document).ready(function(){
		$("#homeBlock");
		foffset = $(".footer").offset();
		$(".footer").css({position: "absolute", top: foffset.top+"px", left: foffset.left+"px"});
		newsBoxHeight = $("#newsBox").height()+90;
		$("#newsBox").css({height: newsBoxHeight+"px"});
		$("#newsBox").removeClass("active-box");
		$("#newsBox").addClass("active");
		$("#homeBlock").accord();
	});


	nextDiv = null;
	activeBox = null;
	
	function mainNavControl(index)
	{
		var activeNavMenu = $("#active");
		var clickedNavMenu = $("#mainNavMenu").children("li:eq("+index+")");
		$(activeNavMenu).attr("id","inActive");
		$(clickedNavMenu).attr("id","active");
	}
	
	function footerNavControl(index)
	{
		var activeNavMenu = $("#footerNav").children(".active");
		var clickedNavMenu = $("#footerNav").children("li:eq("+index+")");
		$(activeNavMenu).removeClass("active");
		$(clickedNavMenu).addClass("active");
	}
	function navigationControl(id)
	{
		switch (id)
		{
			case "homeBlock":
				mainNavControl(0);
				footerNavControl(0);
			break;
		
			case "aboutUsBlock":
				mainNavControl(1);
				footerNavControl(1);
			break;
			
			case "newsBlock":
				mainNavControl(2);
				footerNavControl(2);
			break;			
			
			case "servicesBlock":
			mainNavControl(3);
			footerNavControl(3);
			break;			
			
			case "galleryBlock":
			mainNavControl(4);
			footerNavControl(4);
			break;			
			
			case "contactBlock":
			mainNavControl(5);
			footerNavControl(5);
			break;
		}
	}
	
	function slideTo(id,e)
	{
		
		if ($("div:animated").length)
		{
			return false;
		}

		nextDiv = $("#"+id);
		activeBox = $(".data-block.activeBlock");
		
		if ($(nextDiv).height()<670 && id!='homeBlock')
		{
			$(nextDiv).css({height: "670px"});
		}

		offset = activeBox.offset();
		offset = activeBox.offset();

		activeLeft = offset.left;
		activeTop = offset.top;

		$(nextDiv).css({position: "absolute", top: activeTop+"px", left: activeLeft+"px"});
	
		foffset = $(".footer").offset();
		
		
		
		$(activeBox).animate(
				{
					opacity: 0,
					top: "900px"
				},
				{
					duration: 1000,
					easing: 'easeInBack', 
					complete: function() 
					{

						navigationControl(id);
		       			
						$(this).removeClass("activeBlock");
		       			$(this).css({display: "none"});
		       			
		       			var currentBlockHeight = $(nextDiv).height();
		       			$(nextDiv).css({ opacity: 1, top: "-"+currentBlockHeight+"px", display: "block"});
		       			
		       			
		       			foffset = $(".footer").offset();
		       			var myNewTopForFooter = currentBlockHeight+93;
		       			var myNewLeftForFooter = foffset.left;  
		       			
		       			$(".footer").animate({top: myNewTopForFooter+"px", left: myNewLeftForFooter+"px"});
		       			$(nextDiv).animate(
		    					{
		    						top: activeTop+"px"
		    					},
		    					{
		    						duration: 700,
		    						easing: 'easeOutBack', 
		    						complete: function() 
		    						{
				    			       	$(this).addClass("activeBlock");
				    			       	$(this).css("position","static");
				    			       	if (id=='galleryBlock')
				    			       	{
				    			       		getGallery();
				    			       	}
		    			    		}
		    						
		    					});
		    		}
				});
			return false;
		};
		
		$.fn.accord = function()
		{   
			var curDiv = $(this); 
			var currentBlockHeight = $(curDiv).height();
			$(this).find(".data-binder").hover(function(){
				if ($(".data-binder:animated").length)
				{
					return false;
				}
				if (!($(this).is(".active")))
				{
					
	if ($(".data-binder.active").is("#newsBox"))
					{
						$(".data-binder.active").animate({height: "115px"},500,"easeInOutCubic",function(){ $(this).removeClass("active"); var currentBlockHeight = $(curDiv).height(); var myNewTopForFooter = currentBlockHeight+93;});
					}
					else
					{
						$(".data-binder.active").animate({height: "115px"},500,"easeInOutCubic",function(){ $(this).removeClass("active"); var currentBlockHeight = $(curDiv).height(); var myNewTopForFooter = currentBlockHeight+93;});
					}
	
					if ($(this).is("#newsBox"))
					{
						$(this).animate({height: (newsBoxHeight)+"px"},500,"easeInOutCubic",function(){ $(this).addClass("active"); var currentBlockHeight = $(curDiv).height(); var myNewTopForFooter = currentBlockHeight+93;$(".footer").animate({top: myNewTopForFooter+"px"}); });
					}
					else
					{
						$(this).animate({height: "436px"},500,"easeInOutCubic",function(){ $(this).addClass("active"); var currentBlockHeight = $(curDiv).height(); var myNewTopForFooter = currentBlockHeight+93; $(".footer").animate({top: myNewTopForFooter+"px"}); });
					}
				}
			});
		};
		
		function getNews(id,toSlide)
		{
			if (toSlide)
			{
				slideTo('newsBlock',$("#homeBlock"));
			}
			displayBlock = $("#mainNews");
			url="getNews.php";
			data = "lang="+lang+"&id="+id;
			ajax(displayBlock,url,data);
			return false;
		}
		
		
		function getGallery()
		{
			displayBlock = $("#galleryBinder");
			url="gallery.php";
			data = "lang="+lang;
			ajaxForG(displayBlock,url,data);
			return false;
		}
		
		
			
			function ajaxForG(displayBlock,url,data)
			{
				$.ajax({
					type: "get",
					url: url,
					data: data,
					dataType: "html",
					beforeSend: function(){
						
					$(displayBlock).html("<p style=\"text-align: center;\"><img src=\"images/ajax-loader.gif\" /></p>");
					},
					complete: function(){ 
							
							
							var currentBlockHeight = $("#galleryBlock").height();
							foffset = $(".footer").offset();
							var myNewTopForFooter = currentBlockHeight+93;
							var myNewLeftForFooter = foffset.left;  
							
							$(".footer").animate({top: myNewTopForFooter+"px", left: myNewLeftForFooter+"px"});
							
					},
					success: function(html){
						$(displayBlock).html(html);
						
						$('#photos').galleryView({
							panel_width:588,
							panel_height: 420,
							frame_width: 118,
							frame_height: 85
						});
					}
				});
			}
			
		function ajax(displayBlock,url,data)
		{
			$.ajax({
				type: "get",
				url: url,
				data: data,
				dataType: "html",
				beforeSend: function(){
					//$("#loading").fadeIn("fast");
				},
				complete: function(){ 
	
				},
				success: function(html){
					$(displayBlock).html(html);
				}
			});
		}
		
		function submitContactForm()
		{
			var senderName = $("input[name='name']").val();
			var senderEmail = $("input[name='email']").val();
			var senderTel = $("input[name='tel']").val();
			var senderMsg = $("textarea[name='message']").val();
			//var contactData = "name="+senderName+"&email="+senderEmail+"&tel="+senderTel+"&message="+senderMsg;
			
			$.ajax({
				type: "POST",
				url: "sendContact.php",
				data: {name: senderName, email: senderEmail, tel: senderTel, message: senderMsg},
				dataType: "html",
				beforeSend: function(){
					//$("#loading").fadeIn("fast");
				},
				complete: function(){ 
					
				},
				success: function(html){
					$("#report").html("<p>"+html+"</p>");
					if (html=='Mail sent successfully')
					{
						var senderName = $("input[name='name']").val('');
						var senderEmail = $("input[name='email']").val('');
						var senderTel = $("input[name='tel']").val('');
						var senderMsg = $("textarea[name='message']").val('');
					}
				}
			});
			
			return false;
		}

