//Changes the picture when over_button is activated

var clickedsize ="";

function over_button(size) {


	try {
 
	if (size != null && size == "normalsize" && clickedsize != "normal" ) {
		var imageid = document.getElementById(size);
    	imageid.src = "/images/mouse_over_normal.gif";
  	}
  	if (size != null && size == "largesize" && clickedsize != "large") {
		var imageid = document.getElementById(size);
    	imageid.src = "/images/mouse_over_large.gif";
  	}
  	if (size != null && size == "xlargesize" && clickedsize != "xlarge") {
		var imageid = document.getElementById(size);
    	imageid.src = "/images/mouse_over_xlarge.gif";
  	}

  	} catch(err) {
		//we have this since popups don't have access to images. Otherwise this 
		// script will error
	}

	
	
} 

//Changes the picture when out_button is activated
function out_button(size) {


	try {
  	if (size != null && size == "normalsize" && clickedsize != "normal") {
   		var imageid = document.getElementById(size);
    		imageid.src = "/images/mouse_out_normal.gif";
  	}
  	if (size != null && size == "largesize" && clickedsize != "large") {
   		var imageid = document.getElementById(size);
    		imageid.src = "/images/mouse_out_large.gif";
  	}
  	if (size != null && size == "xlargesize" && clickedsize != "xlarge") {
   		var imageid = document.getElementById(size);
    		imageid.src = "/images/mouse_out_xlarge.gif";
  	}

	} catch(err) {
		//we have this since popups don't have access to images. Otherwise this 
		// script will error
	}
} 

//fetches the cookies value
function getCookie() {

	var nameEQ = "SIZEPARAMETER" + "=";
	var cookies = document.cookie.split(';');
	for(var i=0;i < cookies.length;i++) {
		var c = cookies[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
	
}


function getTextsize() {
	if (getCookie != null || getCookie != '' || getCookie != 'null') {
		setTextsize(getCookie(), true);
	}
	
}
//sets the text size based on cookie value
function setTextsize(size, useCookie) {
    	if (size == '' || size == 'null' || size == null) {
        	return;
    	}

	if (useCookie == true) {
           
            var expirationDate = new Date();
            // expiration date is set to 90 days
            expirationDate.setTime(expirationDate.getTime() + 1000*60*60*24*90);
		
	    setCookie('SIZEPARAMETER', size, expirationDate);
	    clickedsize = size;
	   
	    var doc = document.getElementById("sheet");
	    var cssName = "";
	   
	    if (doc != '' || doc != 'null') {
	    	cssName = doc.href;
	  
	    	var suffix = ".css";
	    	var stop = cssName.length - 4;
	    	var start = 0;
	    	cssName = cssName.substring(start,stop)
	    	
	    	var cssNameFirstPartIndexEnd = cssName.indexOf("/css/") + 5;
	    	
	    	var cssNameFirstPart = cssName.substring(start, cssNameFirstPartIndexEnd );
	    	var cssNameSecondPart = cssName.substring(cssName.indexOf("/css/") + 5);
	    	var sizepart = cssNameSecondPart.split("_");
	    	var lastPart = sizepart.length;
	    
	    
	    	var sizesuffix = sizepart[lastPart-1];
	    	cssName = "";
	    	for(i = 0; i < sizepart.length -1; i++) {
				cssName += sizepart[i] + "_"; 
	    	}
	    	
	    	cssName = cssNameFirstPart + cssName + size + suffix;
	    }
	    
	    if (cssName != "" ) {
	    	doc.href=cssName;
	    	// set the chosen image
	    	try {
		var imageNormal = document.getElementById("normalsize");
	    	var imageLarge = document.getElementById("largesize");
	    	var imageXlarge = document.getElementById("xlargesize");
	    
	    	imageNormal.src = "/images/mouse_out_normal.gif";
	    	imageLarge.src = "/images/mouse_out_large.gif";
	    	imageXlarge.src = "/images/mouse_out_xlarge.gif";
	    	
	    		if (size != null && size == "normal") {
				var imageid = document.getElementById(size + "size");
    			imageid.src = "/images/mouse_over_normal.gif";
  			}
  			if (size != null && size == "large") {
				var imageid = document.getElementById(size + "size");
    			imageid.src = "/images/mouse_over_large.gif";
  			}
  			if (size != null && size == "xlarge") {
				var imageid = document.getElementById(size + "size");
    			imageid.src = "/images/mouse_over_xlarge.gif";
  			}
  			
	   	} catch(err) {
		//we have this since popups don't have access to images. Otherwise this 
		// script will give errors
		}
	    }
	}
}

function initTextsize(){
    setFontsize(getCookie('SIZEPARAMETER'), false);
}
//the cookie will live 90 days
function setCookie(name, value, expires) { 

	document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString()); 
} 