function resize_skyscraper(){
	try{
		if((document.body.clientWidth - 780) > 0){
			document.getElementById('mood_skyscraper').style.width = document.body.clientWidth - 780;
		} else {
			document.getElementById('mood_skyscraper').style.width = 0;
		}
	} catch(e){
		// void
	}
}

onresize = resize_skyscraper;
onload = resize_skyscraper;


function openMediaplayer(section, id){
	checkWinSize();
	if(!center_x || !center_y){
		center_x = 400;
		center_y = 300;
	}
	mediaplayer = window.open("/mediaplayer/section="+section+"/id="+id+"/show.html", "mediaplayer", "resizable=no, location=no, scrollbars=no, status=no, statusbar=no, menubar=no, addressbar=no, width=400, height=478");
	mediaplayer.resizeTo(400,478);
	mediaplayer.moveTo( (center_x - Math.round((400/2)) ),(center_y - Math.round((478/2)) ) );
}

function openMediatype(section, type, id){
	checkWinSize();
	if(!center_x || !center_y){
		center_x = 400;
		center_y = 300;
	}
	mediaplayer = window.open("/mediaplayer/section="+section+"/type="+type+"/id="+id+"/show.html", "mediaplayer", "resizable=no, location=no, scrollbars=no, status=no, statusbar=no, menubar=no, addressbar=no, width=400, height=478");
	mediaplayer.resizeTo(400,478);
	mediaplayer.moveTo( (center_x - Math.round((400/2)) ),(center_y - Math.round((478/2)) ) );
}

function openMediafile(section, filename, title){
	checkWinSize();
	if(!center_x || !center_y){
		center_x = 400;
		center_y = 300;
	}
	mediaplayer = window.open("/mediaplayer/section="+section+"/id="+filename+"/title="+title+"/show.html", "mediaplayer", "resizable=no, location=no, scrollbars=no, status=no, statusbar=no, menubar=no, addressbar=no, width=400, height=478");
	mediaplayer.resizeTo(400,478);
	mediaplayer.moveTo( (center_x - Math.round((400/2)) ),(center_y - Math.round((478/2)) ) );
}

function largerText(){
	current_size = getTextSize();
	new_size = parseInt(current_size) + 10;
	setTextSize(new_size);
}

function smallerText(){
	current_size = getTextSize();
	new_size = parseInt(current_size) - 10;
	setTextSize(new_size);
}

function getTextSize(){
	if(!document.styleSheets){
		return;
	} else {
		var theRules = new Array();
		if(document.styleSheets[0].cssRules){
			theRules = document.styleSheets[0].cssRules;
		} else if(document.styleSheets[0].rules){
			theRules = document.styleSheets[0].rules;
		} else {
			return;
		}
		size = theRules[0].style.fontSize;
		return size.substr(0, size.length-1);
	}
}

function setTextSize(inSize){
	if(!document.styleSheets){
		return;
	} else {
		var theRules = new Array();
		if(document.styleSheets[0].cssRules){
			theRules = document.styleSheets[0].cssRules;
		} else if(document.styleSheets[0].rules){
			theRules = document.styleSheets[0].rules;
		} else {
			return;
		}
		theRules[0].style.fontSize = inSize+"%";
		createCookie("fontsize", inSize, 365);
	}
}

function createCookie(name,value,days) {
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		expires = "";
	}
  	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[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;
}

window.onload = function(e){
	var cookie = readCookie("fontsize");
	var size = cookie ? cookie : 70;
	setTextSize(size);
}