// GLOBAL VARIABLES
var swap_text_boxes = [];
var total = 0;
var count = 0;
function initialize_rotator()
{
	jQuery("#news-rotator li").hide();
	jQuery("#news-rotator li a").attr('target', '_blank');
      jQuery("#news-rotator li:first-child").fadeIn('slow');
      var total = jQuery("#news-rotator li").size();
      var count = 1;
	jQuery('#news-rotator li a').each(
		function()
		{
			if(jQuery(this).text().length > 60)
			{
				jQuery(this).text(jQuery(this).text().substring(0,59)+'...');
			}
		}
	);

	jQuery("#news-up").click(function(){
		if(count < total)
		{
			jQuery("#news-rotator li:nth-child("+count+")").fadeOut('slow',
				function()
				{
					count++;
					jQuery("#news-rotator li:nth-child("+count+")").fadeIn('slow');
				}
			);
		}
		else
		{
			jQuery("#news-rotator li:nth-child("+count+")").fadeOut('slow',
				function()
				{
					count = 1;
					jQuery("#news-rotator li:nth-child("+count+")").fadeIn('slow');
				}
			);
		}
		return false;
	});
	
	jQuery("#news-down").click(function(){
		jQuery("#news-rotator li:nth-child("+count+")").fadeOut('slow');
		if(count > 1)
		{
			jQuery("#news-rotator li:nth-child("+count+")").fadeOut('slow',
				function()
				{
					count--;
					jQuery("#news-rotator li:nth-child("+count+")").fadeIn('slow');
				}
			);
		}
		else
		{
			jQuery("#news-rotator li:nth-child("+count+")").fadeOut('slow',
				function()
				{
					count = total;
					jQuery("#news-rotator li:nth-child("+count+")").fadeIn('slow');
				}
			);
		}
		return false;
		
	});
}

function initialize_search()
{
	  //Store the default value for each box
	  jQuery('#s').each(function() {
	    swap_text_boxes[jQuery(this).attr('id')] = jQuery(this).attr('value');
	  });
	
	  //Add focus and blur events to set or clear the value
	  jQuery('#s').bind('focus', function() {
	    if(jQuery(this).val() == swap_text_boxes[jQuery(this).attr('id')]) {
	      jQuery(this).val('');
	    }
	  });
	
	  jQuery('#s').bind('blur', function() {
	    if(jQuery(this).val() == '') {
	      jQuery(this).val(swap_text_boxes[jQuery(this).attr('id')]);
	    }
	  	});
}

function initialize_tooltips()
{		
		xOffset = 10;
		yOffset = 20;
						
		jQuery("a.tooltip").hover(function(e){	
			
			if(this.title.length > 0){
				
			this.t = this.title;
			this.title = "";									  
			jQuery("body").append("<p id='tooltip'>"+ this.t +"</p>");
			jQuery("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");	
				}	
	    },
		function(){
			this.title = this.t;		
			jQuery("#tooltip").remove();
	    });	
		jQuery("a.tooltip").mousemove(function(e){
			jQuery("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px");
		});			
}

jQuery(document).ready(function(){
	if(jQuery('#news-rotator'))
	{
		initialize_rotator();
	}
			
	initialize_search();
	initialize_tooltips();
});
	
				//swfobject.registerObject("featured-content-flash", "7.0.0");
function set_homepage()  
{  
	document.body.style.behavior='url(#default#homepage)';  
	document.body.setHomePage('http://www.whatsnewlaporte.com');
	history.go(0);
}