/* Text changer - light version.
Let your text's font size customizable.
by Marco Rosella - http://www.centralscrutinizer.it/en/design/js-php/text-changer
                v0.2 - May 18, 2006
*/

/* LAST MODIFIED - 16/03/2010 - ADDED INTCAMPAIGN COOKIE CODE */

/* get quote buttons */

$(document).ready(function() {
				if ($(document).getUrlParam("campaign") || $.cookie('ppp_ac')=='campaign'){
					var campaign=$(document).getUrlParam("campaign")?$(document).getUrlParam("campaign"):$.cookie('ppp_ac_val');	
					$('#prodURL').attr('href',$('#prodURL').attr('href')+'&campaign='+campaign);
				}
	});

$(document).ready(function() {
				if ($(document).getUrlParam("campaign") || $.cookie('ppp_ac')=='campaign'){
					var campaign=$(document).getUrlParam("campaign")?$(document).getUrlParam("campaign"):$.cookie('ppp_ac_val');	
					$('#prodURL2').attr('href',$('#prodURL2').attr('href')+'&campaign='+campaign);
				}
	});

$(document).ready(function() {
				if ($(document).getUrlParam("intcamp") || $.cookie('intcamp')=='intcamp'){
					var campaign=$(document).getUrlParam("intcamp")?$(document).getUrlParam("intcamp"):$.cookie('intcamp_val');	
					$('#prodURLint').attr('href',$('#prodURLint').attr('href')+'&intcamp='+campaign);
				}
	});



/* campaign cookie code */

			
		 
			/* intcamp */
		 $(document).ready(function(){
		 	var options = { path: '/', expires: 30 };
			// If Parameter intcamp is passed then set intcamp cookie
			if ($(document).getUrlParam("intcamp")){				
				$.cookie('intcamp','intcamp', options); //set intcamp cookie
				$.cookie('intcamp_val',$(document).getUrlParam("intcamp"), options); //set intcamp cookie variable value
				
			}
		 });
		 
		
		 
	 	/* ppp_ac */
		 $(document).ready(function(){
             var options = { path: '/', expires: 30 };
             //check if ppp ac cookie exists, if not check URL variables and create if found
             if ((!$.cookie('ppp_ac')) || ($.cookie('ppp_ac_val') != $(document).getUrlParam("campaign"))) {
                      if ($(document).getUrlParam("campaign")){
						$.cookie('ppp_ac', 'campaign', options); //set cookie variable
                        $.cookie('ppp_ac_val', $(document).getUrlParam("campaign"), options); //set cookie variable value
                      }
             }
             });
		 
		 
		


		 
window.onload = function(){
	textChanger.init(); 	
}

var textChanger = {
	cpanel : 'header-textsize-changer',  //set here the id of the element (div, p) within you want to insert the control panel
	element : 'pagewidth',   	 //set here the id of the element (div, p) within you want to change the text
	defaultFS : 1.3,         //set here the default font size in 'em'
	init: function() {
		var cpel = document.getElementById(textChanger.cpanel);
		var el = document.getElementById(textChanger.element);
		if (cpel == null || el == null) {
			//alert('The elements with the \"'+textChanger.cpanel+'\" and/or \"'+textChanger.element+'\" ID do not exist in HTML source.');
		} 
		else {
		var u = document.createElement('ul');
		cpel.appendChild(u);
		u.innerHTML = 
		'<li id="decrease"><a href="#" title="Decrease font s ize">A</a></li>'+
		'<li id="reset"><a href="#" title="Default font size">A</a></li>'+
		'<li id="increase"><a href="#" title="Increase font size">A</a></li>'
		var sz = textChanger.getCookie();
		el.style.fontSize = sz ? sz + 'em' : textChanger.defaultFS + 'em';
		var incr = document.getElementById('increase');
		incr.onclick = function(){textChanger.changeSize(1); return false;};
		var decr = document.getElementById('decrease');
		decr.onclick = function(){textChanger.changeSize(-1); return false;};
		var reset= document.getElementById('reset');
		reset.onclick = function(){textChanger.changeSize(0); return false;};
		}
	} ,

	changeSize: function(val) {
		var el = document.getElementById(textChanger.element);
		var size = el.style.fontSize.substring(0,3);
		var fSize = parseFloat(size,10);
		if (val == 1) {
			fSize += 0.11;
			if (fSize > 1.7) fSize = 1.7;
		} 
		if (val == -1) {
			fSize -= 0.11;
			if (fSize < 0.5) fSize = 0.5;
		}		
		if (val == 0) {
			fSize = textChanger.defaultFS;
		}
		el.style.fontSize = fSize + 'em';
		textChanger.updateCookie(fSize);
		} ,
		
	updateCookie: function(vl) {
		var today = new Date();
		var exp = new Date(today.getTime() + (365*24*60*60*1000)); //the cookie will expire in one year  
		document.cookie = 'textChangerL=size=' + vl + ';' +'expires=' + exp.toGMTString() + ';' +'path=/';
	} ,

	getCookie: function() { 
		var cname = 'textChangerL=size=';	
		var start = document.cookie.indexOf(cname);
		var len = start + cname.length;
		if ((!start) && (cname != document.cookie.substring(0,cname.length))) {return null;}
		if (start == -1) return null;
		var end = document.cookie.indexOf(";",len);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(len, end));
	}
}