function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
  try {
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
                + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
    }
  } catch (err) { alert(err.message); }
}

function processRequest(page) {
	var xmlObj = false;
	var elem_id = 'mainContent';
	if(window.XMLHttpRequest) xmlObj = new XMLHttpRequest();
	else if(window.ActiveXObject) xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
	if (xmlObj) {
		var myurl = 'pages/' + page + '.php';
		try {
			pageTracker._trackPageview(myurl);
		} catch (err) { trace('Page not registered: ' + myurl) }
		xmlObj.onreadystatechange = function() {
			// 0=Uninitialised 1=Loading 2=Loaded 3=Interactive 4=Completed
			if (xmlObj.readyState == 4) {
				var result = xmlObj.responseText;
				elem = document.getElementById(elem_id);
				elem.innerHTML = result;
				try { elem.focus(); } catch(err) {}
			}
		}
		xmlObj.open("GET", myurl, true);
		xmlObj.send (null);
	} else {
		alert ('xmlObj is null!');
	}
}function processRequestPOST(url, parameters) {	var xmlObj = false;	if (window.XMLHttpRequest) {
		xmlObj = new XMLHttpRequest();
		if (xmlObj.overrideMimeType) xmlObj.overrideMimeType('text/html');
	} else if (window.ActiveXObject) {
		try {xmlObj = new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e) {
			try {xmlObj = new ActiveXObject("Microsoft.XMLHTTP");}
			catch(e) {}
		}
	}
	if (!xmlObj) return false;
	try {
		pageTracker._trackPageview(url);
	} catch (err) { trace('Page not registered: ' + url) }
	xmlObj.onreadystatechange = function() {
		// 0=Uninitialised 1=Loading 2=Loaded 3=Interactive 4=Completed
		if (xmlObj.readyState == 4) {
			var result = xmlObj.responseText;
			trace(result);
		}
	}
	xmlObj.open('POST', url, true);
	xmlObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlObj.setRequestHeader("Content-length", parameters.length);
	xmlObj.setRequestHeader("Connection", "close");
	xmlObj.send(parameters);
	return true;
}


function _e(id) {
	return document.getElementById(id);
}

function trace (obj) {
	try { console.log(obj); }
	catch(err) {
		try { document.getElementById('console').innerHTML = obj; }
		catch(e) { }
	}
}

function hint(elem, text, direction) {
	switch(direction) {
	case 'in':
		elem.style.color="#000";
		if (elem.value != text) return;
		elem.value = '';
		break;
	case 'out':
		if (elem.value.length != 0 && elem.value != text) return;
		if (elem.value.length == 0) elem.value = text;
		elem.style.color="#AAA";
		break;
	}
}

function sendMessage(elem, page, fieldsArr) {
	elem.disabled = true;
	var invalidFields = new Array();
	var parameters = "";
	for (key in fieldsArr) {
		var val = _e(key).value;
		if (val.length == 0 || (fieldsArr[key].length > 0 
				&& val == fieldsArr[key])) {
			invalidFields[invalidFields.length] = key;
			_e(key).style.border="thin solid red";
		} else {
			_e(key).style.border="";
			parameters += '&'+key+'='+val;
		}
	}
	if (invalidFields.length > 0) {
		elem.disabled = false;
		showMessage('You have some invalid fields!<br/>Please correct your form');
		return;
	}
	if (parameters.length == 0) {
		elem.disabled = false;
		showMessage('We&apos;re sorry, there data to be sent!');
		return;
	}
	parameters = parameters.substr(1);
	showMessage('Thank you for your message.<br/>Please be patient while we submit your data', 3000);
	processRequestPOST(page, parameters);
}

function showMessage(text, timeout) {
	try {
                var vscroll = 0;
                if (self.pageYOffset) vscroll = self.pageYOffset;
                else if (document.documentElement && document.documentElement.scrollTop) vscroll = document.documentElement.scrollTop;
                else if (document.body) vscroll = document.body.clientHeight;
                trace(document.body.scrollTop);
                trace(vscroll);
		_e('message_text').innerHTML = text;
                if (document.body.scrollTop) vscroll = document.offsetTop;
                _e('messageContainer').style.top = (vscroll + (vscroll > 340 ? 150 : 340))+'px';
		_e('messageContainer').style.display = '';
		if (typeof timeout == 'undefined') var timeout = 2000;
		setTimeout(hideMessage, timeout);
	} catch(err) { trace(err.message) }
}

