/*
modal
*/


$(document).ready(function() {	

// analytics


	$("ul#ticker01").liScroll({travelocity: 0.08});
	
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
			
		$('#dialog').load('step1.php?m=xml');

		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask').fadeOut(400).hide();

		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
			$('#mask').fadeOut(700);
		$(this).fadeOut(400);
		$('.window').fadeOut(300);
	});			
	
});

/*
step 1 validation
*/

function checkInput(f){	
	var hasError = false;
	var error = 'Please correct these issues with your information:\n\n';
	if(trim(f.quoteFirstName.value) == '' || trim(f.quoteFirstName.value) == 'First Name') {
		hasError = true;
		error += 'Missing First Name.\n';
	}
	if(trim(f.quoteLastName.value) == '' || trim(f.quoteLastName.value) == 'Last Name') {
		hasError = true;
		error += 'Missing Last Name.\n';
	}
	if(trim(f.quoteCompany.value) == '') {
		hasError = true;
		error += 'Missing Business Name.\n';
	}	
	if(trim(f.quoteEmail.value) == '') {
		hasError = true;
		error += 'Missing Email.\n';
	}		
	if((f.npa.value + f.nxx.value + f.xxxx.value).replace(/[^0-9]/g, '').length != 10) {
		hasError = true;
		error += 'Missing or Invalid Phone Number.\n';
	}
	//if(hasError) alert(error);
	return !hasError;
}

function trim(s) {
	return s.replace(/^\s*|\s*$/g, '');
}

/*
superfish - clean
*/

(function($){$.fn.superfish=function(op){var sf=$.fn.superfish,c=sf.c,$arrow = $(['<span class="',c.arrowClass,'"></span>'].join('')),over=function(){var $$=$(this),menu=getMenu($$);clearTimeout(menu.sfTimer);$$.showSuperfishUl().siblings().hideSuperfishUl()},out=function(){var $$=$(this),menu=getMenu($$),o=sf.op;clearTimeout(menu.sfTimer);menu.sfTimer=setTimeout(function(){o.retainPath=($.inArray($$[0],o.$path)>-1);$$.hideSuperfishUl();if(o.$path.length&&$$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path)}},o.delay)},getMenu=function($menu){var menu=$menu.parents(['ul.',c.menuClass,':first'].join(''))[0];sf.op=sf.o[menu.serial];return menu},addArrow=function($a){$a.addClass(c.anchorClass).append($arrow.clone())};return this.each(function(){var s=this.serial=sf.o.length;var o=$.extend({},sf.defaults,op);o.$path=$('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){$(this).addClass([o.hoverClass,c.bcClass].join(' ')).filter('li:has(ul)').removeClass(o.pathClass)});sf.o[s]=sf.op=o;$('li:has(ul)',this)[($.fn.hoverIntent&&!o.disableHI)?'hoverIntent':'hover'](over,out).each(function(){if(o.autoArrows)addArrow($('>a:first-child',this))});var $a=$('a',this);$a.each(function(i){var $li=$a.eq(i).parents('li')})}).each(function(){var menuClasses=[c.menuClass];$(this).addClass(menuClasses.join(' '))})};var sf=$.fn.superfish;sf.o=[];sf.op={};sf.c={bcClass:'sf-breadcrumb',menuClass:'sf-js-enabled',anchorClass:'sf-with-ul',arrowClass:'sf-sub-indicator',shadowClass:'sf-shadow'};sf.defaults={hoverClass:'sfHover',pathClass:'overideThisToUse',pathLevels:1,delay:800,animation:{height:'show'},speed:'normal',autoArrows:false,disableHI:false};$.fn.extend({hideSuperfishUl:function(){var o=sf.op,not=(o.retainPath===true)?o.$path:'';o.retainPath=false;var $ul=$(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass).find('>ul').hide().parent()
if($(this).parent().parent().is('li')){
	$(this).find('>span').stop().animate({height:0,top:15,left:'50%',width:0})
	$(this).find('>ul>li>span').css({height:0,top:15,left:'50%',width:0})
}
else {
	$(this).not('.current').stop().animate({backgroundPosition:'50% 52px'})
	$(this).find('>ul>li>span').css({height:0,top:15,left:'50%',width:0})
	$(this).find('>ul>li>ul>li>span').css({height:0,top:15,left:'50%',width:0})
};return this},showSuperfishUl:function(){var o=sf.op,$ul=this.addClass(o.hoverClass).find('>ul:hidden');$ul.animate(o.animation,o.speed);return this}})})(jQuery);
$(function(){
	$('.sf-menu').superfish().find('ul li').not('.current').append('<span></span>')
	.hover(
		function(){
			$(this).find('>span').stop().animate({height:29,top:0,left:0,width:'100%'})
		},
		function(){
			if($(this).hasClass('sfHover'))return
			else $(this).find('>span').stop().animate({height:0,top:15,left:'50%',width:0})
		}
	)
	$('.sf-menu>li').not('.current').hover(function(){$(this).stop().animate({backgroundPosition:'50% -72px'})},function(){$(this).not('.sfHover').stop().animate({backgroundPosition:'50% 52px'})})
})


/*!
 * liScroll 1.0
 * Examples and documentation at: 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
 * 2007-2010 Gian Carlo Mingati
 * Version: 1.0.2.1 (22-APRIL-2011)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires:
 * jQuery v1.2.x or later
 * 
 */

jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 1;
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar and Fabien Volpi
				});
				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.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$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);
				});			
		});	
};

