﻿var isIE = (navigator.appName.indexOf("Internet Explorer")>=0);
var isIE7 = (navigator.appVersion.indexOf("MSIE 7.0")>=0);
var isFF = (navigator.appName.indexOf("Netscape")>=0);
var isSafari = (navigator.appVersion.indexOf("Safari")>=0);

function getObject(name) {
	return document.getElementById(name);
}

var summary = null;
var txt = null;
var maxHeight = null;
var intervalID = null;
var scrollID = null;
var IEOpf = null;
var FFOpf = null;
var myObj = null;

function toogleText(){
	summary = getObject("divSummary");
	txt = getObject("divText");
	if(txt.style.display == "none"){
		txt.style.overflow = "";
		txt.style.height = "";
		summary.style.display = "none"
		scrollID = setInterval('animScroll(1)',10);
		IEOpf = 10;
		FFOpf = 0.1;
		myObj = txt;
		txt.style.filter= "alpha(opacity ="+ IEOpf+")";
		txt.style.opacity = FFOpf;
		txt.style.display = "block";
		maxHeight = txt.scrollHeight;//-30;
		intervalID = setInterval('fadeIn()',150);
		txt.style.height = 50+"px";
		txt.style.overflow = "hidden";
		inflateTxt();
	} else {
		scrollID = setInterval('animScroll(0)',10);
		txt.style.display = "none";
		IEOpf = 10;
		FFOpf = 0.1;
		summary.style.filter= "alpha(opacity ="+ IEOpf+")";
		summary.style.opacity = FFOpf;
		myObj = summary;
		summary.style.display = "block";
		intervalID = setInterval('fadeIn()',150);
	}
}
function inflateTxt(){
	currHeight = txt.style.height;
	currHeight = currHeight.substring(0,currHeight.indexOf("px"));
	if(currHeight < maxHeight){
		currHeight =  parseInt(currHeight) + 50;
		txt.style.height = currHeight+"px";
		setTimeout('inflateTxt()',50);
	}
}
function fadeIn(){
	if(isIE){
		if(IEOpf < 100){
			myObj.style.filter= "alpha(opacity ="+ IEOpf+")";
			IEOpf = IEOpf +10;
		}else{
			clearInterval(intervalID);
		}
	}
	if(isFF){
	 if(FFOpf < 1.0){
			myObj.style.opacity = FFOpf;
			FFOpf = FFOpf + 0.1;
		}else{
			clearInterval(intervalID);
		}
	}
}
var currY = 300;
var startY = 0;
function animScroll(dir){
	if(dir == 0){
		if(!isIE){
			currY = window.pageYOffset;
		}
		currY = currY -5;
		if(currY > 0){
			window.scrollTo(0,currY);
		}else{
			currY = 300;
			clearInterval(scrollID);
		}
	}else{
		startY = startY +5;
		if(startY < 350){
			window.scrollTo(0,startY);
		}else{
			startY = 0;
			clearInterval(scrollID);
		}
	}
}

var imgWidth = 214;
var imgHeight = 10;
var maxWidth = 637;
var win = null;
var myImg = null;
var myTitle = null;
var IntervalId = 0;

// Images Prev and Next
var imagesArray = [];
var titlesArray = [];
var currIndex;
	
