// JavaScript Document
$(document).ready(function () {
	
	$("#listingNav").tabs({ fx: { opacity: 'toggle',speed: 'fast' } });
	$("#ListingMainTab").tabs({ fx: { opacity: 'toggle',speed: 'fast' } });
	
    //$('#accord1').accordion({ autoheight: false });
	$('#accord1').accordion({header:'cite'});
    $("#topnavigation").replaceWith($("#topnavplaceholder").html());
    $("#topnavplaceholder").remove();

	var linkContainers = $('div.topNav > div');
	var intLinkCont = $('div.topNav > div > div');
	linkContainers.hide();
	
	if($.browser.msie){
	  $('.topNav span img').width("327");	
	}
	
	$('div.topNav ul.linkNavigation li').click(function () {
		//which link is clicked
		var currentlinkbox = $(this).attr("class");
		var filterclass = "#" + currentlinkbox;
		
		//if they click on the selected tab, do nothing
		if(currentlinkbox.indexOf("selected") > 0 ){
		 return false;	
		}
		
		//ignore clicks on the phone number
		if( currentlinkbox == "topnavphone"){
			return false;
		}
			
		//reset the background
		$('div.topNav ul.linkNavigation li:not(".topnavphone",".linkBox1")').css("background", "url('/includes/images/shell/topnav/tab-looking-off.gif') no-repeat 100% 0%");
		$('.linkBox1').css("background", "url('/includes/images/shell/topnav/tab-looking-linkBox1-off.gif') no-repeat 100% 0%");
				
		//reset the z-indexes
		$('.linkBox1').css("z-index","56");
		$('.linkBox2').css("z-index","55");
		$('.linkBox3').css("z-index","54");
		$('.linkBox4').css("z-index","53");
		$('#maplinkbox').css("z-index","52");
		$('.linkBox5').css("z-index","51");
		
		//which link is clicked
		var currentlinkbox = $(this).attr("class");
		var filterclass = "#" + currentlinkbox;
		
		//button to use for closing content
		var closebtn = "<div id='closeBtn'><img onClick='javascript:$.closetopnav();' src='/includes/images/shell/topnav/button-close.gif'></div>";
		
		//change the content in the masterlinkbox
		$("#masterlinkbox").html($(filterclass).html()+closebtn).show("slow");

    if(currentlinkbox == "linkBox4"){
		  var opt = {showOn: "both", 
							 buttonImageOnly: true, 
							buttonText: "Choose date", 
							buttonImage: imgroot + "/includes/images/wct/calendar.gif", 
							dateFormat: "mm/dd/yy",
							defaultDate: null};
		  $("#events_search_form .eventcaldates .eventcaldatepicker").datepicker(opt);
	  }
		//alter the look of the tabs at the top
		$('div.topNav ul.linkNavigation li').removeClass('selected');
		$('#header').css("margin-top","-24px");
		
		$(this).addClass('selected').css("background-image", "url('/includes/images/shell/topnav/tab-looking-" + currentlinkbox + "-on.gif')").css("line-height", "25px").css("z-index","58");
		return false;
	});

	jQuery.closetopnav = function(){
		
		// used on the close button to close the masterlinkbox
		$("#masterlinkbox").hide("slow");
		
		//reset the z-indexes
		$('.linkBox1').css("z-index","56");
		$('.linkBox2').css("z-index","55");
		$('.linkBox3').css("z-index","54");
		$('.linkBox4').css("z-index","53");
		$('.linkBox5').css("z-index","52");								

		//alter the styles
		$('div.topNav ul.linkNavigation li:not(".topnavphone",".linkBox1")').removeClass('selected').css("background", "url('/includes/images/shell/topnav/tab-looking-off.gif') no-repeat 100% 0%");
        $('.linkBox1').removeClass('selected').css("background", "url('/includes/images/shell/topnav/tab-looking-linkBox1-off.gif') no-repeat 100% 0%");
		$('#header').css("margin-top","0px");
	};
	
	// WCT Nav
	
	var wctlinkContainers = $('div.wctNav > div');
	wctlinkContainers.hide().filter(':first').fadeIn('slow');
	
	$('div.wctNav ul.wctNavigation a').click(function () {
		wctlinkContainers.hide();
		wctlinkContainers.filter(this.hash).fadeIn('slow');
		$('div.wctNav ul.wctNavigation a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
	
});
