﻿	var debug = function(what){
			if(window.console && window.console.firebug){
				//console.log(what);
			}	
			else{
				//alert(what);
			}
		}		

      var rotateAds = function() {                    
            var AdAArray = new Array('RotateA', 'RotateA1', 'RotateA2', 'RotateA3', 'RotateA4');            
            var AdBArray = new Array('RotateB', 'RotateB1', 'RotateB2', 'RotateB3');
 
            var AdArrayArray = new Array(AdAArray, AdBArray);

            
            for (i=0; i<AdArrayArray.length;i++){
              var t = 1 + parseInt(Math.floor(Math.random()*(AdArrayArray[i].length - 1)));
              //console.log('t:' + t);
              var adToDisplay = 0;
              for (j=0; j<AdArrayArray[i].length;j++){
                toggleAd(AdArrayArray[i][j], (j == t));         
              }
            } 
        }   
        
    
        function toggleAd(ad, isVisible){
            if(ad != 'Placeholder')
            {
				ad = '#' + ad;
                elm = $(ad);
                if (isVisible) {
                  elm.css('display','inline');
                  elm.css('position','relative');
                } else {
                  elm.css('display','none');
                  elm.css('position','absolute');
                }
            }
        }

debug('loading...');



	var setEventListeners = function() {
		debug('set listeners');

		$('#navigation-residential-link-main strong img').click(function(){window.location='/default.aspx'});
		$('#navigation-business-link-main strong img').click(function(){window.location='/business.aspx'});
		
		$("#csOffLink").click(function(){toggleClass.toggle('1');});
		$("#pybOffLink").click(function(){toggleClass.toggle('0');});

	}
	

rotateAds();// display random ads	
setEventListeners();

	$(document).ready(function() {
	  debug('dom ready');
	  init();
	});


	var init = function() {
	  
	  displaySegment();
	   
	  preloadImages();// preload branding bg images
	  
	  toggleClass.init('loginTabs','pyb','cs','0');
	
	  urchinTracker();
	}
	

	

