jQuery(function() {
$("div.background2").css("opacity","0");
$("div.background3").css("opacity","0");
$("div.background4").css("opacity","0");
$("div.background5").css("opacity","0");

	  var temp1 = $("#informationTitle").html();
	  var temp2 = $("#informationTitle2").html();
	  var temp3 = $("#informationTitle3").html();
	  var temp4 = $("#informationTitle4").html();

    /*$("a.PhysiciansLink").hover(
      function () {
		  $("#informationTitle").html(temp1);
		  $("div.background").stop().animate({ 
			opacity: 1
		  }, 700 );
		  $("div.background3").stop().animate({ 
			opacity: 0
		  }, 700 );
		  $("div.background4").stop().animate({ 
			opacity: 0
		  }, 700 );
		  $("div.background2").stop().animate({ 
			opacity: 0
		  }, 700 );
      }, 
      function () {
		  
      }
    );*/

	window.setTimeout(function() {
		rotateImages1();
	}, 1);
	
	function rotateImages1() {
		setTimeout(function() {
			  $("#informationTitle").html(temp2);
			  $("div.background").animate({ 
				opacity: 0
			  }, 700 );
			  $("div.background3").animate({ 
				opacity: 0
			  }, 700 );
			  $("div.background4").animate({ 
				opacity: 0
			  }, 700 );
			  $("div.background2").animate({ 
				opacity: 1
			  }, 700 );
			  rotateImages2();
		}, 6000);
	};
	
	function rotateImages2() {
		setTimeout(function() {
			  $("#informationTitle").html(temp3);
			  $("div.background").stop().animate({ 
				opacity: 0
			  }, 700 );
			  $("div.background3").stop().animate({ 
				opacity: 1
			  }, 700 );
			  $("div.background4").stop().animate({ 
				opacity: 0
			  }, 700 );
			  $("div.background2").stop().animate({ 
				opacity: 0
			  }, 700 );
			  rotateImages3();
		}, 6000);
	};
	
	function rotateImages3() {
		setTimeout(function() {
			  $("#informationTitle").html(temp4);
			  $("div.background").stop().animate({ 
				opacity: 0
			  }, 700 );
			  $("div.background3").stop().animate({ 
				opacity: 0
			  }, 700 );
			  $("div.background4").stop().animate({ 
				opacity: 1
			  }, 700 );
			  $("div.background2").stop().animate({ 
				opacity: 0
			  }, 700 );
			  rotateImages4();
		}, 6000);
	};
	
	function rotateImages4() {
			setTimeout(function() {
			  $("#informationTitle").html(temp1);
			  $("div.background").stop().animate({ 
				opacity: 1
			  }, 700 );
			  $("div.background3").stop().animate({ 
				opacity: 0
			  }, 700 );
			  $("div.background4").stop().animate({ 
				opacity: 0
			  }, 700 );
			  $("div.background2").stop().animate({ 
				opacity: 0
			  }, 700 );
			  rotateImages1();
		}, 6000);
	};


	/*$("a.PatientsLink").hover(
      function () {
		  $("#informationTitle").html(temp2);
		  $("div.background").stop().animate({ 
			opacity: 0
		  }, 700 );
		  $("div.background3").stop().animate({ 
			opacity: 0
		  }, 700 );
		  $("div.background4").stop().animate({ 
			opacity: 0
		  }, 700 );
		  $("div.background2").stop().animate({ 
			opacity: 1
		  }, 700 );
      }, 
      function () {

      }
    );*/
	
	/*$("a.PayersLink").hover(
      function () {
		  $("#informationTitle").html(temp3);
		  $("div.background").stop().animate({ 
			opacity: 0
		  }, 700 );
		  $("div.background3").stop().animate({ 
			opacity: 1
		  }, 700 );
		  $("div.background4").stop().animate({ 
			opacity: 0
		  }, 700 );
		  $("div.background2").stop().animate({ 
			opacity: 0
		  }, 700 );
      }, 
      function () {

      }
    );*/
	
	/*$("a.AdminsLink").hover(
      function () {
		  $("#informationTitle").html(temp4);
		  $("div.background").stop().animate({ 
			opacity: 0
		  }, 700 );
		  $("div.background3").stop().animate({ 
			opacity: 0
		  }, 700 );
		  $("div.background4").stop().animate({ 
			opacity: 1
		  }, 700 );
		  $("div.background2").stop().animate({ 
			opacity: 0
		  }, 700 );
      }, 
      function () {

      }
    );*/
	
	//hide the element with id "feast"
	$("div.feast").hide();
	
	//slides the element with class "feast" when img with class "expandable" is clicked
	$("img.expandable").click(function()
	{
		if($('img.expandable').is('.collapsed')) {
			$('img.expandable').attr('src','/images/collapse.png');
			$('img.expandable').removeClass('collapsed');
			$('img.expandable').addClass('expanded');
		}
		else {
			$('img.expandable').attr('src','/images/expand.png');
			$('img.expandable').removeClass('expanded');
			$('img.expandable').addClass('collapsed');
		}
		$('div.feast').slideToggle(900);
	});
	
	$("ul.sf-menu").superfish(); 
	
	$('a[rel="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});	
	
	$('#searchArea span.printLink').click(function() {
		$("div.feast").show();
		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;
		
		//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 = 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=See this page on the Ameritox Site: ' + url);
		$('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();
	});
		
});