/**
 * @author KoreLogic
 */
	var imageHolder = new Array();
	var imageRan = new Array();
	var commentsHolder  = new Array();
	var imgID = 0	;
	var intPosLeft = 0;
	var intPosTop = 0;
	var maxHeight = 0;

	window.onload = function()
	{
		resize();
		init();
	}
	window.onresize = function()
	{
		resize();
	}
	
		function resize(){
			$('main').style.height = browserHeight()  +'px';
   			$('main').style.width = browserWidth() +'px';
			$('border').style.height = 509 +'px';
   			$('border').style.width = 865 +'px';
    		$('border').style.top = ((browserHeight() - 509)/2) +'px';
    		$('border').style.left = ((browserWidth() - 865)/2) +'px';
			$('nav').style.top = 6 +'px';
    		$('nav').style.left = 0 +'px';
			$('content').style.height = 487 +'px';
   			$('content').style.width = 489 +'px';
			$('content').style.top = 10 +'px';
			$('contentbg').style.height = 490 +'px';
   			$('contentbg').style.width = 490 +'px';
			$('contentbg').style.top = 8 +'px';
			$('content').style.left = -499 +'px';
    		$('contentbg').style.left = -500 +'px';
		}
		function openPop(url, idlink){
				$('popup').style.left = getPosition($(idlink))[0] + 70 + 'px';
				$('popup').style.top = getPosition($(idlink))[1] - 380 + 'px';
				$('popupInternal').style.left = getPosition($(idlink))[0] + 70 + 'px';
				$('popupInternal').style.top = getPosition($(idlink))[1] - 380 + 'px';
				if(winhidden == "1"){
					$('popup').show();
					$('popupInternal').show();
					var requestPage = new Ajax.Request(
					url, 
					{
						method: 'get', 
						onComplete: receivedPop
					});
				}
		}
		
		function closePop(){
				new Effect.Fade('popup',{ duration: 0.2 });
				new Effect.Fade('popupInternal',{ duration: 0.2 });
		}

		function receivedPop(originalRequest){
			$('popupInternal').innerHTML = originalRequest.responseText;
			findLocalLinks();
		}
		
		function playMovie(url){
				var requestPage = new Ajax.Request(
				url, 
				{
					method: 'get', 
					onComplete: receivedPlay
				});
		}
		function receivedPlay(originalRequest){
			$('movie').innerHTML = originalRequest.responseText;
			$('movie').show();
		}
		
		function loadBG(path){
			$('bgImage').src = path;
			//alert(path)
			//$('border').style.backgroundImage = 'url('+ path +')';
		}
		
		function init(){
			findLocalLinks();
			objPopup = new OpacityObject('popup' ,'gfx/SpeachBubble');
			objPopup.setBackground();
			$('popup').hide();
			$('popupInternal').hide();
			$('movieLinks').hide();
			$('movie').hide();
		}
		var currentPage = "";
		var currentBG = "";
		var working = "0"
		var winhidden = "1"
		function openPage(url, refID, bgPath, activeColour){
			$('popup').hide();
			$('popupInternal').hide();
			$('content').hide();
			$('movieLinks').hide();
			$('movie').hide();
			navContainer = $('nav').getElementsByTagName('a');
			for(i = 0; i < navContainer.length; i++) {
				$(navContainer[i]).style.backgroundColor = '#000000';
			}
			if (refID == "1066"){
				
				loadBG(bgPath);
				$('popups').show();
				$('movieLinks').show();
				$(refID).style.backgroundColor = '#'+activeColour;
				currentPage = refID;
				
				//if(winhidden == "0"){
					new Effect.MoveBy('contentbg', 0, -500);
					new Effect.MoveBy('content', 0, -499, {afterFinish: function()
						{
							$('content').style.left = -499 +'px';
							$('contentbg').style.left = -500 +'px';
							working = "0";
							winhidden = "1";
							loadBG(bgPath);
						}
					});
				//}
			}else{
				if (working == "0"){
					working = "1";
					currentBG = bgPath;
					if (currentPage != refID){
						getPage(url);
						$(refID).style.backgroundColor = '#'+activeColour;
						$(refID).style.color = '#000'
						currentPage = refID;
					}else{
						if(winhidden == '0'){
							new Effect.MoveBy('contentbg', 0, -500);
							new Effect.MoveBy('content', 0, -499, {afterFinish: function()
								{
									$('content').style.left = -499 +'px';
	    							$('contentbg').style.left = -500 +'px';
									working = "0";
									winhidden = "1";
									$('popups').show();
								}
							});
						}
						findLocalLinks();
						currentPage = '';
					}
					
					//if(bgPath != ''){
						//alert(bgPath)
					//}
				}
			}
		}
		
		function findLocalLinks(){
			Event.unloadCache();
			linkContainer = document.getElementsByTagName('a');
			if(linkContainer.length > 0){
				for(i = 0; i < linkContainer.length; i++) {
					//alert(linkContainer[i].hasClassName('exclude'));
					//if(linkContainer[i].hasClassName('exclude') == 'true'){
						//Event.observe(linkContainer[i], 'click', this.localLinkClick.bindAsEventListener(this.linkContainer[i]), false);
					//}
				}
			}
		}
		
		function localLinkClick(e){
			Event.stop(e);
			getPage(this.href);
			
		}
		
		function getPage(url){
			var requestPage = new Ajax.Request(
			url, 
			{
				method: 'get', 
				onComplete: receivedPage
			});
		}
		
		function receivedPage(originalRequest){
			$('content').innerHTML = originalRequest.responseText;
			findLocalLinks();
			if(winhidden == "1"){
				$('popups').hide();
				$('movieLinks').hide();
				$('popup').hide();
				$('popupInternal').hide();
				$('content').style.left = -499 +'px';
    			$('contentbg').style.left = -500 +'px';
				$('content').scrollTop = 0;
				$('content').show();
				new Effect.MoveBy('contentbg', 0, 500);
				new Effect.Appear('content',{ duration: 0.5 , afterFinish: function()
							{
								new Effect.Opacity('contentbg', {duration:0, from:1.0, to:0.98});		
							}
				});
				new Effect.MoveBy('content', 0, 499, {afterFinish: function()
					{
						working = "0";
						winhidden = "0";
						loadBG(currentBG);

					}
				});
				
			}else{
				
				$('movieLinks').hide();
				new Effect.MoveBy('content', 0, -499, {afterFinish: function()
					{
						$('content').style.left = -499 +'px';
    					$('contentbg').style.left = -500 +'px';
						
						new Effect.MoveBy('contentbg', 0, 500);
						new Effect.Appear('content',{ duration: 0.5 , afterFinish: function()
									{
										new Effect.Opacity('contentbg', {duration:0, from:1.0, to:0.98});
										working = "0";
										winhidden = "0";
										loadBG(currentBG);
										$('popup').hide();
										$('popupInternal').hide();
										$('content').show();
									}
						});
						new Effect.MoveBy('content', 0, 499);
					}
				});
				new Effect.MoveBy('contentbg', 0, -500);

			}
			
		}
		
		function browserHeight() {
		  var myWidth = 0, myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    myHeight = window.innerHeight;
		  } else if( document.documentElement &&
		      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    myHeight = document.body.clientHeight;
		  }
		  if (myHeight < 570) {
		    myHeight = 570;
		  }
		  return myHeight;
		}
		
		function browserWidth() {
		  var myWidth = 0, myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    myWidth = window.innerWidth;
		  } else if( document.documentElement &&
		      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    myWidth = document.documentElement.clientWidth;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    myWidth = document.body.clientWidth;
		  }
		  if (myWidth < 900) {
		    myWidth = 900;
		  }
		  return myWidth;
		}

//###########################################################
	function getPosition(element)
	{
		var positionX = 0;
		var positionY = 0;
		
		while (element != null)
		{
			positionX += element.offsetLeft;
			positionY += element.offsetTop;
			element = element.offsetParent
		}
		return [positionX, positionY];
	}
	
	function getElementWidth(objectId) {
		x = $(objectId);
		return x.offsetWidth;
	}

	function getAbsoluteLeft(objectId) {
		// Get an object left position from the upper left viewport corner
		o = $(objectId)
		oLeft = o.offsetLeft            // Get left position from the parent object
		while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent    // Get parent object reference
			oLeft += oParent.offsetLeft // Add parent left position
			o = oParent
		}
		return oLeft
	}

	function getAbsoluteTop(objectId) {
		// Get an object top position from the upper left viewport corner
		o = $(objectId)
		oTop = o.offsetTop            // Get top position from the parent object
		while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent  // Get parent object reference
			oTop += oParent.offsetTop // Add parent top position
			o = oParent
		}
		return oTop
	}
	