var checkerVar = 0;
ieversion = 0;
toggle = 0;
brSpacer = 0;
currMenu = null;
loaderGif = new Image(16,11);
loaderGif.src = "img/ajax-loader.gif"; 

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x;
 var ieversion=new Number(RegExp.$1)
}

if (navigator.userAgent.indexOf("Mozilla/5.0") != -1 && navigator.userAgent.indexOf("Gecko/") != -1) brSpacer = -21;

if (navigator.userAgent.indexOf("Firefox") != -1) brSpacer = -21;

if (navigator.userAgent.indexOf("Opera") != -1) brSpacer = 1;

if (ieversion>=9) brSpacer = -21;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function fixIeBG(){
	if (ieversion>0) {
		if(screen.width>1440) {
			document.body.style.backgroundImage = "url(img/bg-big.jpg)";
		}
		if (ieversion<=7) {
			brSpacer = 10;
		}
		else if (ieversion==8) {
			brSpacer = -10;
		}
	}
	else {
		$('bg').innerHTML = '<img src="img/background.jpg" id="bgimage" width="100%" height="100%" alt=""/>';
		document.body.style.backgroundImage = '';
		
	}
}

function toggleIt(){
	if (toggle==0) {
		$('portfoliosub').morph('width:210px;',{ queue: 'end' }); 
		$('portsubtext').setStyle('width:210px;'); 
		toggle = 1;
		return false;
	}
	else {
		$('portfoliosub').morph('width:0px;',{ queue: 'end' }); 
		$('portsubtext').setStyle('width:0px;');
		toggle = 0;
		return false;
	}	
}

function resizeRightBar()
{
	if ($('botright')) {
		if (ieversion>0) $('botright').style.marginTop = (443 - ($('topright').offsetHeight)-($('botright').offsetHeight))+"px";
		else $('botright').style.marginTop = (438 - ($('topright').offsetHeight)-($('botright').offsetHeight))+"px";
	}
}

function lalalalla() {
	document.write("lah");	
}

function IsNumeric(input)
{
   return (input - 0) == input && input.length > 0;
}


function showSection(elem)
{
	$(elem).style.visibility = "visible";
}


function hideSection(elem)
{
	$(elem).style.visibility = "hidden";
}

function showTh(elem)
{
	if (elem<10) elemStr = "0"+elem;
	else elemStr = elem;
	//alert(elemStr);
	//alert(($(theGallery+elem+"thumb").src));
	//alert("gallery/th/"+theGallery+elemStr+"th.jpg");
	oldSrc = $("thumb"+theGallery+elem).src;
	$("thumb"+theGallery+elem).src = "gallery/th/"+theGallery+elemStr+"th.jpg";

}

function hideTh(elem)
{	
	if (elem<10) elemStr = "0"+elem;
	else elemStr = elem;
	if ($("thumb"+theGallery+elem).src.search(/th/i)!=-1) $("thumb"+theGallery+elem).src = oldSrc;
}

function preventResizeError()
{
  //iphone detection
  if(((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) && ($('content').style.top!="2px")) {
		$('content').style.top = "2px";
		$('outer').style.top = "0px";
		$('content').style.left = "490px";
  }
  else {
	  if (window.innerHeight) {
		if (window.innerHeight<595 && ($('content').style.top!="2px")) {
			$('content').style.top = "2px";
			$('outer').style.top = "0px";
		}
		else if (window.innerHeight>=595 && ($('content').style.top=="2px")) {
			$('content').style.top = "-293px";
			$('outer').style.top = "50%";
		}
	  }
	  else if (document.documentElement.clientHeight) {	
		if (document.documentElement.clientHeight<595 && ($('content').style.top!="2px")) {
			$('content').style.top = "2px";
			$('outer').style.top = "0px";
		}
		else if (document.documentElement.clientHeight>=595 && ($('content').style.top=="2px")) {
			$('content').style.top = "-293px";
			$('outer').style.top = "50%";
		}
	  }
	  else if (document.body.clientHeight) {	
		if (document.body.clientHeight<595 && ($('content').style.top!="2px")) {
			$('content').style.top = "2px";
			$('outer').style.top = "0px";
		}
		else if (document.body.clientHeight>=595 && ($('content').style.top=="2px")) {
			$('content').style.top = "-293px";
			$('outer').style.top = "50%";
		}
	  }
	  if (window.innerWidth) {
		if (window.innerWidth<992 && ($('content').style.left!="490px")) {
			$('content').style.left = "490px";
		}
		else if (window.innerWidth>=992 && ($('content').style.left=="490px")) {
			$('content').style.left = "50%";
		}
	  }
	  else if (document.documentElement.clientWidth) {	
		if (document.documentElement.clientWidth<982 && ($('content').style.left!="490px")) {
			$('content').style.left = "490px";
		}
		else if (document.documentElement.clientWidth>=982 && ($('content').style.left=="490px")) {
			$('content').style.left = "50%";
		}
	  }
	  else if (document.body.clientWidth) {	
		if (document.body.clientWidth<982 && ($('content').style.left!="490px")) {
			$('content').style.left = "490px";
		}
		else if (document.body.clientWidth>=982 && ($('content').style.left=="490px")) {
			$('content').style.left = "50%";
		}
	  }
  }
}

function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }

    return rv;
}

