//jQuery.noConflict();

jQuery(document).ready(function () {

    if ($("div.iCarousel'").length > 0) {
        $('.iCarousel').iCarousel();
    }
    if ((".iCarousel a[href]").length > 0) {
        $('.iCarousel a[href][title]').qtip({
            content: {
                text: false // Use each elements title attribute
            },
            style: {
                tip: true, // Apply a speech bubble tip to the tooltip at the designated tooltip corner
                border: {
                    width: 0,
                    radius: 4
                },
                name: 'light' // Use the default light style
                //width: 510 // Set the tooltip width
            } // Give it some style
        });

    }

    if (jQuery("#maingal").length > 0) {
        createGallery("maingal",933,450);
    }
    if ($(".sbutton").length > 0) {
        //Buttons 
        $(".sbutton").hover(function () {
            $(".sbutton img")
            // first jump 
            .animate({ top: "-10px" }, 200).animate({ top: "-4px" }, 200)
            // second jump
            .animate({ top: "-7px" }, 100).animate({ top: "-4px" }, 100)
            // the last jump
            .animate({ top: "-6px" }, 100).animate({ top: "-4px" }, 100);
        });

    }
    //Timeline code
    var tot = $('.event').length;

    if (tot > 0) {
    
    /* This code is executed after the DOM has been completely loaded */

	/* The number of event sections / years with events */
	
	$('.eventList li').click(function(e){
			showWindow('<div>'+$(this).find('div.content').html()+'</div>');
	});
	
	/* Each event section is 320 px wide */
	var timelineWidth = 320*tot;
	var screenWidth = $(document).width();
	
	$('#timelineScroll').width(timelineWidth);
	
	/* If the timeline is wider than the screen show the slider: */
	if(timelineWidth > screenWidth)
	{
		$('#scroll,#slider').show();
		$('#centered,#slider').width(120*tot);
		
		/* Making the scrollbar draggable: */
		$('#bar').width((120/320)*screenWidth).draggable({

			containment: 'parent',
			drag: function(e, ui) {
	
				if(!this.elem)
				{
					/* This section is executed only the first time the function is run for performance */
					
					this.elem = $('#timelineScroll');
					
					/* The difference between the slider's width and its container: */
					this.maxSlide = ui.helper.parent().width()-ui.helper.width();

					/* The difference between the timeline's width and its container */
					this.cWidth = this.elem.width()-this.elem.parent().width();
					this.highlight = $('#highlight');
				}
				
				/* Translating each movement of the slider to the timeline: */
				this.elem.css({marginLeft:'-'+((ui.position.left/this.maxSlide)*this.cWidth)+'px'});
				
				/* Moving the highlight: */
				this.highlight.css('left',ui.position.left)
			}
		});
		
		$('#highlight').width((120/320)*screenWidth-3);
	}
	//Timeline
    }
//    if (jQuery("table a[href][rel]").length > 0) {
//        //   
//        // Destroy currrent tooltip if present
//        //if($('table a[rel]').data("qtip")) $(this).qtip("destroy");
//        // By suppling no content attribute, the library uses each elements title attribute by default
//        // Use the each() method to gain access to each elements attributes
//        var content = '<img src="';
//        content += $('table a').attr('rel');
//        content += '" alt="Loading thumbnail..."/>';

//        $('table a[rel]').each(function () {
//            $(this).qtip(
//      {
//          content: {
//              // Set the text to an image HTML string with the correct src URL to the loading image you want to use
//              text: '<img src="' + $(this).attr('rel') + '" alt="Loading thumbnail..."/>', //'<img class="throbber" src="/ClientScript/qtip/ajax-loader.gif" alt="Loading..." />',
//              //url: $('table a').attr('rel'), // Use the rel attribute of each element for the url to load
//              title: {
//                  text: $(this).text(), // Give the tooltip a title using each elements text
//                  button: 'Close' // Show a close link in the title
//              }
//          },
//          position: {
//              corner: {
//                  target: 'topRight', // Position the tooltip above the link
//                  tooltip: 'bottomLeft'
//              },
//              adjust: {
//                  screen: true // Keep the tooltip on-screen at all times
//              }
//          },
//          show: {
//              when: 'mouseover',
//              solo: true // Only show one tooltip at a time
//          },
//          hide: 'unfocus',
//          style: {
//              tip: true, // Apply a speech bubble tip to the tooltip at the designated tooltip corner
//              border: {
//                  width: 0,
//                  radius: 4
//              },
//              name: 'light', // Use the default light style
//              width: 'auto' // Set the tooltip width
//          }
//      })
//        });

    //    }

    function showWindow(data) {
        /* Each event contains a set of hidden divs that hold
        additional information about the event: */

        var title = $('.title', data).text();
        var date = $('.date', data).text();
        var body = $('.body', data).html();

        $('<div id="overlay">').css({

            width: $(document).width(),
            height: $(document).height(),
            opacity: 0.6

        }).appendTo('body').click(function () {

            $(this).remove();
            $('#windowBox').remove();

        });

        $('body').append('<div id="windowBox"><div id="titleDiv">' + title + '</div>' + body + '<div id="date">' + date + '</div></div>');

        $('#windowBox').css({
            width: 500,
            height: 350,
            left: ($(window).width() - 500) / 2,
            top: ($(window).height() - 350) / 2
        });

    }
    // activates the lightbox used at the portfolio page, if you are using a dark color scheme use another theme parameter
    if($("a[rel^='prettyPhoto']").lenght> 0) {
    
    //jQuery("a[rel^='prettyPhoto'], a[rel^='lightbox[portfolio]']").prettyPhoto({theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */	
   // 																			 });
   // jQuery("a[rel^='prettyPhoto']").prettyPhoto({
//    animationSpeed: 'normal', /* fast/slow/normal */
//    padding: 40, /* padding for each side of the picture */
//    opacity: 0.35, /* Value betwee 0 and 1 */
//    showTitle: true, /* true/false */
//    allowresize: true, /* true/false */
//    counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
//    theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
//    hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
//    modal: false, /* If set to true, only the close button will close the window */
//    changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
//    callback: function(){} /* Called when prettyPhoto is closed */
//    });
		jQuery("a[rel^='prettyPhoto'], a[rel^='lightbox']").prettyPhoto({
		overlay_gallery: false, "theme": 'light_rounded' /* light_square / dark_rounded / light_square / dark_square */															
	});

	}
	
	/*
	 * prettyPhoto 
	 */
		
	
	/* 
	 * toggle functions 
	 */
	//Hide (Collapse) the toggle containers on load
	jQuery(".toggle_content").hide(); 

	//Switch the "Open" and "Close" state per click
	jQuery("h4.toggle").toggle(function(){
		jQuery(this).addClass("active");
		}, function () {
		jQuery(this).removeClass("active");
	});

	//Slide up and down on click
	jQuery("h4.toggle").click(function(){
		jQuery(this).next(".toggle_content").slideToggle();
	});
	

    //}
    // Cufon.replace('h1,h2,h3,h4,h5,h6', { fontFamily: 'nevis' });
    //Cufon.replace('h2',{fontFamily:'Scream outlined'});
    //Cufon.replace('.l', { fontFamily: 'nevis', color: '-linear-gradient(#266F22, #062E51)', color: '#ffffff' });
    /* 
    * Cufon 
    */
    var $disable_cufon = "";

    if ($disable_cufon != 'true') {

        Cufon.replace('h4,h5,#site_name,.dropcap1,.dropcap4,.teaser_large', {});
        Cufon.replace('#blurb,#footer_teaser_text', { color: '#f3f3f3', textShadow: '#f9f9f9 1px 1px' });
        Cufon.replace('th,.light_gradient', {
            color: '-linear-gradient(#bbb, #888)',
            hover: 'true'
        });
        Cufon.replace('h3', {
            color: '-linear-gradient(#bbb, #888)'
        });
        Cufon.replace('h4.foot', {
            color: '#f3f3f3',fontSize:'15px'
        });
        Cufon.replace('.staged_slide h2, .partial_staged_slide h2, .floating_slide h2, .full_slide h2, #body_block_background h2,.widgettitle,.dropcap2,.dark_gradient', {
            color: '-linear-gradient(#999, #4d4d4d)',
            hover: 'true',
            textShadow: '#fff 1px 1px'
        });
        Cufon.replace('h2,.partial_gradient_slide h2', {});
        Cufon.replace('.large_button', { textShadow: '0 -1px 0 #888888' });

        Cufon.replace('.toggle_frame h4.toggle', { color: '-linear-gradient(#bbb, #888)', hover: 'false' });

        //fix flash of unstyled content with cufon
        jQuery('h1,h2,h3,h4,h5,#blurb,#site_name,.toggle,.light_gradient.dropcap1,.widgettitle,.dropcap2,.dropcap4,.teaser_large,.dark_gradient,th').each(function () {
            jQuery(this).css("text-indent", "0px");
        });

        var userAgent = navigator.userAgent.toLowerCase();
        if (jQuery.browser.msie) {
            var $ieVersion = jQuery.browser.version.substring(0, 1);
            if ($ieVersion == 7) {
                jQuery(".dropcap1").css({ paddingTop: "2px" });
            }
        }

    }


    $("ul.sf-menu").superfish();
    //k_menu(); //improves the css dropdown menu with animation and ie6 compatibility
    fader(".preview_images a", ".featured_item"); // this is the mainpages fading script-> when a image is clicked a fadeout followed by a fade in occurs
    k_pointer(); // this script manages the pointer below the preview pics
    k_autoslide(".preview_images a", 14000); // this script starts the automatic slideshow, number represents the time between the transition in milliseconds
    k_newsticker(".ticker span", 10000); // starts the newsticker, number defines the time between transitions in milliseconds
    k_newsticker(".pticker span", 10000);
    k_next_slide(".preview_images a", ".featured_item", ".show-next"); // shows the next slide
    k_form(); // initializes ajax sending of the contact form
    tblForm;
    if (jQuery("#show").length > 0) {
        createRotate("show", 460, 250);
    }
    site_improvements(); // adds some improvements to the site

    /*image slider*/
    if (jQuery('.featured_i').length > 0) jQuery('#featured2').levitate({
        duration: 300, 					// transition duration 
        transition: "easeInOutCubic", 	// transition easing
        opacity: 0.6, 				// opacity of second row
        opacity_level2: 0, 			// opacity of third row
        interval: 4000					// interval between auto rotate, set to false if you want to disable outorotation

    });

});
function createGallery(gal,w,h) {
	var flashvars = {
	    paramXMLPath: "/Data/Sites/1/SharedFiles/slideshow/param.xml",
		initialURL: escape(document.location)
	}
	var params = {}
	params.allowscriptaccess = "always";
	params.allownetworking = "all";
	params.wmode = "transparent";
	params.menu = "false";          
	var attributes = {}
	swfobject.embedSWF("Data/Sites/1/SharedFiles/slideshow/slideshowpro.swf", "maingal", "" + w + "", "" + h + "", "9.0.0", false, flashvars, params, attributes);  

}
function createRotate(container, w, ht) {
    var flashvars = {
        /*skin: "modieus.swf",*/
        file: "/Data/Sites/1/SharedFiles/rotator/rotate.xml",
        wmode:"opaque",
		menu:"false",
        overstretch :"fit",
        screencolor:"0xFFFFFF"
        //playlist: "bottom"

    }
    var params = {
        base: ".",
        bgcolor: "#ffffff",
        allowfullscreen: "true"
    }
    var attributes = {}
    swfobject.embedSWF("Data/Sites/1/SharedFiles/rotator/rotator.swf", "" + container + "", "" + w + "", "" + ht + "", "9.0.0", false, flashvars, params, attributes);
}

