var currentFontSize = 4;
function revertStyles(fontsize){
	currentFontSize = fontsize;
	changeFontSize(0);
}
function switchTool(name, value) {
	createCookie(name, value, 365);
	//window.location.reload();
	window.location.reload();
	return;
}
switchFontSize=function(ckname,val){
	var bd = $E('BODY');
	switch (val) {
		case 'inc':
			if (CurrentFontSize+1 < 7) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize++;
				bd.addClass('fs'+CurrentFontSize);
			}
		break;
		case 'dec':
			if (CurrentFontSize-1 > 0) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize--;
				bd.addClass('fs'+CurrentFontSize);
			}
		break;
		default:
			bd.removeClass('fs'+CurrentFontSize);
			CurrentFontSize = val;
			bd.addClass('fs'+CurrentFontSize);
	}
	Cookie.set(ckname, CurrentFontSize,{duration:365});
	equalHeightInit();
}
function changeFontSize(sizeDifference){
	//get css font size
	var rule = getRuleByName("body.fs" + (currentFontSize + sizeDifference));
	if (rule){
		document.body.style.fontSize = rule.style.fontSize;
		currentFontSize = currentFontSize + sizeDifference;
		createCookie("FontSize", currentFontSize, 365);
		equalHeightInit();
	}
	return;
};
function getRuleByName(ruleName){
	for (i=0; i<document.styleSheets.length; i++){
		var style = document.styleSheets[i];
		var rules = style.cssRules?style.cssRules:style.rules;
		if (rules){
			for (j = 0; j<rules.length; j++){
				if (rules[j].selectorText.trim().toUpperCase() == ruleName.trim().toUpperCase()){
					return rules[j];
				}
			}
		}
	}
	return null;
}
function setActiveStyleSheet(title) {
	createCookie("ColorCSS", title, 365);
	window.location.reload();
	return;
}
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 setScreenType(screentype){
	createCookie("ScreenType", screentype, 365);
	window.location.reload();
	return;
}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };
function changeToolHilite(oldtool, newtool) {
	if (oldtool != newtool) {
		if (oldtool) {
			oldtool.src = oldtool.src.replace(/-hilite/,'');
		}
		newtool.src = newtool.src.replace(/.gif$/,'-hilite.gif');
	}
}
//addEvent - attach a function to an event
function scAddEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
function getElem (id) {
	var obj = document.getElementById (id);
	if (!obj) return null;
	var divs = obj.getElementsByTagName ('div');
	if (divs && divs.length >= 1) return divs[divs.length - 1];
	return null;
}
function getFirstDiv (id) {
	var obj = document.getElementById (id);
	if (!obj) return null;
	var divs = obj.getElementsByTagName ('div');
	if (divs && divs.length >= 1) return divs[0];
	return obj;
}
function instr(str, item){
	var arr = str.split(" ");
	for (var i = 0; i < arr.length; i++){
		if (arr[i] == item) return true;
	}
	return false;
}
function equalHeightInit (){
	//Content and wrap col
	var sc_content = document.getElementById ('sc-container');
	var sc_colwrap = document.getElementById ('sc-colwrap');
	if (sc_content && sc_colwrap) {
		if (sc_content.scrollHeight > sc_colwrap.scrollHeight) 
		{
			var sc_inners = getElementsByClass ("innerpad", sc_colwrap, "DIV");	
			var va_height = sc_content.scrollHeight + 42;
			if (sc_inners && sc_inners.length)
			{
				sc_inners[0].style.height = va_height + 'px';
			}
		}else{
			document.getElementById ('sc-content').style.height = sc_content.scrollHeight + 'px';
		}
	}
	//Bottom spotlight 1
	var sc_botsl = document.getElementById ('sc-botsl1');
	if (sc_botsl)
	{
		var botsl = getElementsByClass ("sc-box.*", sc_botsl, "DIV");	
		if (botsl && botsl.length)
		{
			var maxh = 0
			for (var i=0; i<botsl.length ; ++i)
			{
				maxh = (botsl[i].scrollHeight > maxh)? botsl[i].scrollHeight:maxh;
			}
			for (var i=0; i<botsl.length ; ++i)
			{
				if (botsl[i].scrollHeight < maxh)
				{
					var sc_inners = getElementsByClass ("moduletable.*", botsl[i], "DIV");	
					if (sc_inners && sc_inners.length)
					{
						sc_inners[0].style.height = maxh - 30 + 'px';
					}
				}				
			}
		}
	}
	//Bottom spotlight 2
	var sc_botsl = document.getElementById ('sc-botsl2');
	if (sc_botsl)
	{
		var botsl = getElementsByClass ("sc-box.*", sc_botsl, "DIV");	
		if (botsl && botsl.length)
		{
			var maxh = 0
			for (var i=0; i<botsl.length ; ++i)
			{
				maxh = (botsl[i].scrollHeight > maxh)? botsl[i].scrollHeight:maxh;
			}
			for (var i=0; i<botsl.length ; ++i)
			{
				if (botsl[i].scrollHeight < maxh)
				{
					var sc_inners = getElementsByClass ("moduletable.*", botsl[i], "DIV");	
					if (sc_inners && sc_inners.length)
					{
						sc_inners[0].style.height = maxh - 30 + 'px';
					}
				}				
			}
		}
	}
}
scAddEvent (window, 'load', equalHeightInit);
function preloadImages () {
	var imgs = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var imgsrc = arguments[i];
		imgs[i] = new Image();
		imgs[i].src = imgsrc;
	}
}
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	var j = 0;
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (var i = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	//alert(searchClass + j);
	return classElements;
}
function fixIE() {
	var objs = getElementsByClass ("createdate", null, "TD");
	if (objs) {
		for (var i=0; i<objs.length; i++){
			objs[i].innerHTML = "<span>" + objs[i].innerHTML + "</span>";
		}
	}
	var obj = $E('h1.logo a');
	obj.onmouseover = function () {
		this.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=templates/sc_genista/images/logo2.png, sizingMethod='crop')");
	}
	obj.onmouseout = function () {
		this.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=templates/sc_genista/images/logo1.png, sizingMethod='crop')");
	}
