
/* <![CDATA[ */


var quotetab = '';

function blank(text, ele) {
	if(ele.value == text || ele.value == "Not Valid a Phone Number :(" || ele.value == "Not Valid Email :(" || ele.value == "No Numbers :(" || ele.value == "Can\'t be blank :(")
		ele.value = "";
}

function unblank(text, ele) {
	if(ele.value == "")
		ele.value = text;
}

function clicker(ele) {
if (location.pathname.replace(/^\//,'') == ele.pathname.replace(/^\//,'') && location.hostname == ele.hostname) {
			var $target = $(ele.hash);
			
			
			$target = $target.length && $target || $('[name=' + ele.hash.slice(1) +']');
			
			if ($target.length) {
				
				var targetOffset = $target.offset().left;
				
				var divOffset = $('#header-slider').offset().left;
				
				var pOffset = $('#header-slider div'+ele.hash).offset().left;
				
				var pScroll = (pOffset - divOffset) - 10;
				
				//var tHeight = $target.height();
				
				$('#header-slider').stop().animate({scrollLeft: '+=' + pScroll + 'px'}, 500);
				
				if(quotetab == 'form') {
					$('#quote_tab').html('<a href="#header_default" onclick="return clicker(this)"><img src="images/global/quote_tab.png" alt="Click to Request a Quote" /></a>');
					quotetab = 'default';
				}
				else {
					$('#quote_tab').html('<a href="#quote_form" onclick="return clicker(this)"><img src="images/global/quote_tab.png" alt="Click to Request a Quote" /></a>');
					quotetab = 'form';
				}
				
				return false;
			}
		}
}

var up_down = 'up';

$(document).ready(function() {
	
	quotetab = 'form';

	if($.browser.msie) {
		
		if($.browser.version < 7) {
			$('#header li img').attr('src', 'images/global/header/ie_green_check.png');
			$('#quote_tab img').attr('src', 'images/global/ie_quote_tab.png');	
		}
		
	}

	$('#header li a').hover(function() {
		if($.browser.version < 7)
			$('#header li.'+$($(this).parent()).attr('class')+' img').attr('src', 'images/global/header/ie_orange_check.png');
		else
			$('#header li.'+$($(this).parent()).attr('class')+' img').attr('src', 'images/global/header/orange_check.png');
	}, function() {
		if($.browser.version < 7)
			$('#header li img').attr('src', 'images/global/header/ie_green_check.png');
		else
			$('#header li img').attr('src', 'images/global/header/green_check.png');	
	});
	
	$('#quote_tab').hover(function() {
		if($.browser.version < 7)
			$('#quote_tab img').attr('src', 'images/global/ie_quote_tab_over.png');			
		else
			$('#quote_tab img').attr('src', 'images/global/quote_tab_over.png');
	}, function() {
		if($.browser.version < 7)
			$('#quote_tab img').attr('src', 'images/global/ie_quote_tab.png');	
		else
		$('#quote_tab img').attr('src', 'images/global/quote_tab.png');
	});
	
	$('#infobox-container li a[href*=#]').click(function() {
	
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			
			if ($target.length) {
				
				$('#infobox-container li a.selected').removeClass('selected');
				
				$(this).addClass('selected');
				
				var targetOffset = $target.offset().left;
				
				var divOffset = $('#infobox #slide').offset().left;
				
				var pOffset = $('#slide div'+this.hash).offset().left;
				
				var pScroll = '';
				
				pScroll = (pOffset - divOffset);
				
				//var tHeight = $target.height();
				
				
				
				
				if($.browser.version < 7) {
					if(pScroll.toString().substring(0, 1) != '-') { $('#slide').stop().animate({'left': '-'+pScroll+'px'}, 500); }
					else { $('#slide').stop().animate({'left': pScroll + 'px'}); }
				} else {
					$('#slide').stop().animate({scrollLeft: '+=' + pScroll + 'px'}, 500);
				}
				
				if(up_down == 'down') {
					
					$('#infobox').stop().animate({height: '135px'}, 500);
				
					$('.arrow').stop().animate({top: '171px'}, 500);
				
				$('.arrow img').attr('src', 'images/home/infobox/arrow.jpg');
				
				up_down = 'up';
				
				}
				
				return false;
			}
		}
	
	});
	
	$('#quote_tab a[href*=#]').click(function() {

		clicker(this);
		
		return false;
	
	});
	
	$('.arrow a ').click(function() {
	
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = $('#infobox-container li a.selected').attr('href');
			
			if(up_down  == 'up' && $('#slide div'+target).height() > 135) {
				
				var tHeight = $('#slide div'+target).height();
				
				var aHeight = tHeight + 37;
				
				$('#infobox').stop().animate({height: tHeight + 'px'}, 500);
				
				$('.arrow').stop().animate({top: aHeight + 'px'}, 500);
				
				$('.arrow img').attr('src', 'images/home/infobox/arrow_up.jpg');
				
				up_down = 'down';
				
			} else if(up_down == 'down' && $('#slide div'+target).height() > 135) {
			
				$('#infobox').stop().animate({height: '135px'}, 500);
				
				$('.arrow').stop().animate({ top: '171px'}, 500);
				
				$('.arrow img').attr('src', 'images/home/infobox/arrow.jpg');
				
				up_down = 'up';
			
			}
			
			return false;
		}
	
	});
	
	$('#quick_quote').submit(function() {
		error = false;
		var datastring = $('#quick_quote').serialize();
		
		$('#quick_quote .required').each(function(count, element) { 
			check(element, 'quick');
		});
		
		if($('#how_can_we_help :selected').val() == '') {
			$('#how_can_we_help').addClass('error');
			error = true;
		}
		
		if(!error) {
			
			$('#quote_form div').fadeOut(function() {
				$('#quote_form div').html('<p>Sending... <img src="images/global/ajax-loader.gif">');
			});
			$('#quote_form div').fadeIn();
			
			$.ajax({
				type: "POST",
				url: "includes/php/mail.php",
				data: datastring,
				dataType: 'json',
				success: function(data) {
					
					$('#quote_form div').fadeOut(function() {
					
						$('#quote_form div').html(data['msg']);
					
					});
			
					$('#quote_form div').fadeIn();
					
					window.setTimeout(function() {
						var divOffset = $('#header-slider').offset().left;
					
						var pOffset = $('#header-slider div#header_default').offset().left;
						
						var pScroll = (pOffset - divOffset);
						
						$('#header-slider').stop().animate({scrollLeft: '+=' + pScroll + 'px'}, 500);
						
						$('#quote_tab a').attr('href', '#quote_form');
						
					}, 2000);
					
				}
			});
		
		}
		
		return false;
	});
	
});

/* ]]> */


