/**
 * $.include - script inclusion jQuery plugin
 * Based on idea from http://www.gnucitizen.org/projects/jquery-include/
 * @author Tobiasz Cudnik
 * @link http://meta20.net/.include_script_inclusion_jQuery_plugin
 * @license MIT
 */
// 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(CF.path + 'js/coin-slider.js');
<!-- floatdialog block -->
$.include(CF.path + 'js/floatdialog.js');
<!-- floatdialog block -->
<!-- superfish menu begin -->
$.include(CF.path + 'js/hoverIntent.js');
$.include(CF.path + 'js/superfish.js');
<!-- superfish menu end -->
<!-- tooltip begin -->
$.include(CF.path + 'js/atooltip.jquery.js');
<!-- tooltip end -->
<!-- contact form begin -->
$.include(CF.path + 'js/runonload.js');
$.include(CF.path + 'js/contact-form.js');
<!-- contact form end -->
$.include(CF.path + 'js/scrollTop.js');
$.include(CF.path + 'js/flashobject.js');
<!-- tabs begin -->
$.include(CF.path + 'js/tabs.js');
<!-- tabs end -->
<!-- hover-image begin -->
$.include(CF.path + 'js/hover-image.js');
<!-- hover-image -->
<!-- prettyPhoto begin -->
$.include(CF.path + 'js/jquery.prettyPhoto.js');
<!-- prettyPhoto end-->
<!-- imagepreloader begin -->
$.include(CF.path + 'js/imagepreloader.js');
<!-- imagepreloader end-->
<!-- gallery -->
$.include(CF.path + 'js/jquery.galleriffic.js');
$.include(CF.path + 'js/jquery.opacityrollover.js');
<!-- gallery -->
<!-- twitter -->
$.include(CF.path + 'js/jquery.twitter.search.js');
<!-- twitter -->
<!-- faded -->
$.include(CF.path + 'js/jquery.faded.js');
<!-- faded -->
$.include(CF.path + 'js/jquery.cycle.all.latest.js');
<!-- tooltip begin -->
$.include(CF.path + 'js/kwicks-1.5.1.pack.js');
<!-- tooltip end -->  
$(document).ready(function() {
	//superfish menu init
	$('ul.#menu').superfish({
		delay:       400,
		animation:   {opacity:'show',height:'show'},
		speed:       400,
		autoArrows:  false,
		dropShadows: false
	});
	//imagepreloader init
	preloadImages([
		CF.path + 'img/marker_2_active.gif',
		CF.path + 'img/marker_1_active.gif',
		CF.path + 'img/marker_top_active.gif',
		CF.path + 'img/marker_2_rotate.gif',
		CF.path + 'img/search_button_active.gif',
		CF.path + 'img/top_nav_bg.gif'
	]);
	// initiate tool tip
	// basic usage  
	$('.normaltip').aToolTip();  
	// fixed tooltip  
	$('.fixedtip').aToolTip({  
			fixed: true  
	});
	$('.clicktip').aToolTip({  
			clickIt: true,  
			tipContent: 'Hello I am aToolTip with content from param'  
	}); 
	// coin slider
	$(document).ready(function(){
		if ($("#coin-slider").length) {
			$('#coin-slider').coinslider({
				width: 940, // width of slider panel
				height: 600 // height of slider panel
			});
		}
	});
	///// jumper ////////////
	$('.hr a').click(
		function (e) {
			$('html, body').animate({scrollTop: '0px'}, 800);
			return false;
		}
	);
	// accordion
	$("#accordion dt").eq().addClass("active");
	$("#accordion dd").eq().show();
	$("#accordion dt").click(function(){
		$(this).next("#accordion dd").slideToggle("slow")
		.siblings("#accordion dd:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("#accordion dt").removeClass("active");
		return false;
	});
	// slideDown
	$(".slideDown dt").click(function(){
		$(this).toggleClass("active").parent(".slideDown").find("dd").slideToggle();
	})
	// kwicks gallery
	$('.kwicks').kwicks({
		max : 800,
		spacing : 0,
		event : 'mouseover'
	});
	///// code grabber ////////////
	$(".code a.code-icon").toggle(function(){
		$(this).find("i").text("-");
		$(this).next("div.grabber").slideDown().find("i").text("-");
	}, function(){
		$(this).find("i").text("+");
		$(this).next("div.grabber").slideUp();
	})
});	
$(document).ready(function(){
	if ($("#demo1").length) {
		$(document).ready(function(){
			$("#demo1").floatdialog("dialog1", {move: 'down', effect: false})
		})
	};
	if ($("#demo2").length) {
		$(document).ready(function(){
			$("#demo2").floatdialog("dialog2", {move: 'down', effect: false})
		})
	};
});
$(function(){
	// Twitter
	$(document).ready(function(){
		if ($("#twitter").length) {
			$("#twitter").getTwitter({
				userName: "lorem_ipsum_dol",
				numTweets: 3,
				loaderText: "Loading tweets...",
				slideIn: true,
				showHeading: false,
				headingText: "Latest Tweets",
				showProfileLink: true
			});
		}
	});
});
$(document).ready(function(){
	if ($("a[rel^='prettyPhoto']").length) {
		$(document).ready(function() {
			// prettyPhoto
			$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
			///// codegrabber ////////////
			$(".code a.code-icon").toggle(function(){
				$(this).addClass("minus").next("p").slideDown();
			}, function(){
				$(this).removeClass("minus").next("p").slideUp();
			})
		});
	}
});
function onAfter(curr, next, opts, fwd) {
	//get the height of the current slide
	var $ht = $(this).height();
	//set the container's height to that of the current slide
	$(this).parent().animate({height: $ht});
};
$(document).ready(function(){
	if ($("#shuffle").length) {	
		$.include(CF.path + 'js/jquery.easing.1.3.js');
		$('#shuffle').cycle({
			fx:     'shuffle',
			easing: 'backout',
			delay:  -1000
		});
	}
});	
$(document).ready(function(){
	if ($("#zoom").length) {
		$('#zoom').cycle({
			fx:    'zoom',
			sync:  false,
			delay: -2000
		});
	}
});	
$(document).ready(function(){
	if ($("#fade").length) {
		$('#fade').cycle();
	}
});
$(document).ready(function(){
	if ($("#curtainX").length) {
		$('#curtainX').cycle({
			fx:    'curtainX',
			sync:  false,
			delay: -2000
		});
	}
});
$(document).ready(function(){
	if ($("#scrollDown").length) {	
		$('#scrollDown').cycle({ 
				fx:      'scrollDown', 
				speedIn:  2000, 
				speedOut: 500, 
				easeIn:  'bounceout', 
				easeOut: 'backin', 
				delay:   -2000 
		});
	}
});
$(document).ready(function(){
	if ($("#fade_nav").length) {
		$('#fade_nav').cycle({ 
				fx:     'fade', 
				speed:  'fast', 
				timeout: 0, 
				next:   '#next1', 
				prev:   '#prev1' 
			});
	}
});
$(document).ready(function(){
	if ($("#text_slider").length) {	
		$('#text_slider').cycle({ 
			fx:     'scrollHorz', 
			height: 'auto',
			speed:  'slow', 
			timeout: 0, 
			next:   '#next2', 
			prev:   '#prev2',
			after: onAfter
		});
	}
});
$(document).ready(function(){
	if ($("#multi_effects").length) {
		$('#multi_effects').cycle({ 
			fx:      'all', 
			speed:  'slow',
			timeout: 2000
		});	
	}
});
$(document).ready(function(){
	if ($("#thumbs").length) {
		$('div.content').css('display', 'block');
		// Initially set opacity on thumbs and add
		// additional styling for hover effect on thumbs
		var onMouseOutOpacity = 1.0;
		$('#thumbs ul.thumbs li').opacityrollover({
			mouseOutOpacity:   onMouseOutOpacity,
			mouseOverOpacity:  0.5,
			fadeSpeed:         'fast',
			exemptionSelector: '.selected'
		});
		// Initialize Advanced Galleriffic Gallery
		var gallery = $('#thumbs').galleriffic({
			delay:                     2500,
			numThumbs:                 7,
			preloadAhead:              10,
			enableTopPager:            false,
			enableBottomPager:         true,
			maxPagesToShow:            7,
			imageContainerSel:         '#slideshow',
			controlsContainerSel:      '#controls',
			captionContainerSel:       '#caption',
			loadingContainerSel:       '#loading',
			renderSSControls:          false,
			renderNavControls:         true,
			playLinkText:              'Play Slideshow',
			pauseLinkText:             'Pause Slideshow',
			prevLinkText:              '&lsaquo; Previous Photo',
			nextLinkText:              'Next Photo &rsaquo;',
			nextPageLinkText:          '',
			prevPageLinkText:          '',
			enableHistory:             false,
			autoStart:                 false,
			syncTransitions:           true,
			defaultTransitionDuration: 900,
			onSlideChange:             function(prevIndex, nextIndex) {
			// 'this' refers to the gallery, which is an extension of $('#thumbs')
			this.find('ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 0.5);
			},
			onPageTransitionOut:       function(callback) {
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn:        function() {
				this.fadeTo('fast', 1.0);
			}
		});
	}
});