/*Cuber*/
featHeader("home/settings", "fheader", 960, 300); 

function featHeader(fx, con,w,h,css) {
    var flashvars = {};
    jQuery("#intro").height(h);
    flashvars.settingsXML = "http://www.baydaonline.org/Data/rotatordata/" + fx + ".xml";
		var params = {};
			params.allowscriptaccess = "always";
			params.allownetworking = "all";
			params.wmode = "transparent";
			params.menu ="false";
		var attributes = {};
		attributes.wmode = "transparent";
		attributes.id = "slider";
		swfobject.embedSWF("http://www.baydaonline.org/ClientScript/rotator/banner.swf", "" + con + "", "" + w + "", "" + h + "", "9", "expressInstall.swf", flashvars, attributes);
}
function tblForm() {
    jQuery("table.aspcalendarmain").attr({ "style": "none" });
    jQuery("table.aspcalendarmain tr:eq(0) td").attr({ "style": "padding:0;height:20px;" });
    jQuery("td.aspcalendarnextprevious a").attr({ "style": "none" });
    jQuery("table.aspcalendarmain tr:eq(1)").addClass("aspcalendar ui-accordion-header ui-helper-reset ui-state-default ui-corner-all");
    jQuery("table.aspcalendarmain tr:eq(1)").addClass("aspcalendartr");
    jQuery("table.aspcalendarmain .aspcalendarnextprevious:eq(0) a").addClass("ui-icon ui-icon-circle-triangle-w");

}