function checkVersion() {
    var msg = "You're not using Windows Internet Explorer.";
    var ver = getInternetExplorerVersion();

    if (ver > -1) {
        if (ver >= 8.0)
            msg = "You're using a recent copy of Windows Internet Explorer."
        else
            msg = "You should upgrade your copy of Windows Internet Explorer.";
    }

    alert(msg);
}

// onLoad cross-browser equivalent functionality provided by the following
// Dean Edwards/Matthias Miller/John Resig

function init() {
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) clearInterval(_timer);
	
	MM_preloadImages('splash/news_test.gif','splash/paintdraw.gif','splash/about.gif','splash/contact.gif','splash/multi.gif','splash/video.gif');

	if ($('loadingGif')) {
	  $('loadingGif').style.display = "none";
	  $('loadingGif').style.position = "absolute";
	  $('loadingGif').style.top = "333px"; 
	  if (ieversion < 7 && ieversion > 0) $('loadingGif').style.left = "0px";
	  else $('loadingGif').style.left = "305px";
	}
	
	$$('.menutitle').each(function(link, idx) {
			  $(link).observe('mouseover',function() { menuToggle($(link).id); });
  			  $(link).observe('mouseout',function() { menuToggle($(link).id); });
			  $(link).observe('click',function() { menuLoad($(link).id); });			  
			}); 
	
	resizeRightBar();
	preventResizeError();
	if (cMenu = $(currMenu)) cMenu.style.color = "#777777"; 
	fixIeBG();
	//document.getElementById('bgimage').style.display = "block";
}

function fleXcrollTo(id,x,y,relative) {
	var scrollDiv = document.getElementById(id);
		 
	//Return if the target is null
	if (scrollDiv == null) return;
	//Do the scroll by using custom method attached by fleXcroll
	//but first check if the method exists.
   
	if(scrollDiv.contentScroll) scrollDiv.contentScroll(x,y,relative);
}


function menuToggle(eid) {
	if ($(eid).id === currMenu) return 0;
	else if ($(eid).activated === true) {
		$(eid).style.color = "#CCCCCC";
		$(eid).activated = false;
	}
	else {
		$(eid).style.color = "#AAAAAA";
		$(eid).activated = true;
	}
}


function menuLoad(eid) {
	moveTo($(eid).id+'_anchor');
	
	if ($(eid).id === currMenu) return 0;
	else {
		currMenu = $(eid).id;
		$$('.menutitle').each(function(link, idx) {
			  $(link).style.color = "#CCCCCC";	
			  $(link).activated = false;
		}); 
		$(eid).style.color = "#777777";
	}
}

function moveTo(elem){
    elemOffsetTop = $(elem).offsetTop+brSpacer;
	currOffsetStr = $('maincontent_contentwrapper').style.top;
	currOffsetTop = (currOffsetStr.substring(0,currOffsetStr.length-2)*-1);
	
	if (elemOffsetTop!=currOffsetTop) {
		// fDivHeight = $('act_content').offsetHeight;
		// fScrollerHeight = $('maincontent').offsetHeight - $('maincontent_vscrollerbar').offsetHeight;
		// fDest = Math.round((elemOffsetTop/fDivHeight)*fScrollerHeight);
	
		new Effect.Tween(null, currOffsetTop, elemOffsetTop, { duration: 0.8 },function(p){ fleXcrollTo('maincontent',false,((Math.round(p))+"px"),false);});
	}

	return false;
}

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */


/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = init;

