
$(document).ready(function() {
			var $main = $("#main");
			var window_height = $(window).height();
			var header_height = $("#header").height();
			
			
			//Home widget---------------------------------------->
			 $('#home_widget_btn').click(function() {
				var $lefty = $(this).parent();
				if($lefty.css('right') == "-290px"){
					$lefty.animate({right:0});
					$(this).addClass("btn_open");
				}else{
					$lefty.animate({right:-290});
					$(this).removeClass("btn_open");
				}
			  });
			  
			  
			 //Main widget---------------------------------------->
			 $(".articleBox").hide();
			 
			  //Only for Homepage to change content box and background light
			 if(homepage){
				 $(window).scroll(function(){
					if($(window).scrollTop() != 0){
						$(".articleBox").hide();
						$('#main_btn').removeClass("btn_open");
						$("#bg_cover").stop().animate({"opacity":.6},{duration: 800, easing: "easeOutExpo"});
						mainHide = false;
					}
					else{
						window_height = $(window).height();
						header_height = $("#header").height();
							
						if(window_height > 900){
							if(parseFloat($main.css("top")) != window_height-900){
								$(".articleBox").fadeIn();
								$('#main_btn').addClass("btn_open");
								$("#bg_cover").stop().animate({"opacity":0},{duration: 800, easing: "easeOutExpo"});
								mainHide = true;
							}
						}
						else{
							if(parseFloat($main.css("top")) != 0){
								$(".articleBox").fadeIn();
								$('#main_btn').addClass("btn_open");
								$("#bg_cover").stop().animate({"opacity":0},{duration: 800, easing: "easeOutExpo"});
								mainHide = true;
							}
						}
					}
				 });
			 }
			 
			 //Only for Homepage
			 $('#main_btn').click(function() {
				window_height = $(window).height();
				header_height = $("#header").height();
				
				$main.stopTime("contentUp_timer");
				
				if(!mainHide){
					$main.stop().animate({top: window_height - header_height -190},{duration: 800, easing: "easeOutExpo", complete:showArticleBox});
					$("#bg_cover").animate({"opacity":0},{duration: 800, easing: "easeOutExpo"});
					$(this).addClass("btn_open");
					mainHide = true;
				}else{
					$(".articleBox").hide();
					if(window_height > 900){
						$main.stop().animate({top:window_height-900},{duration: 800, easing: "easeOutExpo"});
					}
					else{
						$main.stop().animate({top:0},{duration: 800, easing: "easeOutExpo"});
					}
					$("#bg_cover").animate({"opacity":.6},{duration: 800, easing: "easeOutExpo"});
					$(this).removeClass("btn_open");
					mainHide = false;
				}
			  });
			 
			 function showArticleBox(){
				 $(".articleBox").fadeIn();
			 }
			  //Navigation Background Slider-------------->
			   $("#pauseplay").toggle(function () { 
				  $(this).addClass("pause");
				}, function () {
				  $(this).removeClass("pause");
				});
				
				

			
			//Lightbox
			$("a[rel^='prettyPhoto']").prettyPhoto({show_title: false, theme: 'dark_square'});
			
			//Gallery
			//If link to an Image do Prettyphoto
			attach = $(".gallery dl dt a").attr('href');
			comp = /attachment_id/;
			if(!comp.test(attach)){
			$(".gallery dl dt a").prettyPhoto({show_title: false, theme: 'dark_square'});
			}
			//Add class image-frame
			$(".gallery dl dt a").each(function(index) {
													$(this).attr('rel', 'prettyPhoto[pp_gal]')
													$(this).children("img").addClass("image-frame");
												});
			
			//Tabs
			$("ul.tabs").tabs("div.panes > div");
			$(".accordion").tabs(".accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: null});
			
			//Hide (Collapse) the toggle containers on load
			$(".toggle_container").hide(); 
		
			//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
			$("h3.trigger").click(function(){
				$(this).children("a").toggleClass("active").parent().next().slideToggle("slow");
				return false; //Prevent the browser jump to the link anchor
			});
			
			
			//Quick Contact Form styling
			$(".quick_contact input").click(function(){
					$(this).next().fadeOut(100);
			});
			
			
			//Sidebar Menu Function
			$('#sidebar .widget ul li ul').parent().addClass('hasChildren').children('a').append("<span />");
			var children;
			$("#sidebar .widget ul li").hoverIntent(
										  function () {
											children = $(this).children("ul");
											if($(children).length > 0){
													$(children).stop(true, true).slideDown('fast');	   
											}
										  }, 
										  function () {
											  $(this).children('ul').stop(true, true).slideUp(500);
										  }
			);
			
			//Footer Menu Function
			$('footer .widget ul li ul').parent().addClass('hasChildren').children('a').append("<span />");
			var children;
			$("footer .widget ul li").hoverIntent(
										  function () {
											children = $(this).children("ul");
											if($(children).length > 0){
													$(children).stop(true, true).slideDown('fast');	   
											}
										  }, 
										  function () {
											  $(this).children('ul').stop(true, true).slideUp(500);
										  }
			);
														

});

