/*------------------------------------------------------------------
	
	[JavaScript]

	Project:		www.westnet.com.au
	Version:		2.0
	Assigned to:	Garth Haseldine (GH)
	Changes:		05.01.09 [ GH: Created ]
					23.02.09 [ GH: Added functions to handle the Broadband page ]
					09.03.09 [ GH: Updated Top Menu so it works in all browsers ]
					11.03.09 [ GH: Added the Preload function for the left and right caps ]
	

-------------------------------------------------------------------*/


/*------------------------------------------------------------------

	[Table of Contents]
	
	1. Pre-Load Rollovers
	2. Main Local Navigation
	3. More Information Toggle
	3. Broadband Page Functions
	
-------------------------------------------------------------------*/

var vdefault = 'undefined';
var vtabnames = new Array();
var vLocalNavigationArea = "";

$(document).ready(function(){
						   
/*------------------------------------------------------------------
	[1]	Pre-Load Rollovers
-------------------------------------------------------------------*/

// Preload the Topmenu left and right caps for tier1
$.preload([ 'item-over-capRight', 'item-over-capLeft' ], {
    base:'/images/wnVseven/navigation/local-navigation-top/',
    ext:'.png'
});
						   
/*------------------------------------------------------------------
	[2]	Main Local Navigation
-------------------------------------------------------------------*/

	// The following function works out where the user is so it can set
	// the menu as default.
	
	// 	Find the first tier and put all the titles into an array
	$('.tierOne').find('a').each(function(){
		var vtitle = $(this).attr("title");
		vtabnames.push(vtitle);
	}); //close each(
	
	//console.log(vdefault);
	
	if (vdefault == 'undefined')  // We can manually set the location if we want by setting vdefault on the page
	{
		var vPath = location.pathname.split("/"); // Split the URL up into sections so we can find where they are	
		
		vpathLength = vPath.length - 1;
		vtablength = vtabnames.length - 1;
		
		for (j=0; j<vpathLength; j++) // Go through tab titles and the URL
		{
			for (i=0; i<vtablength; i++)
			{
				if (vPath[j] == vtabnames[i]) // If we find where they are then set the correct tab
				{
					vLocalNavigationArea = vtabnames[i];
					break;
				}
			}
		}

		
		if (vLocalNavigationArea == '' || vLocalNavigationArea == null)       //24/10/2006 CLi: home page won't have any path name, this is for homepage menu
		{
			vLocalNavigationArea = vtabnames[0];
		}
		
	}
	else {
		vLocalNavigationArea = vdefault;
	}

    //Hover Effects for the Main Local Navigation
	$("#localNavigation .tierOne td a").mouseover(function(){
	
		// For all the items remove any hover effects
		$("#localNavigation .tierOne td").each(function(){
			$(this).css({'background-image' : 'none' , 'color' : '#FFFFFF',  'padding-top' : '0px'});
			$("#localNavigation .tierOne td:has(img)").remove();
		}); // Close each
		
		$("#localNavigation .tierOne td a").each(function(){
			$(this).css({'color' : '#FFFFFF'});
		}); // Close each

		
		$("#localNavigation .tierTwo").each(function(){
			$(this).css({'display' : 'none'});
		}); // Close each
		
		// Select the table cell and apply the background image and set the colour of the link
		$(this).parent().css({'color' : '#127cd7', 'margin' : '0px 0px', 'background' : 'url(/images/wnVseven/navigation/local-navigation-top/item-over-back.png) top repeat-x',  'padding-top' : '5px'});
		$(this).css({'color' : '#127cd7', 'margin' : '0px 0px'});
		
		// Add the caps before and after the selected table cell
		$(this).parent().after("<td width='6' align='center'><img src='/images/wnVseven/navigation/local-navigation-top/item-over-capRight.png' width='6' height='32' border='0' align='right'></td>");
		$(this).parent().before("<td width='6' align='center'><img src='/images/wnVseven/navigation/local-navigation-top/item-over-capLeft.png' width='6' height='32' border='0' align='left'></td>");
		
		// Show the submenu
		$("#SM-" + $(this).attr("title")).css({'display' : 'block'});
		
	}); // Close Mouseover
	
	// Bind the mouseleave so it only triggers once when you leave the whole containing div
	$("#localNavigation").bind("mouseleave", function(e){

		// Hide all the submenus
		$("#localNavigation .tierTwo").each(function(){
			$(this).css({'display' : 'none'});
		}); // Close each
		
		// Trigger the event that will show the sections area
		$("#localNavigation .tierOne td a[title=" + vLocalNavigationArea + "]").trigger('mouseover');		
			
	}); // Close Mouseout
	
	// Once the page loads reset the menu
	$('#localNavigation').trigger('mouseleave');
	


/*------------------------------------------------------------------
	[3]	More Information Toggle
-------------------------------------------------------------------*/
	
	// Links that contain "Information"	
	
	$("a[title]").click(function () {
		var idString = $(this).attr("title");
    	$(".hideme[title='" + idString + "']").toggle();
    });
	
	
	
/*------------------------------------------------------------------
	[4]	Broadband Page
-------------------------------------------------------------------*/
	
	
	$("#bb2Planslnk").click(function () {
		$("#bb2Plans").show();
		$("#bb2Planslnk img").attr({src: "/images/wnVseven/btn-broadband2-02.png"});
    	$("#bb1Plans").hide();
		$("#bb1Planslnk img").attr({src: "/images/wnVseven/btn-broadband1-01.png"});
		$("#allPlans").hide();
		$("#allPlanslnk img").attr({src: "/images/wnVseven/btn-view-all-plans-01.png"});
    });
	
	$("#bb1Planslnk").click(function () {
		$("#bb2Planslnk img").attr({src: "/images/wnVseven/btn-broadband2-01.png"});
		$("#bb1Planslnk img").attr({src: "/images/wnVseven/btn-broadband1-02.png"});
		$("#allPlanslnk img").attr({src: "/images/wnVseven/btn-view-all-plans-01.png"});
		$("#bb2Plans").hide();
		$("#allPlans").hide();
    	$("#bb1Plans").show();
    });
	
	$("#allPlanslnk").click(function () {
		$("#bb2Planslnk img").attr({src: "/images/wnVseven/btn-broadband2-01.png"});
		$("#bb1Planslnk img").attr({src: "/images/wnVseven/btn-broadband1-01.png"});
		$("#allPlanslnk img").attr({src: "/images/wnVseven/btn-view-all-plans-02.png"});
		$("#bb2Plans").hide();
		$("#allPlans").show();
    	$("#bb1Plans").hide();
    });
	
	$("#showReach").click(function () {
		$("#proPlans").hide();
		$("#reachPlans").show();
    });
	
	$("#showPro").click(function () {
		$("#proPlans").show();
		$("#reachPlans").hide();
    });
	
	var bbAvail = $("#hfBroadbandAvail").val();
		
	switch (bbAvail)
	{
	case "Pro":
	  $("#bb2Planslnk").trigger('click');
	  $("#showPro").trigger('click');
	  $("#lnkbb2ProAvail").show();
	  $("#lnkbb2ReachAvail").show();
	  $("#lnkbb1Avail").show();
	  $("#bbResults").show();
	  break;
	case "Reach":
	  $("#bb2Planslnk").trigger('click');
	  $("#showReach").trigger('click');
	  $("#lnkbb2ReachAvail").show();
	  $("#lnkbb1Avail").show();
	  $("#bbResults").show();
	  break;
	case "Adsl1":
	  $("#bb1Planslnk").trigger('click');
	  $("#showPro").trigger('click');
	  $("#lnkbb1Avail").show();
	  $("#bbResults").show();
	  break;
	case "NoBroadband":
	  $("#bb1Planslnk").trigger('click');
	  $("#showPro").trigger('click');
	  $("#bbNoResults").show();
	  break;
	case "ProDirect":
	  $("#bb2Planslnk").trigger('click');
	  $("#showPro").trigger('click');
	  break;
	case "ReachDirect":
	  $("#bb2Planslnk").trigger('click');
	  $("#showReach").trigger('click');
	  break;
	case "Adsl1Direct":
	  $("#bb1Planslnk").trigger('click');
	  $("#showPro").trigger('click');
	  break;
	case "":
	  $("#bb2Planslnk").trigger('click');
	  $("#showPro").trigger('click');
	  break;
	default:
	  $("#bb2Planslnk").trigger('click');
	  $("#showPro").trigger('click');
	}
	
	

});