if($.browser.mozilla||$.browser.opera ){document.removeEventListener("DOMContentLoaded",$.ready,false);document.addEventListener("DOMContentLoaded",function(){$.ready()},false)}
jQuery.event.remove( window, "load", jQuery.ready );
jQuery.event.add( window, "load", function(){ jQuery.ready(); } );
jQuery.extend({
	includeStates:{},
	include:function(url,callback,dependency){
		if ( typeof callback!='function'&&!dependency){
			dependency = callback;
			callback = null;
		}
		url = url.replace('\n', '');
		jQuery.includeStates[url] = false;
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.onload = function () {
			jQuery.includeStates[url] = true;
			if ( callback )
				callback.call(script);
		};
		script.onreadystatechange = function () {
			if ( this.readyState != "complete" && this.readyState != "loaded" ) return;
			jQuery.includeStates[url] = true;
			if ( callback )
				callback.call(script);
		};
		script.src = url;
		if ( dependency ) {
			if ( dependency.constructor != Array )
				dependency = [dependency];
			setTimeout(function(){
				var valid = true;
				$.each(dependency, function(k, v){
					if (! v() ) {
						valid = false;
						return false;
					}
				})
				if ( valid )
					document.getElementsByTagName('head')[0].appendChild(script);
				else
					setTimeout(arguments.callee, 10);
			}, 10);
		}
		else
			document.getElementsByTagName('head')[0].appendChild(script);
		return function(){
			return jQuery.includeStates[url];
		}
	},
	readyOld: jQuery.ready,
	ready: function () {
		if (jQuery.isReady) return;
		imReady = true;
		$.each(jQuery.includeStates, function(url, state) {
			if (! state)
				return imReady = false;
		});
		if (imReady) {
			jQuery.readyOld.apply(jQuery, arguments);
		} else {
			setTimeout(arguments.callee, 10);
		}
	}
});

///// include js files ////////////
$.include('js/navigation.js');
$.include('js/jquery.flexibleColumns.min.js');
$.include('js/jquery.watermarkinput.js');
$.include('js/jquery.tipsy.js');
$.include('fancybox/jquery.fancybox-1.3.4.pack.js');

// Sliders

if ($('#imageSlider').length) {
	$.include('sliders/nivo-slider/jquery.nivo.slider.js');
}

if ($('#slidingpanel').length) {
	$.include('panel/js/custom_panel.js');
}

if ($('#contact').length) {
	$.include('js/jquery.jigowatt.js');
} 

	// Load Google Fonts
	WebFontConfig = {
			google: { families: ['Gentium+Book+Basic:400italic:latin','Caudex','Convergence','Cookie','Damion','Federo','Lato','Rochester','Yellowtail','Ubuntu+Condensed','Pinyon+Script','Sorts+Mill+Goudy:400italic','Open+Sans' ] }
		  };
		  (function() {
			var wf = document.createElement('script');
			wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
				'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
			wf.type = 'text/javascript';
			wf.async = 'true';
			var s = document.getElementsByTagName('script')[0];
			s.parentNode.insertBefore(wf, s);
		  })();
	

