/*!
 * Earthlogic, Inc. Sequential Image Rotator
 * http://www.earthlogic.com/
 *
 * Copyright 2010, Earthlogic, Inc.
 * Developer: William Charlton
 * 
 * Requires jQuery.js
 * http://jquery.com/
 *
 * Date: Thur Sept 9 14:33:48 2010
 * 
 * To ease implementation for non javascript developers the properties for this plug-in are extracted from custom
 * attributes on a div tcontainer tag. This div element is also the element to bind the plugin too. Place a default
 * image in the div. If the image is to initially be random you can pass the random option as a custom attribute as well.
 * 
 * It is important to set the WIDTH and HEIGHT of the image as the plug-in reads the size to set the size of the DIV tag.
 * This helps in eliminating unwanted padding. It is also acceptable to apply css class or styles to the DIV element as well.
 * 
 * Custom tag attributes are:
 * - imgpath | Path to image directory. Can ommit and use absolute path on each image
 * - delay | The amount of time in milliseconds to wait before displaying a new image. 5000 = 5 seconds
 * - fadeout | Speed of the image fadeout animation
 * - fadein | Speed of the image fadein. This animation is not visible but is used to restore the overlay image. Set to a very fast speed like 100
 * - imgs | comma delimited string of images. If using imgpath do not use complete image urls. The image element is to be "^" delimited with the first
 *          element being the image source and the second element a href url. This allows each random image to link to a unique location. A href value 
 *          of false will result in a non linking image
 * 
 * EXAMPLE:
 *    <div id="home_image1" class="random_image"imgpath='./other/' 
 *     imgs="home-01.gif^false,other-02.gif^false,other-03.gif^false,other-04.gif^false" 
 *     delay="2500" fadeout="2000" fadein="100"
 *    >
 *       <img width="940" height="139" class="test" name="test1" id="test1" src="./other/other-01.gif" border="0"  />
 *   </div>
 */
jQuery.fn.elsequentialimage=function(){this.each(function(){var a=jQuery(this),c=a.attr("imgs").split(","),k=a.attr("preload")&&jQuery.trim(a.attr("preload"))!=""?jQuery.trim(a.attr("preload")):true,l=a.attr("delay")&&jQuery.trim(a.attr("delay"))!=""?jQuery.trim(a.attr("delay")):5E3,m=a.attr("fadeout")&&jQuery.trim(a.attr("fadeout"))!=""?jQuery.trim(a.attr("fadeout")):1200,n=a.attr("fadein")&&jQuery.trim(a.attr("fadein"))!=""?jQuery.trim(a.attr("fadein")):100,f=jQuery("img",a),o=a.attr("imgpath")&& jQuery.trim(a.attr("imgpath"))!=""?jQuery.trim(a.attr("imgpath")):"",b=f.width(),d=f.height();f.attr("src");a.css({padding:"0px",width:b+"px",height:d+"px","background-repeat":"no-repeat"});var e=false,h=0,i=true;for(b=0;b<c.length;b++){d=c[b].split("^");c[b]={image:o+d[0],href:d[1]}}if(k){d=false;for(b=0;b<c.length;b++){d=new Image;d.src=c[b].image}}var j=function(){if(i){i=false;g=c[0]}else{var g;++h;if(h>=c.length)h=0;g=c[h]}a.css({"background-image":"url("+g.image+")"});e=g.href;setTimeout(function(){f.fadeOut(m, function(){f.attr("src",g.image).fadeIn(n,function(){j()})})},l)};a.mouseover(function(){e&&e!="false"?a.css("cursor","pointer"):a.css("cursor","default")}).mouseout(function(){a.css("cursor","default")}).click(function(){if(e&&e!="false")document.location=e});j()});return this};


jQuery(document).ready(function(){
    $=jQuery;
	
	
	var superfish_options = {
		  delay:800,
		  autoArrows:false,
			dropShadows:false
	};
	
	$("ul.sf-menu").superfish(superfish_options);
	
	 $('.home_slideshow').cycle({
       fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			,timeout: 3000
			,random:true
			//,speedIn:1000
			//,speedOut:1000
            ,sync:1
			,delay:0     // additional delay (in ms) for first transition (hint: can be negative)
    }); 
    
    
    $('.seq_image').elsequentialimage();
		
	 		                      
	
	var default_search = "Search";
	$('#header_search_term_input').bind( 'focus', function(){
		var $t = $(this);
		if( $.trim( $t.val() ) == default_search ){
			$t.val("");
		}
	}).bind( 'change blur',function(){
		var $t = $(this);
		if( $.trim( $t.val() ) == "" ){
			$t.val(default_search);
		}
	}); 
	
	$('#header_search_form').bind('submit', function(e){
		var $t = $(this), $s = $('#header_search_term_input'), $v = $.trim( $s.val() ), $c=$('#header_search');
		if( $v == default_search || $v == "" ){
			e.preventDefault();
			$c.css({"background-color":"#ffc","border":"1px solid #900"});
			$s.val(default_search).css({"color":"#900"});
			setTimeout( function(){
				$c.css({"background-color":"#fff", "border":"1px solid #A7C7EB"});
				$s.css({"color":"#999"}).focus();
			}, 1000);
		} 	
	});

	 
	
});
