﻿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 getE() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;

    elements.push(element);
  }

  return elements;
}

function format( text ) {
    //check if there are two arguments in the arguments list
    if ( arguments.length <= 1 ) {
        //if there are not 2 or more arguments there’s nothing to replace
        //just return the original text
        return text;
    }
    //decrement to move to the second argument in the array
    var tokenCount = arguments.length - 2;
    for( var token = 0; token <= tokenCount; token++ ) {
        //iterate through the tokens and replace their placeholders from the original text in order
        text = text.replace( new RegExp( "\\{" + token + "\\}", "gi" ),
                                                arguments[ token + 1 ] );
    }
    return text;
};

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 = getE("divSummary");
	txt = getE("divText");
	if(txt.style.display == "none"){
		txt.style.overflow = "";
		txt.style.height = "";
		summary.style.display = "none"
		scrollID = setInterval('animScroll(1)',80);
		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()',50);
		txt.style.height = 50+"px";
		txt.style.overflow = "hidden";
		inflateTxt();
	} else {
		scrollID = setInterval('animScroll(0)',80);
		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()',50);
	}
}
function inflateTxt(){
	currHeight = txt.style.height;
	currHeight = currHeight.substring(0,currHeight.indexOf("px"));
	if(currHeight < maxHeight){
		currHeight =  parseInt(currHeight) + 20;
		txt.style.height = currHeight+"px";
		setTimeout('inflateTxt()',20);
	} else {
		currHeight = maxHeight;
	}
}
function fadeIn(){
	if(isIE){
		if(IEOpf <= 100){
			myObj.style.filter= "alpha(opacity="+ IEOpf+")";
			IEOpf = IEOpf +10;
		}else{
			clearInterval(intervalID);
			//myObj.style.filter = "alpha(opacity=100)";
			//$("lnkMore2").style.filter = "alpha(opacity=100)";
			getE("lnkMore2").style.fontWeight = 'bold';
			//$("lnkMore2").style.fontSize = '12pt';
			//$("lnkMore2").style.fontSize = '10pt';
		}
	}
	if(isFF){
	 if(FFOpf < 1.0){
			myObj.style.opacity = FFOpf;
			FFOpf = FFOpf + 0.1;
		}else{
			clearInterval(intervalID);
		}
	}
}

var startY = 0;

function animScroll(dir){
	if(dir == 0){
		window.scrollTo(0,0);
		clearInterval(scrollID);
	}else{
		startY = startY +20;
		if(startY < 120){
			window.scrollTo(0,startY);
		}else{
			window.scrollTo(0,120);
			startY = 0;
			clearInterval(scrollID);
		}
	}
}

function toggleLangs(state){
	var o = getE("langList");
	if(o.style.display != "block"){
		o.style.display = "block";
	} else {
		o.style.display = "none";
	}
}

function toggleProjects(pageID, langID){
	var o = getE('frmProjs');
	if(o.style.display != 'block'){
		o.src = '_projPopup.aspx?id='+pageID+'&lang='+langID;
	}
	var gallery = getE('preview');
	if(gallery != null){
		closePreview();
	}
	o.style.display = (o.style.display != 'block' ? 'block' : 'none');
}
function resizeForm(height){
	var frm = getE('frmProjs');
	frm.style.height = height+"px";
}

