/* 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
*/

window.onload = function(){
	textChanger.init(); 	
}

var textChanger = {
	cpanel : 'textchanger',  //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,         //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="increase"><a href="#" title="Increase font size">A</a></li>'+
		'<li id="reset"><a href="#" title="Default font size">A</a></li>'+
		'<li id="decrease"><a href="#" title="Decrease 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 > 2.0) fSize = 2.0;
		} 
		if (val == -1) {
			fSize -= 0.11;
			if (fSize < 0.5) fSize = 0.5;
		}		
		if (val == 0) {
			fSize = 1;
		}
		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));
	}
}
$(document).ready(function(){
	clearInputs();
	rotatedBox();
	HackIssues();
});
/*---- clear inputs function ---*/
function clearInputs(){
	$('input#search-field:text, input:password, textarea').each(function(){
		if(!this.val) this.val = this.value;
		this.onfocus = function(){
			if(this.value == this.val) this.value = '';
		}
		this.onblur = function(){
			if(this.value == '') this.value = this.val;
		}
	});
}
/*--- rotated box function ---*/
function rotatedBox(){
	var stay_time = 5000;
	$('#header .bg-image').each(function(){
		var _list = $(this).children();
		var _a = _list.index(_list.filter('.active:eq(0)'));
		if(_a == -1) _a = 0;
		var _t;
		_list.removeClass('active').css('opacity', 0).eq(_a).addClass('active').css('opacity', 1);
		function changeEl(_ind){
			if(_ind != _a){
				if(_t) clearTimeout(_t);
				_list.eq(_a).removeClass('active').animate({opacity: 0}, {queue:false, duration:500});
				_list.eq(_ind).addClass('active').animate({opacity: 1}, {queue:false, duration:500});
				_a = _ind;
				_t = setTimeout(function(){
					if(_a < _list.length - 1) changeEl(_a + 1);
					else changeEl(0);
				}, stay_time);
			}
		}
		_t = setTimeout(function(){
			if(_a < _list.length - 1) changeEl(_a + 1);
			else changeEl(0);
		}, stay_time);
	});
}

function HackIssues()
{
    $('.pageTitle[id*=IssueTitle] ~ br').remove();
    $('.pageTitle[id*=IssueTitle]').remove(); 
}