function hideMessage() {
	try {
		_e('message_text').innerHTML = '';
		_e('messageContainer').style.display = 'none';
	} catch(err) { trace(err.message) }
}

function start360(number) {
  try {
    var code = '<applet code="IpixViewer.class" name="IpixViewer" width="515" height="256" archive="http://www.panovision.biz/stuff/host/aiesec/360img/IpixViewer.jar">'
      +'<param name="url" value="http://www.panovision.biz/stuff/host/aiesec/360img/[IMAGE_NUMBER].ipx" />'
      +'<param name="splash" value="http://www.panovision.biz/stuff/host/aiesec/360img/logo.jpg" />'
      +'<param name="splashbg" value="FFFFFF" />'
      +'<param name="initfov" value="120" />'
      +'<param name="spinspeed" value="5" />'
      +'<param name="spinstyle" value="flat" />'
      +'<param name="helpurl" value="http://www.panovision.biz/faq.php" />'
      +'<param name="helpframe" value="_blank" />'
      +'</applet>';
    loadSiteText(number);
    document.getElementById('panovision').innerHTML = code.replace('[IMAGE_NUMBER]',number);
  } catch (err) {
    trace(err);
  }
}

function loadSiteText(number) {
	try {
		var texts = {
			1:'<strong>The Metropolitan Cathedral</strong><br/><br/>The largest Orthodox cathedral in Romania with an impressive architecture has a tremendous history being build, destroyed, left in ruins and rebuild again. This explains the balance of neoclassic, baroque and Italian late neo-renaissance.',
			2:'',
			3:'It is a neo-gothic Palace of Culture, one of Iasi&apos;s most recognizable and charming buildings. Grand but not grandiose, the Palace of Culture is indeed a prime element of Iasi&apos;s skyline, and its image as a city of culture.',
			4:'The budget of the university is almost half the budget of the whole city. Apart from the beautiful neoclassical building we will deepen our understanding of the central role this university plays in the city&apos;s life. The final point of this tour will be a return to art, <span id="loc_2" style="display: none;">a walk through the outstanding Hall of the Lost Footsteps, a collection of paintings, acoustics and fine atmosphere.</span><br/><a class="but_stire" href="#loc_2_top" onclick="_e(\'loc_2\').style.display=(_e(\'loc_2\').style.display==\'\'?\'none\' : \'\'); this.innerHTML=(this.innerHTML==\'[hide details]\'?\'[read more]\':\'[hide details]\');">[read more]</a>',
			5:'',
			6:'',
			7:'',
			8:'',
			9:''
		}
		_e('site_desc').innerHTML = texts[number];
	} catch(err) { trace(err.message); }
}

function registerDownload(elem) {
        try {
                var search = 'download.php?file=';
                var href = elem.href;
                if (!href || href.length == 0) trace('No HREF attribute');
                var pos = href.indexOf(search);
                if (pos>=0) href = href.substr(search.length + pos);
                pageTracker._trackPageview(href);
        } catch (err) { trace('Page not registered: ' + href) }
        return true;
}

function registerSocial(elem) {
        try {
                var search = 'IASHINGTON on ';
                var title = elem.title;
                if (!title || title.length == 0) trace('No TITLE attribute');
                var pos = title.indexOf(search);
                if (pos>=0) title = 'social/' + title.substr(search.length + pos);
                pageTracker._trackPageview(title);
        } catch (err) { trace('Page not registered: ' + title) }
        return true;
}


function registerClick(text) {
        try {
                pageTracker._trackPageview(text);
        } catch (err) { trace('Page not registered: ' + text) }
        return true;
}

function isEmail(str){
	var supported = false;
	if (window.RegExp) 
		try {
			if ((new RegExp("a")).test("a")) 
				supported = true;
		} 
		catch (err) {
		}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}

$(document).ready(function() {
	$('div ul li a')
	.mouseover(function(){
		console.log('in');
		$(this).stop().animate(
			{backgroundPosition:"(0 0)"}, 
			{duration:500})
		})
	.mouseout(function(){
		console.log('out');
		$(this).stop().animate(
			{backgroundPosition:"(0 100%)"}, 
			{duration:500}
		)
	})
});