var displaySegment = function(){
	debug('displaySegment()');
	var segment = $.query.get('segment');
	debug('segment = ' + segment );
	if($.query.get('segment')){	
		switch (segment)	
		{      
			case 'business':
			    debug('- segment business');			
				window.location.replace('/business.aspx');
				break;
			case 'wholesale':
			    debug('- segment wholesale');
				window.location.replace('/wholesale/');
				break;
			default:
			  debug('- segment default');
				break;
		}
	} else {
		nextRotation('res_bb');//start rotation onload	
	}
	
	
}	
	
      //preload images
	var  preloadImages = function(){	
 		    //existing user white bg
		    var plutWhtBG= new Image(214,183); 
		        plutWhtBG.src="images/Default/plutexistingBg.gif"; 
			   			   				   
            //main BG  
            var resBG_bb= new Image(956, 274);
                resBG_bb.src ="/images/Default/mainBg_res_bb.jpg";

            var resBG_ph= new Image(956, 274);
                resBG_ph.src ="/images/Default/mainBg_res_ph.jpg";
               
            var resBG_tv= new Image(956, 274);
                resBG_tv.src ="/images/Default/mainBg_res_tv.jpg";               
               
            var resBG_tv= new Image(956, 274);
                resBG_tv.src ="/images/Default/mainBg_res_bundle.jpg";    
		}    
    

    
		function menuchange(tab, rotation) {
			
	      debug('menuchange (' + tab + ',' + rotation +')');
		    
			//Branding top Navigation LI
			var TopNavLIResidential = $("#Residential");
			  var BrandingTopNavigation = [TopNavLIResidential];
							
			//Branding top Navigation Links
			var TopNavLinkResidential = $("#navigation-residential-link-main");
    		  var BrandingTopNavigationLink = [TopNavLinkResidential];
			 
			//Branding background image
			var mainBG = $("#HTMLBody");
            
		    //Branding Left Navigation
			var LeftNavResidential = $("#typeNavRes");
			var LeftNavResidentialOptions = $("#typeNavResOptions");
			  var BrandingLeftNavigation = [LeftNavResidential];			
									
			// Branding content
			var residentialbundles = $("#residential-bundles");  			
  			var residentialinternet = $("#residential-internet");
  			var residentialphone = $("#residential-phone");
  			var residentialtv = $("#residential-tv");
			  var BrandingContent = [residentialbundles, residentialinternet, residentialphone, residentialtv];
			
			// Branding Residential Rotating Links
			var bundleslink = $("#navigation-residential-bundles");		
			var internetlink = $("#navigation-residential-internet");
            var phonelink = $("#navigation-residential-phone");
            var tvlink = $("#navigation-residential-tv");			
			  var BrandingResidentialLinks = [bundleslink, internetlink, phonelink, tvlink];
			
			// Branding PLUT overlay
			var plut = $("#feature-highlight");	
					
			//Green Tabbed Content
			var tabbedBox = $("loginTabs");

			
			debug('end of vars');

			switch (tab) 
			{      
				case 'res_bb':
					updateClassName(BrandingTopNavigation, TopNavLIResidential, 'inactive', 'active');
					updateClassName(BrandingTopNavigationLink, TopNavLinkResidential, 'inactive', 'active');				
					mainBG.removeClass('residentialPhoneBG').removeClass('residentialTVBG').addClass('residentialBBBG').removeClass('residentialBundlesBG');
		            updateCSS(BrandingContent, residentialinternet, 'display', 'none', 'block');
					updateClassName(BrandingResidentialLinks, internetlink, 'inactive', 'active');
					
					if(rotation){
				       nextRotation('res_ph');
				     } else {
				       stopRotation();
				     }
				    
					break;
					
				case 'res_ph':
					updateClassName(BrandingTopNavigation, TopNavLIResidential, 'inactive', 'active');
					updateClassName(BrandingTopNavigationLink, TopNavLinkResidential, 'inactive', 'active');
				    mainBG.addClass('residentialPhoneBG').removeClass('residentialTVBG').removeClass('residentialBBBG').removeClass('residentialBundlesBG');
					updateCSS(BrandingContent, residentialphone, 'display', 'none', 'block');
					updateClassName(BrandingResidentialLinks, phonelink, 'inactive', 'active');
					
					if(rotation){
				       nextRotation('res_tv');
				     } else {
				       stopRotation();
				     }
				    
					break;
					
				case 'res_tv':
	                updateClassName(BrandingTopNavigation, TopNavLIResidential, 'inactive', 'active');
					updateClassName(BrandingTopNavigationLink, TopNavLinkResidential, 'inactive', 'active');
			        mainBG.removeClass('residentialPhoneBG').addClass('residentialTVBG').removeClass('residentialBBBG').removeClass('residentialBundlesBG');
					updateCSS(BrandingContent, residentialtv, 'display', 'none', 'block');
					updateClassName(BrandingResidentialLinks, tvlink, 'inactive', 'active');
					
					if(rotation){
				       nextRotation('res_bundles');
				     } else {
				       stopRotation();
				     }
				    
					break;	
																
				case 'res_bundles':
					updateClassName(BrandingTopNavigation, TopNavLIResidential, 'inactive', 'active');
					updateClassName(BrandingTopNavigationLink, TopNavLinkResidential, 'inactive', 'active');
			        mainBG.removeClass('residentialPhoneBG').removeClass('residentialTVBG').removeClass('residentialBBBG').addClass('residentialBundlesBG');
					updateCSS(BrandingContent, residentialbundles, 'display', 'none', 'block');
					updateClassName(BrandingResidentialLinks, bundleslink, 'inactive', 'active');
													 
				    if(rotation){
				       nextRotation('res_bb')
				     } else {
				       stopRotation();
				     }
				     				     
					break;	
				
				default:
				
					debug('case: default : ' + tab);
					
					break;
			}
			
			//alert('defaultJS: ' + $("#marketSegment").value);
		}
		
		var t;
		
		function nextRotation(tab) {
		    //console.log('nextRotation');
		    stopRotation();  
		    var nextCall = "menuchange('" + tab + "',true)";
		    t=setTimeout(nextCall,7000);  
		}
		
		function stopRotation(){
		    if(t) {
		        clearTimeout(t);
		    }   
		}
		
		
		function updateCSS (elementArray, selectedElement, elementCSS, defaultValue, selectedValue)
		{
			debug('updateCSS :' + selectedElement.id );
			
			for(i=0;i < elementArray.length; i++)
			{
			  elementArray[i].css(elementCSS, defaultValue);
			}
			if (selectedElement !== null)
			{
			  selectedElement.css(elementCSS, selectedValue);
			}
			return true;	
		}
		
		function overwriteClassName(elementArray, selectedElement, defaultValue, selectedValue)
		{
			for(i=0;i < elementArray.length; i++)
			{
			  elementArray[i].className = defaultValue;
			}
			if (selectedElement !== null)
			{
			  selectedElement.className = selectedValue;
			}
			return true;	
		}
		
	
		function updateClassName(elementArray, selectedElement, defaultValue, selectedValue)
		{
			for(i=0;i < elementArray.length; i++)
			{
			  elementArray[i].removeClass(selectedValue);
			}
			if (selectedElement !== null)
			{
			  selectedElement.addClass(selectedValue);
			}
			return true;	
		}	
		
	

            var intRand = rndNumber = Math.floor(Math.random()*2);
            var strFlash = "";
        	
            switch (intRand){
                case 0:
	                strImg = '<a href="/residential/equipment.aspx?tab=2&anc=lmc"><img src="/images/cta/homeCarsCallout.gif" alt="Talk in Style" width="231" height="90" border="0"/></a>';
	                break;
                case 1:
	                strImg = '<a href="/bigairjump/"><img src="/images/cta/homeJumpTheTruck.gif" alt="Jump The Truck" width="231" height="90" border="0"/></a>';
	                break;
                default:
	                strImg = '<a href="/residential/equipment.aspx?tab=2"><img src="/images/cta/homeCarsCallout.gif" alt="Talk in Style" width="231" height="90" border="0"/></a>';
	                break;
            }
        	
            function chkFormBG() {

            }

	        function ValidateBillPayLogin() {
		        if (($("#UserIDTextBox").value == "") || ($("#PasswordTextBox").value == "")) {
			        alert("You must enter a User ID and Password to continue.");
			        return false;
		        } else {
			        return true;
		        }
	        }
