//rollovers
function createRollovers() {
    var onText = "-on",
        offText = "-off";
 
    $('img.rollover' ).each( function() {

        var onImg = $(this).attr('src').replace(offText,onText),
            offImg = $(this).attr('src').replace(onText,offText);
        
        $(this).bind('mouseenter', function () {
            $(this).attr('src', onImg );
        });
        $(this).bind('mouseleave', function () {
            $(this).attr('src', offImg );
        });
    });
 
    return;
}

function createPropertyTabs() {
	$('.propDetails').hide();
		
	if( window.location.hash ) {
		$('.tabSelector').removeClass('detailTabOn');
		$('.tabSelector').addClass('detailTabOff');
		$(window.location.hash).show();
    	$(window.location.hash + 'Tab').addClass('detailTabOn');
    	$(window.location.hash + 'Tab').removeClass('detailTabOff');
	} else if ($('#overview')) {
    	$('#overview').show();
    	$('#overviewTab').addClass('detailTabOn');
    	$('#overviewTab').removeClass('detailTabOff');
    } 
    
    $('.tabSelector').each( function(el) {
    	$(this).bind( 'click', function() {
    		var did = null;
    		$('.propDetails').hide();
    		$('.tabSelector').removeClass('detailTabOn');
    		$('.tabSelector').addClass('detailTabOff');
    		$(this).removeClass('detailTabOff');
    		$(this).addClass('detailTabOn');
        	did = '#' + $(this).attr('id').replace('Tab','');
        	if ($(did)) {
        		$(did).show();
        	}
    	});
    });
}

$(document).ready(function () {
    createRollovers();
    createPropertyTabs();
});

//Clear fields
function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}
//toggle
	$(function() {
			   var selectedEffect = 'blind';
			   var options = {};

		//run the currently selected effect
		function runEffect(){
			//run the effect
			$("#effect").toggle(selectedEffect,options,500);
		};
		
		//set effect from select menu value
		$("#toggle").click(function() {
			runEffect();
			return false;
		});

	});
//Drop down menu navigation
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
};

// show/hide subnavs
	var timeout    = 500;
	var closetimer = 0;
	var navitem = 0;

	function nav_open(){
		nav_canceltimer();
		   nav_close();
		   show_sub();
		   navitem = $(this).find('ul').css('visibility', 'visible');

	}

	function nav_close(){
		if(navitem) navitem.css('visibility', 'hidden');

	}

	function nav_timer(){
		closetimer = window.setTimeout(hide_sub, timeout);
	}

	function nav_canceltimer(){
		if(closetimer){
			window.clearTimeout(closetimer);
		        closetimer = null;
	}}
	
	function hide_sub(){
	$("#subnavAbout,#subnavLive").fadeOut("slow");
	}
	
	function show_sub(){
	$("#subnavAbout,#subnavLive").fadeIn("slow");
	}


	$(document).ready(function(){
		$('#nav > li').bind('mouseover', nav_open)
		$('#nav > li').bind('mouseout',  nav_timer)
	});