/*
	//var objs = getElementsByClass('.*-transbg');
	var objs = $ES('#sc-cssmenu li ul');
	if (!objs) return;
	for(var i=0; i<objs.length;i++){
		makeTransBg(objs[i]);
	}
	var objs = getElementsByClass('.*-transbg');
	if (!objs) return;
	for(var i=0; i<objs.length;i++){
		makeTransBg(objs[i]);
	}
*/
}
if(isIE6()) scAddEvent (window, 'load', fixIE);
function makeTransBg(el){
	var obj = $(el);
	if(!obj) return;
	if (obj.tagName == 'IMG') {
		//This is an image
		var bgimg = obj.src;
		obj.setStyle('height',obj.offsetHeight);
		obj.setStyle('width',obj.offsetWidth);
		obj.src = 'images/blank.png';
		obj.setStyle ('visibility', 'visible');
		obj.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+bgimg+", sizingMethod='scale')");
	}else{
		//Background
		var bgimg = obj.getStyle('backgroundImage');
		var pattern = new RegExp('url\s*[\(]+(.*)[\)]+');
		if ((m = pattern.exec(bgimg))) bgimg = m[1];
		obj.setStyle('background', 'none');
		//if(!obj.getStyle('position'))
		if(obj.getStyle('position')!='absolute' && obj.getStyle('position')!='relative') {
			obj.setStyle('position', 'relative');
		}
		//Get all child
		var childnodes = obj.childNodes;
		for(var j=0;j<childnodes.length;j++){
			if((child = $(childnodes[j]))) {
				if(child.getStyle('position')!='absolute' && child.getStyle('position')!='relative') {
					child.setStyle('position', 'relative');
				}
				child.setStyle('z-index',2);
			}
		}
		//Create background layer:
		var bgdiv = new Element('DIV');
		bgdiv.setStyle('position', 'absolute');
		bgdiv.setStyle('top', 0);
		bgdiv.setStyle('left', 0);
		bgdiv.setStyle('width', obj.offsetWidth - 4);
		bgdiv.setStyle('height', obj.offsetHeight - 4);
		bgdiv.setStyle('z-index', '1');
		bgdiv.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+bgimg+", sizingMethod='scale')");
		bgdiv.inject(obj);
	}
}
function isIE6() {
	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE")
		version=parseFloat(temp[1])
	}
	return (version && (version < 7));
}
function hackReadon () {
	var readons = getElementsByClass ("readon", null, "A");	
	if (!readons || !readons.length) return;
	for (var i=0; i<readons.length; i++)
	{
		var readon = readons[i];
		//Get readon parent (TR)
		var p = readon;
		while ((p = p.parentNode) && p.tagName != 'TR'){}
		if (!p) continue;
		var pc = p;
		while ((pc = pc.previousSibling) && pc.tagName != 'TR') {}
		var tc = pc.firstChild;
		while (tc && tc.tagName!='TD') tc=tc.nextSibling;
		tc.appendChild (readon);
		p.parentNode.removeChild(p);
		readon.style.display = 'block';
	}
}
scAddEvent (window, 'load', hackReadon);
//Menu image hover effect
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}
function menuImageHover () {
	var mainnav = document.getElementById('sc-mainnav');
	if (!mainnav) return;
	var imgs = mainnav.getElementsByTagName ('IMG');
	if (!imgs || !imgs.length) return;
	for (var i=0; i<imgs.length; i++)
	{
		if (!imgs[i].parentNode.className.test(/active/))
		{
			setOpacity(imgs[i], 50);
			imgs[i].display = 'block';
			imgs[i].parentNode.img = imgs[i];
			imgs[i].parentNode.onmouseover = function () {
				if(typeof(setOpacity)=='function') setOpacity(this.img, 100);
			}
			imgs[i].parentNode.onmouseout = function () {
				if(typeof(setOpacity)=='function') setOpacity(this.img, 50);
			}
		}
	}
}
scAddEvent (window, 'load', menuImageHover);
function calc_menu () {
	var mainmenu = $('sc_mainmenu');
	var width = 0;
	var list_li = $$('.toplv');
	if (list_li) {
		for (var j=0;j<list_li.length;j++) {
			width += list_li[j].offsetWidth;
		}
	}
	mainmenu.setStyle('width',width);
}
function add_image_to_h3() {
	var listh3 = $$('#sc_left .module_menu h3');
	var listh31 = $$('#sc_left .module h3');
	var listh32 = $$('#sc_right .module h3');
	var listh33 = $$('#sc_right .module_menu h3');
	var listh34 = $$('#sc_left .module_text h3');
	var listh35 = $$('#sc_right .module_text h3');
	var temp = '';
	if (listh3) {
		for (var j=0;j<listh3.length;j++) {
			temp = listh3[j].innerHTML;
			listh3[j].innerHTML = '<img src="templates/sc_sccorporate/images/box_left.png" border="0" class="imgbox_left" />' + temp + '<img src="templates/sc_sccorporate/images/box_right.png" border="0" class="imgbox_right" />';
		}
	}
	if (listh31) {
		for (var j=0;j<listh31.length;j++) {
			temp = listh31[j].innerHTML;
			listh31[j].innerHTML = '<img src="templates/sc_sccorporate/images/box_left.png" border="0" class="imgbox_left" />' + temp + '<img src="templates/sc_sccorporate/images/box_right.png" border="0" class="imgbox_right" />';
		}
	}
	if (listh32) {
		for (var j=0;j<listh32.length;j++) {
			temp = listh32[j].innerHTML;
			listh32[j].innerHTML = '<img src="templates/sc_sccorporate/images/box_left.png" border="0" class="imgbox_left" />' + temp + '<img src="templates/sc_sccorporate/images/box_right.png" border="0" class="imgbox_right" />';
		}
	}
	if (listh33) {
		for (var j=0;j<listh33.length;j++) {
			temp = listh33[j].innerHTML;
			listh33[j].innerHTML = '<img src="templates/sc_sccorporate/images/box_left.png" border="0" class="imgbox_left" />' + temp + '<img src="templates/sc_sccorporate/images/box_right.png" border="0" class="imgbox_right" />';
		}
	}
	if (listh34) {
		for (var j=0;j<listh34.length;j++) {
			temp = listh34[j].innerHTML;
			listh34[j].innerHTML = '<img src="templates/sc_sccorporate/images/box_left.png" border="0" class="imgbox_left" />' + temp + '<img src="templates/sc_sccorporate/images/box_right.png" border="0" class="imgbox_right" />';
		}
	}
	if (listh35) {
		for (var j=0;j<listh35.length;j++) {
			temp = listh35[j].innerHTML;
			listh35[j].innerHTML = '<img src="templates/sc_sccorporate/images/box_left.png" border="0" class="imgbox_left" />' + temp + '<img src="templates/sc_sccorporate/images/box_right.png" border="0" class="imgbox_right" />';
		}
	}
}
scAddEvent (window, 'load', add_image_to_h3);
