$(document).ready(function() {

	$('a[rel="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});	

	$("#mainNav a.link").hover(function(){
		$(this).children("img.rollover").animate({ width: 'show' }, 250);
		$(this).children("img.rollover-Text").fadeIn(250);
	}, function(){
		$(this).children("img.rollover").animate({ width: 'hide' }, 250);
		$(this).children("img.rollover-Text").fadeOut(250);
	});
	
	$('a.linkBump').hover(function() { //mouse in
		$(this).animate({ paddingLeft: '10px' }, 100);
	}, function() { //mouse out
		$(this).animate({ paddingLeft: 0 }, 100);
	});
	
	//colorbox lightbox settings
	$("#inline").colorbox({width:"50%", inline:true, href:"#treeList", title:"Trees At Risk"});
	$(".colorboxRadio").colorbox({iframe:true, width:460, height:310});
	$(".colorboxTV").colorbox({iframe:true, width:490, height:375});
	$(".mediaTV").colorbox({iframe:true, width:480, height:375});
	$(".playGame").colorbox({iframe:true, width:880, height:680});
	$(".stopVideos").colorbox({iframe:true, width:580, height:440});
	$("#inlineSafe").colorbox({width:"50%", inline:true, href:"#treeListSafe", title:"Recommended Trees"});
	$("#inlineSafe2").colorbox({width:"50%", inline:true, href:"#treeListSafe", title:"Recommended Trees"});
	$("#inlineZips").colorbox({width:"50%", inline:true, href:"#quarantineZips", title:"Quarantine Details"});
	$("a[rel='bigpics']").colorbox({transition:"elastic"});
	
	$('#Zipcode').keyup(function () {
		$('#results p').load('home.php #results span', { Zipcode : this.value });
	});
	
	$("#phone").validate({
		errorLabelContainer: $("#phone div.errorPhone")
	});
	
	$('#footer a.printPage').click(function() {
		window.print();
		return false;
	});
	
	//grab all the anchor tag with rel set to shareit
	$('a[rel=shareit], #shareit-box').mouseenter(function() {		
		
		//get the height, top and calculate the left value for the sharebox
		var height = $(this).height();
		var top = ($(this).offset().top) - 125;
		
		//get the left and find the center value
		var left = $(this).offset().left + ($(this).width() /2) - ($('#shareit-box').width() / 2);		
		
		//grab the href value and explode the bar symbol to grab the url and title
		//the content should be in this format url|title
		var value = $(this).attr('href').split('|');
		
		//assign the value to variables and encode it to url friendly
		var field = value[0];
		var url = encodeURIComponent(value[0]);
		var title = "BeetleBusters.info | Stop The ALB";
		//encodeURIComponent//(value[1]);
		
		//assign the height for the header, so that the link is cover
		$('#shareit-header').height(height);
		
		//display the box
		$('#shareit-box').show();
		
		//set the position, the box should appear under the link and centered
		$('#shareit-box').css({'top':top, 'left':left});
		
		//assign the url to the textfield
		$('#shareit-field').val(field);
		
		//make the bookmark media open in new tab/window
		$('a.shareit-sm').attr('target','_blank');
		
		//Setup the bookmark media url and title http://www.facebook.com/sharer.php?u=http://davidwalsh.name/dw-content/digg-share.php?My%20Story%201
		$('a[rel=shareit-mail]').attr('href', 'mailto:?subject=' + title);
		$('a[rel=shareit-delicious]').attr('href', 'http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=' + url + '&title=' + title);
		$('a[rel=shareit-designfloat]').attr('href', 'http://www.designfloat.com/submit.php?url='  + url + '&amp;title=' + title);
		$('a[rel=shareit-digg]').attr('href', 'http://digg.com/submit?phase=2&amp;url=' + url + '&amp;title=' + title);
		$('a[rel=shareit-stumbleupon]').attr('href', 'http://www.stumbleupon.com/submit?url=' + url + '&title=' + title);
		$('a[rel=shareit-twitter]').attr('href', 'http://twitter.com/home?status=We need your help to stop the ALB. Learn the signs. Look for it. Report it. And never move firewood. www.beetlebusters.info');
		$('a[rel=shareit-facebook]').attr('href', 'http://www.facebook.com/sharer.php?u=' + url);
		
	});

	//onmouse out hide the shareit box
	$('#shareit-box').mouseleave(function () {
		$('#shareit-field').val('');
		$(this).hide();
	});
	
	//hightlight the textfield on click event
	$('#shareit-field').click(function () {
		$(this).select();
	});
		
});
