//////////////////////////////////////////////
/////   Opens Jquery
//////////////////////////////////////////////
$(document).ready(function(){
	
//////////////////////////////////////////////
/////   The sliding search container at the top of the page
//////////////////////////////////////////////
	$('div#slideContainer').addClass('contactBG');
		
	$('a#slideContact').toggle(function(){
		$this = $(this)
		$('div#slideContainer').slideDown(800, function() { $this.html('Close')})
		return false;
		//$this.html('Close');
	},function(){
		$this = $(this);
		$('div#slideContainer').slideUp(800, function() { $this.html('Get in Contact')});
		return false;
		//$(this).html('Search For a Home');
	});
	
//////////////////////////////////////////////
/////   adds a class of odd (.odd) to every other list item in the News Block (.newsBlock)
//////////////////////////////////////////////
	$('.rightSideBarBlock li').filter(':odd').addClass('odd');
	
//////////////////////////////////////////////
/////   adds a class of odd (.odd) to every other table row in the mortgage table (#mortgageTable)
/////   adds the class tableHover (.tableHover) to a table row with the class of sub (.sub) when hovered
//////////////////////////////////////////////
	$('#businessTable tr').filter(':odd').addClass('odd');
	
	$('tr.sub').hover(function(){
		$(this).addClass('tableHover');
	},function(){
		$(this).removeClass('tableHover');
	});
	
//////////////////////////////////////////////
/////   adds support for IE6 so that the background image in the Main Nav shows up when hovered
//////////////////////////////////////////////
	$('#mainNav ul').click(function(){
		var href = $(this).find('a').eq(0).attr('href');
		window.location = href;
	});
	
	$('#mainNav ul').hover(function(){
		$(this).addClass('navBackground');
	},function(){
		$(this).removeClass('navBackground');
	});
//////////////////////////////////////////////
/////   Closes Jquery
//////////////////////////////////////////////

//Style-Switcher code
	//$('#styleChanger li a.selected').css({backgroundPosition: 'left -16px'});
	$('#styleChanger ul li a').click(function(){
			$('#styleChanger li a.selected').css({backgroundPosition: 'left 0px'});
            switchStylestyle(this.getAttribute("rel"));
			createCookie('id', this.id, 365);
			$(this).css({backgroundPosition: 'left -16px'});
			$('#styleChanger ul li a').removeClass('selected');
			$(this).addClass('selected');
            return false;
    });
    var style = readCookie('style');
	var id= readCookie('id');
    if (style) switchStylestyle(style);
	if(id){
		$('#styleChanger li a.selected').removeClass('selected');
		$('#'+id).addClass('selected');
	}
	$('#styleChanger li a.selected').css({backgroundPosition: 'left -16px'});
//Style-Switcher Ends	

//Initialize newsSlider
$('#newsSlider').newsSlider();

});
function switchStylestyle(styleName)
{
        $('link[@rel*=style][@title]').each(function(i)
        {
                this.disabled = true;
                if (this.getAttribute('title') == styleName) this.disabled = false;
        });
        createCookie('style', styleName, 365);
}
// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions
