$(document).ready(function(){
	//DEFAULT
	$("#pointer0").fadeIn("slow");
	$("div#c_la").slideDown();
	$("div.subnav ul:first li:first").addClass("current")
	$("#pointer0").children("p:first").children().children("img").attr("src","../images/btn_c_la_on.gif");

	//VIEW SCHEDULE
	var $div = $('#viewSchedule');
	var $toggle = $('#toggle');
    var height = $div.height();
    //$div.hide().css({ height : 0 });

	$('#toggle').click(function () {
        if ($div.is(':visible')) {
            $div.animate({ height: 0 }, { duration: 500, complete: function () {
                $div.hide();
				$div.parent().removeClass("hideSchedule")
            } });
        } else {
            $div.show().animate({ height : height }, { duration: 500 });
			$div.parent().addClass("hideSchedule");
        }
        
        return false;
    });
	
	var $titleCable =  $("a[href='#cable']");
	var $titleSatel = $("a[href='#satellite']");
	var $titleTerre = $("a[href='#terrestrial']");			   
	var srcArr = ["../images/title_cable.gif","../images/title_satellite.gif","../images/title_terrestrial.gif"];
	var locArr = ["0","-480px","-960px"];
	
	function resetMarker () {
		$("div.subnav li").removeClass("current");
		$("div.pointer img").each(
			function () {
			var imgSrc = $(this).parent().attr("class");
			$(this).attr("src","../images/btn_"+imgSrc+".gif");
			}
		)
	}
	
	function displayMap (no) {
		$("#map").children('img').animate({marginLeft: locArr[no]}, 1000 );
		$("#mapTitle").attr("src", srcArr[no]);
		
		if ($("div#pointer"+no).is(':hidden')) {
			$("div.pointer").fadeOut("slow");
			$("div#pointer"+no).fadeIn("slow");
		}
	}

	function showChannelInfo (locLink,type) {
		$(locLink).click(function () { 
			var location = $(this).attr("class");
			
			//SHOW MAP
			if (type=="cable") {
				displayMap (0);
			}
			if (type=="satel") {
				displayMap (1);
			}
			if (type=="terre") {
				displayMap (2);
			}
			
			//SHOW CHANNEL INFO
			if ($("div#"+location).is(':hidden')) {
				$("div.channelInfoWrapper").slideUp();
				$("div#"+location).slideDown();
			}
			
			//SHOW POINTER
			/*
			$("div.subnav li").removeClass("current");
			$("div.pointer img").each(
				function () {
				var imgSrc = $(this).parent().attr("class");
				$(this).attr("src","../images/btn_"+imgSrc+".gif");
				}
			)
			*/
			resetMarker();
			$("div.subnav ."+location).parent("li").addClass("current");
			$("div.pointer ."+location).children("img").attr("src","../images/btn_"+location+"_on.gif")
		})
	}
	
	function resetChannelInfo (defaultLoc) {
		$("div.channelInfoWrapper").hide();
		$("div#"+defaultLoc).slideDown();
		$("ul.subnav li").removeClass("current");
	}

	
	//LINKS FOR EACH TITLE
	$titleCable.click(function() {
		displayMap (0);
		resetChannelInfo ("c_la");
		resetMarker();
		$("div.subnav ul.cable li:first").addClass("current")
		$("#pointer0").children("p:first").children().children("img").attr("src","../images/btn_c_la_on.gif");
	})
	$titleSatel.click(function() {
   		displayMap (1);
		resetChannelInfo ("s_nationwide");
		resetMarker();
	})
	$titleTerre.click(function() {
		displayMap (2);					   	
		resetChannelInfo ("t_la");
		resetMarker();
		$("div.subnav ul.terrestrial li:first").addClass("current")
		$("#pointer2").children("p:first").children().children("img").attr("src","../images/btn_t_la_on.gif");
	})
	
	showChannelInfo('#pointer0 a','cable');
	showChannelInfo('#pointer1 a','satel');
	showChannelInfo('#pointer2 a','terre');
	
	showChannelInfo('ul.cable a','cable');
	showChannelInfo('ul.satellite a','satel');
	showChannelInfo('ul.terrestrial a','terre');

});