var $j = jQuery.noConflict();
$j(function () {

if ( $j("#show_requestor2").val() == "0" ) {
	$j("#requestor2").hide();
}

$j("#addRequestor").click(function() {
    $j('#requestor2').slideToggle();
}); 
$j("#remove").click(function() {
    $j('#requestor2').slideToggle();
    $j("#requestor2 input[type=text]").val("");
    $j("#requestor2 input[type=radio]").removeAttr("checked");
    $j("#requestor2 span.error").hide();
});
	
	//hide the element with id "feast"
	$j("div.feast").hide();
	
	//slides the element with class "feast" when img with class "expandable" is clicked
	$j("img.expandable").click(function()
	{
		if($j('img.expandable').is('.collapsed')) {
			$j('img.expandable').attr('src','/images/collapse.png');
			$j('img.expandable').removeClass('collapsed');
			$j('img.expandable').addClass('expanded');
		}
		else {
			$j('img.expandable').attr('src','/images/expand.png');
			$j('img.expandable').removeClass('expanded');
			$j('img.expandable').addClass('collapsed');
		}
		$j('div.feast').slideToggle(900);
	});
	
	$j("ul.sf-menu").superfish(); 
	
	$j('a[rel="external"]').click( function() {
		window.open( $j(this).attr('href') );
		return false;
	});	
	
	$j('#searchArea span.printLink').click(function() {
		$j("div.feast").show();
		window.print();
		return false;
	});	
	
	//grab all the anchor tag with rel set to shareit
	$j('a[rel=shareit], #shareit-box').mouseenter(function() {		
		
		//get the height, top and calculate the left value for the sharebox
		var height = $j(this).height();
		var top = $j(this).offset().top;
		
		//get the left and find the center value
		var left = $j(this).offset().left + ($j(this).width() /2) - ($j('#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 = $j(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 = encodeURIComponent(value[1]);
		
		//assign the height for the header, so that the link is cover
		$j('#shareit-header').height(height);
		
		//display the box
		$j('#shareit-box').show();
		
		//set the position, the box should appear under the link and centered
		$j('#shareit-box').css({'top':top, 'left':left});
		
		//assign the url to the textfield
		$j('#shareit-field').val(field);
		
		//make the bookmark media open in new tab/window
		$j('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
		$j('a[rel=shareit-mail]').attr('href', 'mailto:?subject=' + title);
		$j('a[rel=shareit-delicious]').attr('href', 'http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=' + url + '&title=' + title);
		$j('a[rel=shareit-designfloat]').attr('href', 'http://www.designfloat.com/submit.php?url='  + url + '&amp;title=' + title);
		$j('a[rel=shareit-digg]').attr('href', 'http://digg.com/submit?phase=2&amp;url=' + url + '&amp;title=' + title);
		$j('a[rel=shareit-stumbleupon]').attr('href', 'http://www.stumbleupon.com/submit?url=' + url + '&title=' + title);
		$j('a[rel=shareit-twitter]').attr('href', 'http://twitter.com/home?status=See this page on the Ameritox Site: ' + url);
		$j('a[rel=shareit-facebook]').attr('href', 'http://www.facebook.com/sharer.php?u=' + url);
		
	});

	//onmouse out hide the shareit box
	$j('#shareit-box').mouseleave(function () {
		$j('#shareit-field').val('');
		$j(this).hide();
	});
	
	//hightlight the textfield on click event
	$j('#shareit-field').click(function () {
		$j(this).select();
	});
	
	$j(".iframe").colorbox({width:"748", height:"470", iframe:true});
	
	$j('a, area').filter(function () {
        return this.hostname && (this.hostname).split(':')[0] !== (location.hostname).split(':')[0] && $j(this).attr('rel') != 'external'
    }).not(':has(img, div, mailto)').addClass('external').end().click(function (e) {
        open(this.href);
        e.preventDefault()
    });
			
});
