/* ---------------------------- 
[Global Javascript]

Project: 	SF Communities
Version:	1.0
Last change:	02/16/11 [templates created, lg]
Assigned to:	Lonnie Griffin [lg]
Primary use:	Web

------------------------------- */

/* ---------------------------- */
/* Submenu
/* ---------------------------- */

$(document).ready(function(){
	
	$("#submenu>li>ul").hide();
	$("#submenu>li:has(ul)>a").addClass("plus");
	$("#submenu>li.active>ul:first").show();
	
	$("#submenu>li.active:has(ul)").removeClass("plus");
	$("#submenu>li.active:has(ul)").addClass("minus");
	
	$("#submenu>li:has(li.active)>a").removeClass("plus");
	$("#submenu>li:has(li.active)>a").addClass("minus");
	
	$("#submenu>li:has(li.active)>a").next("ul").show();
	
	$("#submenu>li:has(ul)>a").click(function(event) {
		if (this == event.target) {
			$(this).next("ul:first").slideToggle("fast");
			if($(this).hasClass("plus")) {
				$(this).removeClass("plus");
				$(this).addClass("minus");
			} else {
				$(this).removeClass("minus");
				$(this).addClass("plus");
			};
		};
		return false;
	})
});


/* ---------------------------- */
/* Sidebar Widgets
/* ---------------------------- */

$(document).ready(function(){
	/* Initialize Hot Homes Scrollpane */
	$('#scrollpane-hothomes').jScrollPane();
	/* Items for Interior Pages */
	if ($("body").attr("id") != "homepage") {
		/* Hot Homes Acordian */
		$("#scrollpane-hothomes").hide();
		$("#hothomes .btn-accordian").toggle(function() {
			$("#scrollpane-hothomes").slideDown();
			$(this).attr("src","images/btn-close.gif");
		}, function() {
			$("#scrollpane-hothomes").slideUp();
			$(this).attr("src","images/btn-open.gif");
		});
		/* Search Tools - Accordian */
		$("#searchtools .btn-accordian").toggle(function() {
			$("#scrollpane-searchtools").slideUp();
			$(this).attr("src","images/btn-open.gif");
		}, function() {
			$("#scrollpane-searchtools").slideDown();
			$(this).attr("src","images/btn-close.gif");
		});
	} else {
		/* Homepage only - Special Offers Cycle */
		$('#scrollpane-specialoffers').cycle({ 
			  prev:   '#btn-left', 
			  next:   '#btn-right', 
			  timeout: 4000,
			  speed:  500
		});	
	}
	
});


/* ---------------------------- */
/* Dropdowns
/* ---------------------------- */

$(document).ready(function() {
	function hideDropdowns() {
		$("#menu").find("ul").hide();
	}
	function ulHover(whichDiv) {
		$(whichDiv).hover(function() {
			// Do nothing 
		},function() { 
			hideDropdowns();
		});
	}
	$("#menu a").hover(function() {
		if ($(this).attr('rel')) {
			$("#menu ul").hide();
			$("#"+$(this).attr('rel')).fadeIn("fast");
		}
	}, function() {
		ulHover("#"+$(this).attr('rel'));
	});
	$("#menu").hover(function(){ 
		// Do nothing  
	}, function() {
		hideDropdowns();
	}); 
});

/* ---------------------------- */
/* Image Rollovers
/* ---------------------------- */

$(window).bind('load', function() {
    var preload = new Array();
    $(".img-over").each(function() {
        s = $(this).attr("src").replace(/\.(.+)$/i, "-on.$1");
        preload.push(s)
    });
    var img = document.createElement('img');
    $(img).bind('load', function() {
        if(preload[0]) {
            this.src = preload.shift();
        }
    }).trigger('load');
});

$(document).ready(function() {
	$(".img-over").each(function() {
        if ($(this).attr("src").match(/-on\.(.+)$/i)) {
            $(this).removeClass("hover");
        }
    });
    $(".img-over").hover(function() {
        s = $(this).attr("src").replace(/\.(.+)$/i, "-on.$1");
        $(this).attr("src", s);
    }, function() {
        s = $(this).attr("src").replace(/-on\.(.+)$/i, ".$1");
        $(this).attr("src", s);
	})
});