function togglePopup(winID,imgObj,imgUrl,titleObj,titleText){
	win = getObject(winID);
	myTitle = getObject(titleObj);
	myImg = getObject(imgObj);
	
	myImg.src = imgUrl;
	myTitle.innerHTML = titleText;

	myImg.style.width = imgWidth+"px";
	myImg.style.height = imgHeight+"px";
	
	win.style.width = imgWidth+"px";
	win.style.height = imgHeight+"px";

	var opacity = getObject("divOpacity");
	var v = viewPoint;
	v.calc();
	docheightcomplete = (v.standardbody.offsetHeight > v.standardbody.scrollHeight) ? v.standardbody.offsetHeight : v.standardbody.scrollHeight;
	opacity.style.width = v.docwidth + "px";
	opacity.style.height = this.docheightcomplete + "px";

	if(win.style.display != "block" ){
		opacity.style.display = "block";
		win.style.display = "block";
		win.style.left = v.scroll_left + (v.docwidth-win.offsetWidth) / 4 + "px";
		win.style.top = v.scroll_top + (v.docheight-win.offsetHeight) / 5 + "px";
		toggleSelects("none");
		
		// Images Prev and Next
		setImageArrIndex(imgUrl);
		
		inflate();
	} else {
		opacity.style.display = "none";
		win.style.display = "none";
		toggleSelects("inline");
	}
}

// Images Prev and Next
function setImageArrIndex(url){
	for(var i=0;imagesArray.length;i++){
		if(imagesArray[i] == url){
			currIndex=i;
			setPageingButtons();
			return;
		}
	}
}
function setPageingButtons(){
	var prev =  getObject('ctl00_img_PrevBtn');
	var next = getObject('ctl00_img_NextBtn');
	if(currIndex == 0){
		prev.style.visibility='hidden';
	}else{
		prev.style.visibility='visible';
	}
	if(currIndex == imagesArray.length-1){
		next.style.display = "none";
	}else{
		next.style.display = "block";
	}
}
function populateArray(){
	var myImages = getObject('ctl00_ParentContent_HidImgs');
	var myTitles = getObject('ctl00_ParentContent_HidTitles');
	imagesArray = myImages.value.split('^');
	titlesArray= myTitles.value.split('^');
}
function getPrevImage(){
	myImg.src = imagesArray[currIndex-1];
	currIndex--;
	setPageingButtons();
	//myTitle.innerHTML = titleText;
}
function getNextImage(){
	myImg.src = imagesArray[currIndex+1];
	currIndex++;
	setPageingButtons();
	//myTitle.innerHTML = titleText;
}
function inflate(){
	var t = 0.125;
	if(imgWidth < maxWidth){
		imgWidth += 50;
		imgHeight += 50;
		myImg.style.width = imgWidth+"px";
		myImg.style.height = imgHeight+"px";
		win.style.width = 60+imgWidth+"px";
		win.style.height = 45+imgHeight+"px";
		setTimeout('inflate()',10);
	}else{
		imgWidth = 214;
		imgHeight = 10;
		return;
	}
}

function toggleSelects(stat){
	if(isIE && !isIE7) {
		var selects = document.getElementsByTagName("SELECT");
		for(var i = 0; i < selects.length; i++){
			selects[i].style.display = stat;
		}
	}
}
var viewPoint={
	calc:function(){
		var ie = document.all && !window.opera
		var domclientWidth = document.documentElement && parseInt(document.documentElement.clientWidth) || 100000 //Preliminary doc width in non IE browsers
		this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
		this.scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
		this.scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset
		this.docwidth=(ie)? this.standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16)
		this.docheight=(ie)? this.standardbody.clientHeight: window.innerHeight
	}
}


function toggleLangs(state){
	var o = getObject("langList");
	if(o.style.display != "block"){
		o.style.display = "block";
	} else {
		o.style.display = "none";
	}
}

function relativeTop(o){
	var t = 0;
	var t2 = o;
	while(t2.offsetParent!= null && t2 != document.body){
		t += t2.offsetTop;
		t2 = t2.offsetParent;
	}
	if(t == 0){ t = o.offsetTop; }
	return t;
}

function relativeLeft(o){
	var l = (isIE ? 0 : (document.body.offsetWidth - 965)/2);
	var t2 = o;
	while(t2.offsetParent!= null && t2.offsetParent != document.body){
		l += t2.offsetLeft;
		t2 = t2.offsetParent;
	}
	if(l == 0){ l = o.offsetLeft; }
	return l;
}