// overload jquery's onDomReady
if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
        document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
        document.addEventListener( "DOMContentLoaded", function(){ jQuery.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('/common/js/cufon/FrancophilSans_500-FrancophilSans_700.font.js');
$.include('/common/js/jquery.easing.1.3.js');

	// Dropdown Menu Plugin
	if (jQuery(".ddsmoothmenu").length) {
		$.include('/common/js/ddsmoothmenu.js');
	}

	// jQuery flexible columns
	if (jQuery("#fsb, .column").length) {
		$.include('/common/js/jquery.flexibleColumns.min.js');
		jQuery(function(){

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

// ========================================= Sliders ===================================================

	// jQuery Accordion
	if (jQuery("#accordion").length) {
		$.include('/common/js/accordion-slider/jquery.elegantAccordion.js');
		jQuery(document).ready(function(){
			jQuery('#accordion').eAccordion ({
				easing: 'swing',                // Anything other than "linear" or "swing" requires the easing plugin
				autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not
				startStopped: false,            // If autoPlay is on, this can force it to start stopped
				stopAtEnd: false,				// If autoplay is on, it will stop when it reaches the last slide
				delay: 4500,                    // How long between slide transitions in AutoPlay mode
				animationTime: 600,             // How long the slide transition takes
				hashTags: true,                 // Should links change the hashtag in the URL?
				pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
				width: null,					// Override the default CSS width
				height: null,					// Override the default CSS height
				expandedWidth: '422px'			// Width of the expanded slide
			});
		});
	}

	// jQuery Cycle
	if (jQuery(".widget_recent_projects").length) {
		$.include('/common/js/jquery.cycle.all.min.js');
		jQuery(function(){
			jQuery('.widget_recent_projects ul').cycle({
				fx: 'scrollLeft',
				timeout: 5000,
				delay: -1000
			});
		});
	}

	// jQuery PrettyPhoto
	if (jQuery("a[data-rel^='prettyPhoto']").length) {
		$.include('/common/js/jquery.prettyPhoto.js');
	}

	// jQuery Tinycarousel
	if (jQuery("#slider-code").length) {
		$.include('/common/js/jquery.tinycarousel.js');
		jQuery(document).ready(function(){
			jQuery.fn.showFeatureText = function() {
			  return this.each(function(){    
				var box = jQuery(this);
				var text = jQuery('h4',this);    
			
				text.css({ position: 'absolute', bottom: '0px' }).hide();
			
				box.hover(function(){
				  text.slideDown("fast");
				},function(){
				  text.slideUp("fast");
				});
			
			  });
			}
				
			// jQuery text slide up / slide down effect
			jQuery('#slider-code .overview li').showFeatureText();
			
			// jQuery Tinycarousel
			jQuery('#slider-code').tinycarousel({
				start: 1, // where should the carousel start?
				display: 4, // how many blocks do you want to move at 1 time?
				axis: 'x', // vertical or horizontal scroller? ( x || y ).
				controls: true, // show left and right navigation buttons.
				pager: false, // is there a page number navigation present?
				interval: false, // move to another block on intervals.
				intervaltime: 3000, // interval time in milliseconds.
				rewind: true, // If interval is true and rewind is true it will play in reverse if the last slide is reached.
				animation: true, // false is instant, true is animate.
				duration: 1000, // how fast must the animation move in ms?
				callback: null // function that executes after every move
			});
		});
	}

	// jQuery tipsy
	if (jQuery(".social").length) {
		$.include('/common/js/jquery.tipsy.js');
	}

	// jQuery Watermark Plugin
	if (jQuery(".widget_search").length) {
		$.include('/common/js/jquery.watermarkinput.js');
	}

	if (jQuery(".gototop").length) {
		$.include('/common/js/jquery.localscroll-min.js');
		$.include('/common/js/jquery.scrollTo-min.js');
	}
	
	// Contact Form Plugin
	if (jQuery("#contact").length) {
		$.include('/common/js/jquery.jigowatt.js');
	}

	// jQuery Uniform Plugin
	if (jQuery("select, input:checkbox, input:radio").length) {
		$.include('/common/js/jquery.uniform.min.js');
	}

	// Scripts Initials
	if (jQuery("body").length) {
		$.include('/common/js/common.js');
	}