function k_menu()
{
		jQuery("#nav a").removeAttr('title');
		jQuery("#nav ul").css({display: "none"}); // Opera Fix
		
		jQuery(" #nav li").hover(function()
		{
			jQuery(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(400,"easeInOutQuart");
		}
		,function()
		{
			jQuery(this).find('ul:first').css({visibility: "hidden"});
		});
		
}


function k_next_slide($items_to_click, $items_to_fade,$next)
{
	$items = jQuery($items_to_fade);
	$click_these_items = jQuery($items_to_click);
	var x = 0;
	
	$items.each(function(i)
	{
		jQuery(this).find($next).click(function()
		{
		i+1 < $click_these_items.length ? x = i + 1 : x = 0;	
		$click_these_items.filter(":eq("+x+")").trigger('click');
		return false;
		});
	});
}


function k_newsticker($items_to_fade, $display_time)
{
	
	tickerchange = setInterval(k_start_ticker, $display_time);
	var $tickeritem = jQuery($items_to_fade);
	var i = 1;
	
	function k_start_ticker()
	{
	$tickeritem.filter(":eq("+i+")").trigger('fade');
	i+1 < $tickeritem.length ? i++ : i = 0;	
	}
	
	  $tickeritem.each(function(i)
	  {
		  jQuery(this).bind("fade",function()
		  {	
			  $new_ticker_item = $tickeritem.filter(":eq("+i+")");
			  
			  if( $new_ticker_item.css("display") == "none" )
			  {
				  $tickeritem.filter(":visible").fadeOut(400, function()
				  {	
					  $new_ticker_item.fadeIn(400);
				  });
			  }
			  
		  });
	  });
}


function k_autoslide($items_to_click, $display_time)
{	
	interval = setInterval(k_start_autoplay, $display_time);
	var $click_these_items = jQuery($items_to_click);
	var i = 1;
	
	$click_these_items.click(function($eventobject, $autoplay)
	{
		if(interval && !$autoplay) clearInterval(interval);
	});
	
	
	function k_start_autoplay()
	{	
		
		$click_these_items.filter(":eq("+i+")").trigger('click',[true]);
		i+1 < $click_these_items.length ? i++ : i = 0;
		
	}
	
}

function k_fader($items_to_fade, $next_or_prev)
{	
	var $items = jQuery($items_to_fade);
	var $currentitem = $items.filter(":visible");
	var $new_item;
	var $selector;
	
	if($items.length > 1)
	{
		for(i = 0; i < $items.length; i++)
		{
			if($items[i] == $currentitem[0])
			{	
				$selector = $next_or_prev >= 0 ? i != $items.length-1 ? i+1 : 0 : i == 0 ? $items.length-1 : i-1;
				
				$new_item = jQuery($items[$selector]);
				break;
			}
		}
		
		if( $new_item.css("display") == "none" )
			{	
				$currentitem.css({zIndex:1});
				$new_item.css({zIndex:2}).fadeIn(1200, function()
				{
					$currentitem.css({display:"none"});
				});
				
			}
	}
}


function fader($items_to_click, $items_to_fade)
{	
	var $item = jQuery($items_to_fade);
	
	jQuery($items_to_click).each(function(i)
	{
		jQuery(this).click(function()
		{	
			$new_item = $item.filter(":eq("+i+")");
			
			if( $new_item.css("display") == "none" )
			{
				$item.filter(":visible").fadeOut(400, function()
				{	
					$new_item.fadeIn(400);
				});
			}
			
			return false;
			
		});
		
	});
	
}

function k_pointer()
{	
	var $wrapper = jQuery(".preview_images");
	var $slider = jQuery('<div class="pointer"></div>').appendTo($wrapper);
	
	var $slider_half = $slider.width()/2;
	jQuery(".preview_images a").each(function(i)
	{
		jQuery(this).click(function()
		{	
			jQuery(".current_prev").removeClass('current_prev');
			jQuery(this).addClass('current_prev');
			
			$image_pos = jQuery(this).position();
			$newposition = $image_pos.left + jQuery(this).width()/2 - $slider_half;
			$slider.animate({"left":$newposition},600,"easeOutBack");
		});
		
	});
	
}



function k_form(){
	if(!(jQuery.browser.msie && parseInt(jQuery.browser.version) < 7)) // ajax contact form disabled in ie6, it does work but ie6 shifts layout on error :P
	{
		
	var my_error;
	jQuery(".ajax_form #send").bind("click", function(){
											 
	my_error = false;
	jQuery(".ajax_form #name, .ajax_form #message, .ajax_form #email ").each(function(i){
				
				

				
				
				var value = jQuery(this).attr("value");
				var check_for = jQuery(this).attr("id");
				var surrounding_element = jQuery(this).parent();
				if(check_for == "email"){
					if(!value.match(/^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/)){
						
						surrounding_element.attr("class","").addClass("error");
						
						my_error = true;
						}else{
						surrounding_element.attr("class","").addClass("valid");	
						}
					}
				
				if(check_for == "name" || check_for == "message"){
					if(value == ""){
						
						surrounding_element.attr("class","").addClass("error");
						
						my_error = true;
						}else{
						surrounding_element.attr("class","").addClass("valid");	
						}
					}
						   if(jQuery(".ajax_form #name, .ajax_form #message, .ajax_form #email").length  == i+1){
								if(my_error == false){
									jQuery(".ajax_form").slideUp(400);
									
									var $datastring = "ajax=true";
									jQuery(".ajax_form input, .ajax_form textarea").each(function(i)
									{
										var $name = jQuery(this).attr('name');	
										var $value = jQuery(this).attr('value');
										$datastring = $datastring + "&" + $name + "=" + $value;
									});
																		
									
									jQuery(".ajax_form #send").fadeOut(100);	
									
									jQuery.ajax({
									   type: "POST",
									   url: "send.php",
									   data: $datastring,
									   success: function(response){
									   jQuery(".ajax_form").before("<div class='ajaxresponse' style='display: none;'></div>");
									   jQuery(".ajaxresponse").html(response).slideDown(400); 
									   jQuery(".ajax_form #send").fadeIn(400);
									   jQuery(".ajax_form #name, .ajax_form #message, .ajax_form #email , .ajax_form #website").val("");
										   }
										});
									} 
							}
					});
			return false;
	});
}

}


function site_improvements()
{
	jQuery(".featured_item").prepend("<div class='corner_left ie6fix'></div><div class='corner_right ie6fix'></div>");
	
	if((jQuery.browser.msie && parseInt(jQuery.browser.version) < 7))
	{
		jQuery("#nav, .navwrap, #main, #featured, #featured_bottom, .content_top, #content, #footer").addClass("ie6fix");
	}
}




var ie6 = jQuery.browser.msie && parseInt(jQuery.browser.version) < 7;

(function($)
{ 
	$.fn.levitate = function(default_options) 
	{
		var defaults = 
		{  
			duration:600, 					// transition duration 
			transition:"easeInOutCubic", 	
			opacity:0.6,
			opacity_level2:0,
			interval: 5000
			
		};  
		
		var def = $.extend(defaults, default_options); 
		
		return this.each(function()
		{	
			// variables and elements we need
			var $container = $(this), $items = $container.find('.featured_i'), $values = [], $zindex = [], $offset = 0, $animating = false, $clicked=false;
			
			var interval = setInterval(function(){}, 50000);//fake interval needed to circumvent some js errors in not-so-good-browsers ;D
			
			jQuery(window).load(function(){
				if(def.interval && !$clicked )
					{
					interval = setInterval(function() { rotate(-1); }, def.interval); 
					}
				});
		
			//sets the opacity for elements in JS since its not yet a valid css declaration (if user wants opacity):
			if (def.opacity != 1 && def.opacity_level2 != 1)
			{	$items.not('.featured_item_active').css('opacity',def.opacity_level2);
				$container.find('.featured_item_active').css('opacity', 1);
				$container.find('.featured_item_last, .featured_item_upcoming').css('opacity', def.opacity);
				
			}
			//gets the values for each element by extracting the css, this way we can use unlimited items
			$items.each(function(i)
			{	
				var $item = $(this);
				 
				$values[i]= {
								width: $item.width(),
								top: parseInt($item.css('top')),
								left: parseInt($item.css('left')),
								opacity: $item.css('opacity')
							};
							
				$zindex[i] =	$item.css('zIndex');
							
			}); // end each loop
			
			
			$items.click(function(e)
			{	
				if (! $animating)
				{	
					$direction = e.pageX > $(window).width() / 2 ? -1 : 1;
					rotate($direction);
				}
				clearInterval(interval);
				$clicked = true;
			}); // end click
			
			
			function rotate($direction)
			{	
				if ($items.length <= 2) return;
				$animating = true;
				
				if($items.length == $offset || $items.length == ($offset*-1))
				{
					$offset = 1 * $direction;
				}
				else
				{
					$offset = $offset + $direction;
				}
								
				
				//$offset = $items.length == $offset ? 1 : $offset + 1;
				$items.each(function(i)
				{	
					var $item = $(this), $next;
					
					$next = i + $offset;
					
						if($next >= $items.length)
						{
							$next = i - $items.length + $offset;
						}
						else if($next < 0)
						{
							$next = i + $items.length + $offset;
						}
					
					//modifier of -12 for images because of border + padding				
					$item.animate($values[$next], def.duration, def.transition);
					$item.find("img").animate({width:$values[$next].width-12}, def.duration, def.transition, function()
					{
						$animating = false;
					});
					
					setTimeout(function()
					{
        				$item.css({zIndex: $zindex[$next]});
    				}, def.duration / 2);
    				
				});
			} //end rotate
		});	
	};
})(jQuery); 












/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

//**********************************************************************
//                                       Carousel
//****************************************************************
$.fn.iCarousel = function () {

    function repeat(str, num) {
        return new Array( num + 1 ).join( str );
    }
  
    return this.each(function () {
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),
            
            singleWidth = $single.outerWidth(), 
            visible = Math.ceil($wrapper.innerWidth() / singleWidth), /*/ note: doesn't include padding or border*/
            currentPage = 1,
            pages = Math.ceil($items.length / visible);            


        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }

        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect
        
        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);
        
        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            
            $wrapper.filter(':not(:animated)').animate({
                scrollLeft : '+=' + left
            }, 500, function () {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                } 

                currentPage = page;
            });                
            
            return false;
        }
        
        $wrapper.after('<a class="arrow back">&lt;</a><a class="arrow forward">&gt;</a>');
        
        // 5. Bind to the forward and back buttons
        $('a.back', this).click(function () {
            return gotoPage(currentPage - 1);                
        });
        
        $('a.forward', this).click(function () {
            return gotoPage(currentPage + 1);
        });
        
        // create a public interface to move to a specific page
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });
    });  
};

