
$(document).ready(function() {
						  			
			 //Main widget---------------------------------------->
			 $('#main_btn').click(function() {
				var $main = $("#main");
				var window_height = $(window).height();
				var header_height = $("#header").height();
				if($main.css('top') == "0px"){
					$main.animate({top: window_height - header_height -90});
					$(this).addClass("btn_open");
				}else{
					$main.animate({top:0});
					$(this).removeClass("btn_open");
				}
			  });
			  //Navigation Background Slider-------------->
			   $("#pauseplay").toggle(function () { 
				  $(this).addClass("pause");
				}, function () {
				  $(this).removeClass("pause");
				});
				
			//Lightbox
			$("a[rel^='prettyPhoto']").prettyPhoto({show_title: false});
			
			//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});
			}
			//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);
										  }
			);
														

});

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);


// Loader

$.fn.preloader = function(options){
	
	var defaults = {
		             delay:150,
					 preload_parent:"a",
					 check_timer:300,
					 ondone:function(){ },
					 oneachload:function(image){  },
					 fadein:400 
					};
	
	// variables declaration and precaching images and parent container
	 var options = $.extend(defaults, options),
	 root = $(this) , images = root.find("img").css({"visibility":"hidden",opacity:0}) ,  timer ,  counter = 0, i=0 , checkFlag = [] , delaySum = options.delay ,
	 
	 init = function(){
		
		timer = setInterval(function(){
			
			if(counter>=checkFlag.length)
			{
			clearInterval(timer);
			options.ondone();
			return;
			}
		
			for(i=0;i<images.length;i++)
			{
				if(images[i].complete==true)
				{
					if(checkFlag[i]==false)
					{
						checkFlag[i] = true;
						options.oneachload(images[i]);
						counter++;
						
						delaySum = delaySum + options.delay;
					}
					
					$(images[i]).css("visibility","visible").delay(delaySum).animate({opacity:1},options.fadein,
					function(){ $(this).parent().removeClass("preloader");   });
					
					
					
				 
				}
			}
		
			},options.check_timer) 
		 
		 
		 } ;
	
	images.each(function(){
		
		if($(this).parent(options.preload_parent).length==0)
		$(this).wrap("<a class='preloader' />");
		else
		$(this).parent().addClass("preloader");
		
		checkFlag[i++] = false;
		
		
		}); 
	images = $.makeArray(images); 
	
	
	var icon = jQuery("<img />",{
		
		id : 'loadingicon' ,
		src : theme_path+'/images/preloader/89.gif'
		
		}).hide().appendTo("body");
	
	
	
	timer = setInterval(function(){
		
		if(icon[0].complete==true)
		{
			clearInterval(timer);
			init();
			 icon.remove();
			return;
		}
		
		},100);
	
	}
