/* 
	Carta - Javascript plugins call
*/

function include(path) {
    document.write('<script type="text/javascript" src="' + path + '"><\/script>');
}

/* Cufon (text replacement) */
include("js/cufon-yui.js");
include("js/ChunkFive.font.js");

/* Cool and smooth animations (optional) */
include("js/jquery.easing.1.3.js");

/* Intentional mouseover plugin */
include("js/hoverIntent.min.js");

/* Superfish dropdown menu */
include("js/superfish.js");

/* Fancybox lightbox */
include("js/jquery.fancybox-1.3.2.pack.js");

/* 
	Accordion plugin
*/
(function(jQuery) {
	jQuery.fn.wb_accordion = function(options) {
	
		/* Presets */
		var defaults = {
			slide: ".slide", // slide selector
			first: 1, // slide to open first
			fullwidth: 730, // open slide width
			height: 308, // slides height
			dropshadow: true,
			hoveropacity: 0.5,
			hovercolor: "#FFF",
			speed: 700,
			easing: "easeOutExpo" // optional
		};
		var options = jQuery.extend(defaults, options);
		
		//
		return this.each(function() {
			
			var slides = jQuery(this).find(options.slide);
			slides.css({
				"width": options.fullwidth,
				"height": options.height
			})
			.parent()
			.css("height", options.height)
						
			var count = slides.length,
				minwidth = (jQuery(this).width() - options.fullwidth) / (count - 1),
				tabindex = options.first - 1,
				last = jQuery(this).find(options.slide + ":eq(" + tabindex + ")"),
				easing = (jQuery.easing.def) ? options.easing : "linear",
				slideimages = jQuery(this).find(options.slide).children("img").hide()
				
			//
			open(jQuery(this).find(options.slide + ":eq(" + tabindex + ")"));
			
			jQuery(this).find(options.slide + ":not(:eq(" + tabindex + "))").css("width", minwidth)
						
			slideimages.each(function(i) {	
				jQuery(this).delay(i*200).fadeIn()
			})
			
			jQuery(this).find(options.slide).prepend('<div class="overlay"></span>')
			jQuery(this).find(options.slide).children("div").hide()
			
			jQuery(options.slide)
				.find(".overlay")
				.css("position", "absolute")
				.css("width", jQuery(this).width())
				.css("height", jQuery(this).height())
				.css("z-index", "50")
				.css("background", options.hovercolor)
				.hide()
			
			
			if (options.dropshadow) {	
				jQuery(this).find(options.slide + ":not(:last-child)").prepend('<div class="drop-shadow"></span>');
				jQuery(this).find(".drop-shadow").css("height", options.height);
			}
						
			jQuery(this).find(options.slide).hoverIntent(function(){
				if (!jQuery(this).hasClass("open")) {
					close(last);
					open(this);
					last = this;
				}
			}, function(){});
			
			jQuery(this).find(options.slide).hover(function(){
				jQuery(this).siblings(options.slide).find(".overlay").show().css("opacity", options.hoveropacity);
			}, function(){
				jQuery(this).siblings(options.slide).find(".overlay").hide();
			})
			
			function open(tab) {
				jQuery(tab)
					.addClass("open")
					.animate({ width: options.fullwidth }, { queue: false, duration: options.speed, "easing": easing })
				if (jQuery(tab).find("div").length)	
					jQuery(tab)
						.find("div:not(.drop-shadow, .overlay)")
						.delay(options.speed / 2)
						.slideDown(100)
			}
			
			function close(tab) {
				if (jQuery(tab).find("div").length) {			
					jQuery(tab)
						.find("div:not(.drop-shadow, .overlay)")
						.stop(true, true)
						.hide()
				}
				jQuery(tab)
					.removeClass("open")
					.animate({ width: minwidth }, { queue: false, duration: options.speed, "easing": easing })
			}
						
		})
		//
		
	}
})(jQuery)

