/* <![CDATA[ */


var quotetab = '';

function blank(text, ele) {
	if(ele.value == text)
		ele.value = "";
}

function unblank(text, ele) {
	if(ele.value == "")
		ele.value = text;
}

$('.portfolio_item').click(function() {
	location.href = $(this).children('p').children('a').attr('href');
});

$('.portfolio_item').hover(function() {
	$(this).addClass('hover');
}, function() {
	$(this).removeClass('hover');	
});

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/default/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/default/quote_tab.png" alt="Click to Request a Quote" /></a>');
				quotetab = 'form';
			}
		}
	}
			
	return false;
}

$('#quote_tab a[href*=#]').click(function() {

	clicker(this);
	
	return false;

});

$(document).ready(function() {
	
	quotetab = 'form';
	
	if($.browser.msie) {
		
		if($.browser.version < 7) {
			$('#header li img').attr('src', '../images/default/header/ie_green_check.png');
			$('#quote_tab img').attr('src', '../images/default/ie_quote_tab.png');	
		}
		
	}

	$('#header li a').hover(function() {
		if($.browser.version < 7)
			$('#header li.'+$($(this).parent()).attr('class')+' img').attr('src', '../images/default/header/ie_orange_check.png');
		else
			$('#header li.'+$($(this).parent()).attr('class')+' img').attr('src', '../images/default/header/orange_check.png');
	}, function() {
		if($.browser.version < 7)
			$('#header li img').attr('src', '../images/default/header/ie_green_check.png');
		else
			$('#header li img').attr('src', '../images/default/header/green_check.png');	
	});
	
	$('#quote_tab').hover(function() {
		if($.browser.version < 7)
			$('#quote_tab img').attr('src', '../images/default/ie_quote_tab_over.png');			
		else
		$('#quote_tab img').attr('src', '../images/default/quote_tab_over.png');
	}, function() {
		if($.browser.version < 7)
			$('#quote_tab img').attr('src', '../images/default/ie_quote_tab.png');	
		else
		$('#quote_tab img').attr('src', '../images/default/quote_tab.png');
	});
	
	$('#infobox 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 li a').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 = (pOffset - divOffset) - 10;
				
				//var tHeight = $target.height();
				
				$('#slide').stop().animate({scrollLeft: '+=' + pScroll + 'px'}, 500);
				
				$('#infobox').stop().animate({height: '200px'}, 500);
				
				$('.arrow').stop().animate({top: '185px'}, 500);
				
				return false;
			}
		}
	
	});
	
	
	$('.arrow a ').click(function() {
	
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = $('#infobox li a.selected').attr('href');
			
			var tHeight = $('#slide div'+target).height() > 200 ? $('#slide div'+target).height() + 55 : 200;
			
			var aHeight = tHeight - 15;
			
			$('#infobox').stop().animate({height: tHeight + 'px'}, 500);
			
			$('.arrow').stop().animate({top: aHeight + 'px'}, 500);
			
			return false;
		}
	
	});
	
	$('#quick_quote').submit(function() {
		error = false; 
									 
		var datastring = $('#quick_quote').serialize();
		
		$('#quick_quote .required').each(function(count, element) { 
			check(element)
		});
		
		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/default/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;
	});
	
});
/* ]]> */