﻿var m=parseInt(Math.random()*5);
  m=(isNaN(m))?0:m;

function writeHomeImage(){
  document.write('<img src="/SiteCollectionImages/HomePageBanners/cow-primary-banner-'+(m+1)+'.jpg" alt="Chesapeake Weather" >');
}


/* ONLOAD */
$(document).ready(function(){
	$("#masterAuthentication .loginControl table td").eq(4).addClass("rememberMe");
	$("#masterAuthentication .loginControl table td").eq(5).addClass("goButton");
	if ($("#masterAuthentication .loginControl table tr").length > 1){
		$("#masterAuthentication .loginControl table td").eq(4).hide();
		$("#masterAuthentication .loginControl table tr").eq(1).addClass("authenticationError");
	}
	$("#masterAuthentication").fadeIn("slow");

	$("a[href$=pdf]").addClass("pdfFileLink").addClass("png").attr({ target: "_blank" });
	$("a[href$=PDF]").addClass("pdfFileLink").addClass("png").attr({ target: "_blank" });
	$("a[href$=png]").addClass("imageFileLink").addClass("png").attr({ target: "_blank" });
	$("a[href$=PNG]").addClass("imageFileLink").addClass("png").attr({ target: "_blank" });
	$("a[href$=jpg]").addClass("imageFileLink").addClass("png").attr({ target: "_blank" });
	$("a[href$=JPG]").addClass("imageFileLink").addClass("png").attr({ target: "_blank" });
	$("a[href$=gif]").addClass("imageFileLink").addClass("png").attr({ target: "_blank" });
	$("a[href$=GIF]").addClass("imageFileLink").addClass("png").attr({ target: "_blank" });
	
	$(".slides-nav").addClass("png");
	
	$('.two .feature table td[id^=MSOZoneCell_WebPartWPQ]').parent().parent().parent().addClass('webPartTable');
	$(".pageBanner div[id*=RichHtmlField]").css('display', 'block');

	var cookieName = 'Username';
	var checkboxId = '.rememberMe input';
	var usernameId = '#ctl00_AuthenticationArea_LoginView1_Login1_UserName';
	var passwordId = '#ctl00_AuthenticationArea_LoginView1_Login1_Password';
	var pastCookie = 'usrName';
	var cookieText = '';
	
	//if new cookie doesn't exist,
	if ($.cookie(cookieName) == null){ 
		//check for the old cookie
		if ($.cookie(pastCookie) != null){ 
			//set cookieText to the old cookie value
			cookieText = $.cookie(pastCookie);
		}
	}
	//if it does exist
	else{
		//set cookieText to the new cookie value
		cookieText = $.cookie(cookieName);
	}

	//if the cookie has no value,
	if (cookieText==''){
		//uncheck the Remember Me box
		$(checkboxId).attr('checked', false); 
	}
	//if it has a value, 
	else { 
		//check the Remember Me box 
		$(checkboxId).attr('checked', true);
		//and fill in the user name
		$(usernameId).attr('value', $.cookie(cookieName));
	}
	
	//on submit, create or destroy the cookie
	$( '.goButton input' ).click(function (i) {
		if ( $(checkboxId).is(':checked') ){
			//create the cookie
			$.cookie( cookieName, $( usernameId ).attr('value'), { expires: 4200 } );
		}
		else{
			//destroy the cookie
			$.cookie( cookieName, null, { expires: -1 } );
		}
	});

});
