﻿
jQuery(function(){
				
	jQuery('form#aspnetForm').attr("action", window.location.href);
	
	// Set nav height if smaller than content
	jQuery('#side-nav').each(function(){
	    $this = jQuery(this).children('.inner');
	    $contentHeight = jQuery(this).prev().children('.inner').outerHeight();
	    	    
	    if ($this.height() < $contentHeight)
	        $this.height($contentHeight);	        
	});
	
	if (jQuery.browser.msie)
	{
	    jQuery('#site-main .main').addClass("shadowed-main");
	    jQuery('#site-foot').addClass("shadowed-foot");
	    
	    DD_roundies.addRule('.shadowed-main', '5px 5px 0px 0px', false);
	    DD_roundies.addRule('.shadowed-foot', '0px 0px 5px 5px', false);
	    DD_roundies.addRule('.data-input, #map, .button, .action-message', '5px', false);
	    //DD_roundies.addRule('#site-mid-panel', '5px 0px 0px 0px', false);
	    //DD_roundies.addRule('.strapline', '0px 0px 7px 7px', false);
	}
	
	jQuery('#site-main .ticker ul').liScroll();
	
	// Add request button
	jQuery('.main').prepend('<a class="thickbox" href="/request.php?placeValuesBeforeTB_=savedValues&amp;TB_iframe=true&amp;height=550&amp;width=700&amp;modal=false">Free Spec &amp; Price Guide</a>');
	
});

function ViewSpecForm()
{
	jQuery('.main a.thickbox').trigger('click');
	return false;
}

function InitHomePageImageRotator()
{
    images = jQuery('#rotator-images .image');
    
    if (images.length > 1)
    {
        i = 0;
        jQuery('#rotator-images .image').each(function(){
            jQuery(this).css("z-index", images.length-i);
            i++;
        });
        jQuery('#rotator-images').find('#rotator-images-overlay').css({ zIndex: images.length+2 });
        jQuery('#rotator-images-fade').css("z-index", images.length+1);
        
        // Preload image
        var first_img = new Image();
        first_img.onload = function(){
            jQuery('#rotator-images-overlay').fadeOut(600, function(){ jQuery(this).remove(); });
            setInterval(function(){
                i = 0;
                img = jQuery('#rotator-images .image:eq(0)').fadeOut(600, function(){
                    jQuery(this)
                        .nextAll().each(function(){ jQuery(this).css({"z-index":images.length-(i++)}) })
                        .end().css({"z-index":images.length-(i++)}).show()
                        .parent().append(jQuery(this));
                });
            }, 7000);
        }        
        first_img.src = jQuery('#rotator-images .image:eq(0)').css("background-image").replace(/^url|[\"\(\)]/g,"");
        //alert(jQuery('#rotator-images .image:eq(0)').css("background-image"));
    }
}

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

/**
* liScroll
* <http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html>
* 
*/
jQuery.fn.liScroll = function(settings) {
	settings = jQuery.extend({
	travelocity: 0.07, stoponhover: true, delay: 3000
	}, settings);		
	return this.each(function(){
			var $strip = jQuery(this);
			$strip.addClass("newsticker")
			var stripWidth = 0;
			var $mask = $strip.wrap("<div class='mask'></div>");
			var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
			var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
			$strip.find("li").each(function(i){
			    stripWidth += jQuery(this, i).outerWidth();
			});
			$strip.width(stripWidth);			
			var defTiming = stripWidth/settings.travelocity;
			var totalTravel = stripWidth/*+containerWidth*/;
			function scrollnews(spazio, tempo){
			    $strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
			}
			setTimeout(function(){
			    scrollnews(totalTravel, defTiming);
			}, settings.delay);
			if (settings.stoponhover){	
			    $strip.hover(
			        function(){
			            jQuery(this).stop();
			        },
			        function(){
			            var offset = jQuery(this).offset();
			            var residualSpace = offset.left + stripWidth;
			            var residualTime = residualSpace/settings.travelocity;
			            scrollnews(residualSpace, residualTime);
			        }
			    );
			}		
	});	
};
