$(document).ready(function(){
	var cc = 0;					   
						   
    $("a").each(function() {
            if (this.href == window.location.href.split("#")[0]) {
                $(this).addClass("selected");
				cc = cc + 1;
            }
	});
	
	if(cc == 0){
				$("a#homeLink").addClass("selected");
			}
	
	//Widgets that are required to be hidden are done with autoHide wrapper.
	$("span.autoHide").find(".toggleTarget").hide();
	$("span.autoHide").find(".toggleTrigger").addClass("inactive");
	
	$('li:first-child').find('a').css({borderWidth:'0 0 1px 0'});
	$('li:last-child').find('a').css({borderWidth:'1px 0 0 0'});	
	$('li:only-child').find('a').css({borderWidth:'0'});
	
	// A Drop menu hover behaviour	
	$("ul.dropMenu li div.list").hide();	
	$("ul.dropMenu li").live("mouseover", function() {
	$(this).find("div.list").show();
	$(this).find("a.icon").addClass("dropMenuIconHover");
	});	
	$("ul.dropMenu li").live("mouseout", function() {
	$(this).find("div.list").hide();
	$(this).find("a.icon").removeClass("dropMenuIconHover"); 
	});
	
	//Bind response to toggleTrigger click event.
	$(".toggleTrigger").bind("click",function(){
	var c = $(this).attr("class");
	if(c == "toggleTrigger inactive"){
	$(this).removeClass("inactive");
	$(this).parent().find(".toggleTarget").slideDown();
	}else{
	$(this).addClass("inactive");
	$(this).parent().find(".toggleTarget").slideUp();
	}
	});
	 
});

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

function initHomeAppList(){
	// Hide all items by default
	$('#homeApps > div:not(:first)').hide();
	
	//Bind each tab
	$('#homeApps > img.icon').bind("click", function(){
	var i = $('#homeApps > img.icon').index(this);
	var objDivToOpen = $('#homeApps > div').eq(i);		
	var objOpened = $(this).parent().find(" > div:visible");
	if(objDivToOpen[0] == objOpened[0] ){
	//Do nothing
	}else{	
	//adjust tabs state
	$(this).addClass("selected");
	var j = $('#homeApps > div').index($('#homeApps > div:visible'));
	if( j >= 0){
	$( '#homeApps > img.icon').eq(j).removeClass("selected");
	}
	//Adjust content state
	objDivToOpen.show();
	objOpened.hide();
	
	}		
	});	
}


//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

function doAccordian(obj,closeAll,selfLocking,animate){
	if(closeAll){
	$(obj + "> dd").hide();	
	}else{
	$(obj + "> dd:not(:first)").hide();
	$(obj + "> dd:first").show();
	$(obj + "> dt:first a").addClass("selected");
	}
	//$(obj + "> dt a").hover(function() {
//			$(this).click();						 
//									 });
	
    $(obj + "> dt a").click(function() {
        var d0 = $(this).parent().next();
        var d1 = $(this).parent().parent().find("> dd:visible");
        if (d0[0] == d1[0]) {
			
			
			if(selfLocking){
			
			if(animate){
            $(this).parent().next().slideUp("slow");
			}else{
			$(this).parent().next().hide();
			}
			
			$(this).removeClass("selected")
			
			}
        } else {
           var obj =  $(this).parent().parent().find("> dd:visible");
		   
		   
		   obj.prev().find("a").removeClass("selected");
		   $(this).addClass("selected");
		   
		   if(animate){
            obj.slideUp("fast");
			$(this).parent().next().slideDown("slow");
		   }else{
			obj.hide();
			$(this).parent().next().show();  
		   }
			
        }
		
        return false;
    });
}
