jQuery(document).ready(function(){
		
  /* ********************* cookies *********************** */		
  function getCookie(c_name)
  {
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
    {
      x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
      y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
      x=x.replace(/^\s+|\s+$/g,"");
      if (x==c_name)
      {
        	return unescape(y);
      }
    }
  }			
  
  /* ********************* header auth  *********************** */	 
  function setHeaderAuthStatus(){
	var firstName = getCookie("MYACCOUNT");
	if(typeof firstName != 'undefined'){
    		document.getElementById("utilNoAuth").style.display = 'none';
   		  document.getElementById("utilLogin").style.display = 'none';
    		document.getElementById("utilWelcome").innerHTML = '<span>Welcome ' + firstName + '</span>';     
    		document.getElementById("utilWelcome").style.display = 'block'; 
    		document.getElementById("utilLogout").style.display = 'block'; 
    		document.getElementById("utilContact").style.display = 'block'; 
    		 
		    document.getElementById("ma_EnrollinOnlineAccess").style.display = 'none';   
    		
    		var objLeftMaEnrollInOnlineAccess = document.getElementById("left_ma_EnrollinOnlineAccess");
    		   		
    		if(typeof objLeftMaEnrollInOnlineAccess != 'undefined' && objLeftMaEnrollInOnlineAccess != null){
		    		document.getElementById("left_ma_EnrollinOnlineAccess").style.display = 'none'; 
		    }		
		    
		    // Temporary fix for conditional url 
		    
		    // Outage links
		    	// Header
		    	document.getElementById("report").innerHTML = '<a href="https://myaccount.alliantenergy.com/ma-ui/outage.html">Report an Outage</a>';

		    	// Top Nav
		    	document.getElementById("ma_OutageStatusInformation").innerHTML = '<a href="https://myaccount.alliantenergy.com/ma-ui/outage.html">Outage Status &amp; Information</a>';
		    
		    	// Left Nav
		   		var objLeftMaPayMyBill = document.getElementById("left_ma_OutageStatusInformation");

    			if(typeof objLeftMaPayMyBill != 'undefined' && objLeftMaPayMyBill != null){
		    		 objLeftMaPayMyBill.innerHTML = '<span><a href="https://myaccount.alliantenergy.com/ma-ui/outage.html">Outage Status &amp; Information</a></span>';	
		    	}		
		    
		    // Pay bill links
		    	// Top Nav
		    	document.getElementById("ma_PayMyBill").innerHTML = '<a href="https://myaccount.alliantenergy.com/ma-ui/payment-flow.html">Pay My Bill</a>';
		    	 
		    	// Left Nav 
		    	var objLeftMaPayMyBill = document.getElementById("left_ma_PayMyBill");		    	
		    
    			if(typeof objLeftMaPayMyBill != 'undefined' && objLeftMaPayMyBill != null){
		    		 objLeftMaPayMyBill.innerHTML = '<span><a href="https://myaccount.alliantenergy.com/ma-ui/payment-flow.html">Pay My Bill</a></span>';	
		    	}				    		   	    
  	}
  	else{
    		document.getElementById("utilNoAuth").style.display = 'block';
    		document.getElementById("utilLogin").style.display = 'block';
    		document.getElementById("utilWelcome").innerHTML = '<span></span>';     
    		document.getElementById("utilWelcome").style.display = 'none'; 
    		document.getElementById("utilLogout").style.display = 'none'; 
    		document.getElementById("utilContact").style.display = 'block';  		 	
  	}
  }  	
  
  setHeaderAuthStatus();
		
	/* ********************* breadcrumb generation *********************** */
	if ((typeof breadcrumbText != 'undefined') && (breadcrumbText.length == breadcrumbUrl.length)){
		generateBreadcrumbs();
	};
	
	function generateBreadcrumbs(){
		var bcLinks = '<span><a href="' + AE_SERVER_NAME + '/aecom/ssNODELINK/ae_home">Home</a></span>';
		var bcLength = breadcrumbText.length-1;
		var bcPage = '<span class="current">'+breadcrumbText[bcLength]+'</span>';
		for (var i=0; i < bcLength; i++) {
			bcLinks += '<span><a href="'+breadcrumbUrl[i]+'">'+breadcrumbText[i]+'</a></span>';
		};
		bcLinks += bcPage;
		$('#breadcrumbs').prepend(bcLinks);
	};
	
	/* ***************** remove search + login boxes value ******/
	$('#search #query, #login .box, .searchKeysWrapper .searchKeys').each(function() {
		$(this)
		.data('default', $(this).val())
		//.addClass('inactive')
		.focus(function() {
			//$(this).removeClass('inactive');
			$(this).addClass('inactive');
			if ($(this).val() == $(this).data('default') || '') {
				$(this).val('');
			}
		})
		.blur(function() {
			var default_val = $(this).data('default');
			if ($(this).val() == '') {
				//$(this).addClass('inactive');
				$(this).removeClass('inactive');
				$(this).val($(this).data('default'));
			}
		});
	});
	
	/* **************** add tabindex to form elements ************** */
	$('#mainContent :input:visible')
	.each(function(i,e){ 
		$(e).attr('tabindex',i+1) 
	});

	/* **************** accordion collapsible ************** */
	if ($('.accordion').length > 0){
		$('.accordion > div.collapse').hide();
		$('.accordion > .showContainer h3').prepend('<span>&nbsp;</span>').addClass('open').attr('title', 'Click to expand/collapse');
		$('.accordion > .showContainer').click(function(){
			$(this).next().slideToggle("slow");
			$(this).toggleClass('close');
			$(this).toggleClass('open');	
		});
	};
		 
	/* **************** popups/dialogs *********************** */	

       for (var i=0; i < 50; i++) {
         $('#ex3a-'+i).jqm({
                     trigger: '.ex3aTrigger-'+i});
              $('#ex3a-600-'+i).jqm({
                     trigger: '.ex3aTrigger-600-'+i});
              $('#ex3a-900-'+i).jqm({
                     trigger: '.ex3aTrigger-900-'+i});
       };

      	$('.dragg').draggable();  /* make dialog draggable, assign handle to title */
		
  // Close Button Highlighting. IE doesn't support :hover. 
  $('input.jqmdX')
  .hover(
    function(){ $(this).addClass('jqmdXFocus'); },
    function(){ $(this).removeClass('jqmdXFocus'); })
  .focus(
    function(){ this.hideFocus=true; $(this).addClass(''); })
  .blur(
    function(){ $(this).removeClass('jqmdXFocus'); });


    
	   	 
	/* **************** print friendly and pdf buttons ****************** */
	$('#print').addClass('printStuff');
	$('#print').prepend('<div class="printer"></div><div class="pdf"></div>');
	$('#print .printer').click(function() {
		printerFriendly();
		return false;
	});
	$('#print .pdf').click(function() {
		savePdf();
		return false;
	});
	
	function printerFriendly(){
		var pop_url = ""; 
		var pop_name = "_blank"; 
		var pop_settings = "location=0,resizeable=1,scrollbars=1,toolbar=0,width=800, height=800, left=100, top=25"; 
		var pop_content = document.getElementById("wrapper").innerHTML;
		var pop_window = window.open(pop_url,pop_name,pop_settings);
		pop_window.document.open();
		pop_window.document.write('<html><head><title>Alliant Energy</title>'); 
		pop_window.document.write('</head><body><div id="noprint" style="width:25%; float:right; text-align:right;"><a href="#" onClick="window.print();window.close();" style="color:blue;"><strong>PRINT</strong></a></div>');
		pop_window.document.write('<link rel="stylesheet" type="text/css" href="/wcm/fragments/ae_css/print.css" media="all" />'); 
		pop_window.document.write(pop_content);          
		pop_window.document.write('</body></html>'); 
		pop_window.document.close();
		if (window.focus) {pop_window.focus()};
		return false;
	};

	function savePdf(){
		return false;
	};
	
	/* ********** datatable enhancements/generation *************** */
	$('#aeDataTable').dataTable({
		"sPaginationType": "full_numbers",
		"sDom": 'lfrt<"tableInfo"ip><"clear">'
	});	

  $.fn.clickID = function() { 
  	var clickID = $.getUrlVars()["clickID"];
  	if(clickID!=undefined){
    	if (clickID.length > 0){
    	  $('#' + clickID ).click();
  	  }
  	}
  }			
	
	$.extend({
    getUrlVars: function(){
      var vars = [], hash;
      var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
      for(var i = 0; i < hashes.length; i++)
      {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
      }
      return vars;
    },
    getUrlVar: function(name){
      return $.getUrlVars()[name];
    }  
  });
  	
});
