//JavaScript Document - /default/javafunctions.js

//Functions to detect internet browser name, version and operating system
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity="+ opacity +")"; 
} 

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 100;
    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
} 

function fadeIn() {
	if (BrowserDetect.browser=="Explorer") {
		setTimeout("shiftOpacity('k', 80)", 1000);
	}
  //Opera
	if (BrowserDetect.browser=="Opera") {
		setTimeout("shiftOpacity('k', 500)", 500);
	}
  //Mozilla
	if (BrowserDetect.browser=="Firefox") {
		setTimeout("shiftOpacity('k', 500)", 500);
	}
  //Safari
	if (BrowserDetect.browser=="Safari") {
		setTimeout("shiftOpacity('k', 500, 200)", 500);
	}
}

function fitToWindow() {
/** Fit the website in browser window */
	var iHeight, iHeightLeft, iHeightB, iWidth, iMinus, iMinusLeftMenu;
  	//IExplorer
	if (BrowserDetect.browser=="Explorer") {
		iMinus=338;
		iMinusLeftMenu=iMinus-17;
		if(document.documentElement.clientHeight>=607) {
			iHeight=document.documentElement.clientHeight-iMinus;
			iHeightLeft=document.documentElement.clientHeight-iMinusLeftMenu;
		}
		else {
			iHeight=270;
			iHeightLeft=270+iMinus-iMinusLeftMenu;
		}
	}
	//Opera
	if (BrowserDetect.browser=="Opera") {
		iMinus=339;
		iMinusLeftMenu=iMinus-17;
		if(window.innerHeight>=607) {
			iHeight=document.documentElement.clientHeight-iMinus;
			iHeightLeft=document.documentElement.clientHeight-iMinusLeftMenu;
		}
		else {
			iHeight=270;
			iHeightLeft=270+iMinus-iMinusLeftMenu;
		}
	}
  	//Mozilla
	if (BrowserDetect.browser=="Firefox") {
		iMinus=338;
		iMinusLeftMenu=iMinus-17;
		if(window.innerHeight>=612) {
			iHeight=document.documentElement.clientHeight-iMinus;
			iHeightLeft=document.documentElement.clientHeight-iMinusLeftMenu;
		}
		else {
			iHeight=270;
				iHeightLeft=270+iMinus-iMinusLeftMenu;
		}
	}
  	//Safari
	if (BrowserDetect.browser=="Safari") {
		iMinus=338;
		iMinusLeftMenu=iMinus-17;
		if(window.innerHeight>=608) {
			iHeight=document.documentElement.clientHeight-iMinus;
			iHeightLeft=document.documentElement.clientHeight-iMinusLeftMenu;
		}
		else {
			iHeight=270;
			iHeightLeft=270+iMinus-iMinusLeftMenu;
		}
	}
	overFlowTop=50;
	overFlowBottom=69;
	if(iHeight>='800') {
		iHeight=800;
		iHeightLeft=800+17;
		overFlowTop=(document.documentElement.clientHeight-1020)/2;
		overFlowBottom=overFlowTop;
	}
	document.getElementById('t').style.height=overFlowTop+"px";
	document.getElementById('b').style.height=overFlowBottom+"px";
	document.getElementById('l').style.height=iHeightLeft+"px";
	document.getElementById('h').style.height=iHeight+"px";
	document.getElementById('h').style.overflow="auto";
	document.getElementById('h').style.padding="20px";
}
/** At website init: Show first page in right content pane */