jQuery(document).ready(function(){
	
	// jQuery Nivo Slider
	if(jQuery('#imageSlider').length) {
		$('#imageSlider').nivoSlider({ 
			effect:'random',
			animSpeed:300,
			startSlide: 0,
			pauseTime:3000,
			captionOpacity: 1,
			controlNav: false, 
			pauseOnHover:true,
			directionNav: true,
			directionNavHide:false
		});
	};
	
	
	// Tabs
	if($('.widget_tabbed').length) {
	   $(".widget_tabbed").tabs();
	}
		
	
	// Scroll to Top script
	$('a[href=#top]').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
		
			
	// jQuery Tipsy
	jQuery('.social_list a').tipsy({	
		gravity: 'ne', // nw | n | ne | w | e | sw | s | se
		fade: true,
		opacity: 1
	})
			
	// jQuery Tipsy
	if($('.es-carousel').length) {
		jQuery('.es-carousel ul li a img ').tipsy({	
			gravity: 'e', // nw | n | ne | w | e | sw | s | se
			fade: 			true
		})
	};		
	
	// jQuery Toggle
	$(".toggle_container").hide(); //Hide (Collapse) the toggle containers on load)
	
	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$(".trigger").click(function(){
		var entry = $(this).next().find('p');
			entry.css('opacity','0');
		$(this).toggleClass("active").next().slideToggle(300, function() {	
			entry.animate({opacity:'1'}, 200)
		});
		return false; //Prevent the browser jump to the link anchor
	});
    
			
	// jQuery autoAlign	
	jQuery("#fsb").autoColumn(40, ".widget-container");
	jQuery("#fsb").autoHeight(".widget-container");

	jQuery(".columns").autoColumn(40, ".column");
	jQuery(".columns").autoHeight(".column");
	
	jQuery(".columns2").autoColumn(40, ".column");
	jQuery(".columns2").autoHeight(".column");
	
	jQuery(".columns3").autoColumn(40,".column");
	jQuery(".columns3").autoHeight(".column");
  
	jQuery(".columns4").autoColumn(40, ".column");
	jQuery(".columns4").autoHeight(".column");
	  
	jQuery(".columns5").autoColumn(40, ".column");
	jQuery(".columns5").autoHeight(".column");
	  
	jQuery(".columns6").autoColumn(40, ".column");
	jQuery(".columns6").autoHeight(".column");
	  
	jQuery(".columns7").autoColumn(40, ".column");
	jQuery(".columns7").autoHeight(".column");
	  
	jQuery(".columns8").autoColumn(40, ".column");
	jQuery(".columns8").autoHeight(".column");
	  
	jQuery(".columns9").autoColumn(40, ".column");
	jQuery(".columns9").autoHeight(".column");
	  
	jQuery(".columns10").autoColumn(40, ".column");
	jQuery(".columns10").autoHeight(".column");
	  
	jQuery(".columns11").autoColumn(40, ".column");
	jQuery(".columns11").autoHeight(".column");
	  
	jQuery(".columns12").autoColumn(40, ".column");
	jQuery(".columns12").autoHeight(".column");
	  
	jQuery(".columns13").autoColumn(40, ".column");
	jQuery(".columns13").autoHeight(".column");
	  
	jQuery(".columns14").autoColumn(40, ".column");
	jQuery(".columns14").autoHeight(".column");
	  
	jQuery(".columns15").autoColumn(40, ".column");
	jQuery(".columns15").autoHeight(".column");
	  
	jQuery(".columns16").autoColumn(40, ".column");
	jQuery(".columns16").autoHeight(".column");	
	

	// Gallery
	$(".gl_col_2 .gallery-item::nth-child(2n)").addClass("nomargin");
	$(".gl_col_3 .gallery-item::nth-child(3n)").addClass("nomargin");
	$(".gl_col_4 .gallery-item::nth-child(4n)").addClass("nomargin");
	   
	$('.gallery-image').hover(function() {
		// on hovering over find the element we want to fade *up*
		var fade = $('.gallery-zoom', this);
		// if the element is currently being animated (to fadeOut)...
		if (fade.is('img')) {
			// ...stop the current animation, and fade it to 1 from current position
			fade.stop().fadeTo(500, 1);
		
		} else {
			fade.fadeIn(500);
		}
	}, function () {
		var fade = $('> .gallery-zoom', this);
		 
		if (fade.is('img')) {
			fade.stop().fadeTo(500, 0);
		} else {
			fade.fadeOut(500);
		}
	});


	// Prepare loading
	jQuery('.zoomer').fancybox({
		'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});


	// jQuery data-rel to rel
	if (jQuery("a[data-rel]").length) {
		jQuery('a[data-rel]').each(function() {jQuery(this).attr('rel', jQuery(this).data('rel'));});
	}
      

	if($('#galleryContainer').length) {
	  $('#galleryContainer').width($(window).width()-80);
      $('#galleryContainer').height($(window).height()-80);

      $(window).resize(function()
         {
             $('#galleryContainer').width($(window).width()-80);
             $('#galleryContainer').height($(window).height()-80);
         });
            
         $('#galleryContainer').DOPThumbnailGallery({'SettingsXMLFilePath':'xml/SettingsThumbnailGallery.xml', 'ContentXMLFilePath':'xml/ThumbnailGallery.xml'});
	}
});