/************************************************************************
TOOL TIP
***************************************************************************/

jQuery(document).ready(function() {
	
	var $slider_type = jQuery("meta[name=slider_type]").attr('content');
	var $slider_speed = jQuery("meta[name=slider_speed]").attr('content');
	var $slider_disable = jQuery("meta[name=slider_disable]").attr('content');
	
	if($slider_type == 'fading'){$slider_img_class = "div[class^='single_fading_slide']";$loadingID = '.fading_slides';}
	if($slider_type == 'tabbed'){$slider_img_class = "div[class^='single_tabbed_slide']";$loadingID = '#tabbed_slides';}
	
	if($slider_disable == 'false'){$disable_slider = false;}
	if($slider_disable == 'true'){$disable_slider = true;}
	
	
/**
 * Slider Image Preloader
 * 
 */
	/*jQuery(function () {

		// grab the images
		var $slider_images = jQuery($slider_img_class+' span img');

		// image length
		var $max_slides = $slider_images.length;

		// remove them from DOM to prevent normal load
		jQuery('.rm_slider_img').remove();

		// start loading
		if($max_slides>0) {
			LoadSliderImage(0,$max_slides);
		}

	// loading function handler
	function LoadSliderImage(index,$max_slides) {

		if(index<$max_slides) {

			// add list to div
			jQuery('<span id="slider_img'+(index+1)+'"></span>').each(function() {
			   jQuery(this).appendTo(jQuery($loadingID+' .load_slider_img').eq(index));
			});

			// new image object
			var $img = new Image();
	
			// current image
			var $curr = jQuery("#slider_img"+(index+1));
	
			// load current image
			jQuery($img).load(function () {
		
				// hide it first + .hide() failed in safari
				jQuery(this).css('display','none');
		
				//add alt attr
				jQuery(this).attr({alt: ""});
	 
				// remove loading class from div and insert the image into it
				jQuery($curr).append(this);
		
				// fade it in
				jQuery(this).fadeIn(250,function() {
			
					if(index == ($max_slides-1)) {
							// remove loading div after all images loaded then start slider
							jQuery('#loading_slider').remove();
							
							if($slider_type == 'fading'){fadingStart();}
							
							if($slider_type == 'tabbed'){
								jQuery(".single_tabbed_slide").removeClass("noscript");
								jQuery("#thumbs").removeClass("noscript");
								tabbedStart();
							}
							
							
						}else{
						  // we are loading next item
						  LoadSliderImage(index+1,$max_slides);
						}
				});
		
			}).error(function () {
				// if loading error remove div
				jQuery($curr).remove();
				// try to load next item
				LoadSliderImage(index+1,$max_slides);
			}).attr('src', jQuery($slider_images[index]).attr('src')).attr('class', jQuery($slider_images[index]).attr('class'));
	   	  }
		}
	});
	*/
/**
 * jQuery Tools Slideshow
 * 
 */
	function fadingStart() {	
		
			jQuery(".slidetabs").tabs(".fading_slides > div.single_fading_slide", {

				// enable "cross-fading" effect
				effect: 'fade',
				fadeOutSpeed: "slow",

				// start from the beginning after the last tab
				rotate: true,
			
				onBeforeClick : function(event,index) {
									var CurrentTab = this.getCurrentPane();
										CurrentTab.next().find('.slider_content').css('display', 'none');
										CurrentTab.find('.slider_content').css('display', 'none');
								},

				onClick : function(event,index) {
									var CurrentTab = this.getCurrentPane();
										CurrentTab.find('.slider_content').css('display', 'block');
								}
			

			// use the slideshow plugin. It accepts its own configuration
			}).slideshow({clickable: false,autoplay: $disable_slider,interval: $slider_speed});
		
		jQuery('.fading_slides').css("display", "block");
	}

/**
 * jQuery Tools Tabbed Slider
 * 
 */
	function tabbedStart() {
	
			// initialize scrollable and return the programming API
			jQuery("#webtreats_tabbed_slider").scrollable({
		
				items: '#tabbed_slides',
				size: 1,
				clickable: false,
				circular: true

			// use the navigator plugin
			}).autoscroll({autoplay: $disable_slider,interval: $slider_speed}).navigator({api: true});
	}
	
});

		Cufon.now();
