/////////////////////////
//FOR PRE-ORDER METER ANIMATION
//US// var iMeterLoop = 0;	//Counter for sales meter level, iMeterLoop value of 1 = 1 pixel height, 1 pixel = 10 sold games 
//US// var fSoldUnits = iSoldUnits/10;	//To make the meter loop only draw 1/10 of the sales
//US// var sGoalColor = '#00ff00';

//////////////////////////
//BUTTONS AND PAGE CONTENT 
var sPageActive;	//Store what page is active
var sCurrentColor = '#0b0a09';	//Current button for active page
var sActiveColor = '#4b4a49';	//Mouse over button
var sIdleColor = '#3b3a39';		//Mouse out button
var aButtons = new Array('Main','Game','Media','Demo','Buy');	//To keep right color on buttons
var aEU = new Array('UK','SE','DK','FI','NO','IE','ES','DE','AT',
					'BE','FR','GR','IS','IT','LU','NL','PT','CH');
var aNA = new Array('CA','US');
var aRU = new Array('RU','PL','BG','CZ','HU','UA','EE','BY','LV',
					'LT','AM','AZ','GE','KZ','KG','MD','SL','UZ',
					'TM','TJ');
var sPageContent = '';

//////////////////////////
//FOR FADE IN/OUT OF PAGES
var fFadeIn = 0.0;				//Fade in from this value, anything above 0 will not make the PR Blobs go away 
var fFadeOut = 1.0;				//Fade out from this value, 1.0 makes the PR Blob display with full opacity
var iFadeSpeed = 40;			//How long time between each 0.1 step in opacity fade, millisec
var fMaxOpacity = fFadeOut;
var fMinOpacity = fFadeIn;

/////////////////////////
//MISC
var mRefill = '';	//Sloppy double image fix


////////////////////////////
//PAGE LOADING
/*Content loading for pages
 */
function LoadPage(sName)
{	
	if(sPageActive == sName) return;
	
	sPageActive = sName;
	
	//Fix for sale text
	if(sName == "sale_link")	
		sName = 'Buy';
	
	ButtonSet(sName);
	
	FadeIn('page_content',SiteTexts(sName));
	
	BackGroundImage(sName);
	
	window.location.hash = sName.replace(sName.substr(0,1),sName.substr(0,1).toLowerCase());
	sPage = sPageActive;
	
	if(sName == 'Buy'){
		if(navigator.platform.indexOf('Linux') > -1) var sPlatform = 'Linux';
		else if(navigator.platform.indexOf('Mac') > -1) var sPlatform = 'Mac';
		else var sPlatform = 'Windows';

		for(i=0;i<aEU.length;i++)
			if(aEU[i] == sULocation) sULocation = 'Europe';

		for(i=0;i<aRU.length;i++)
			if(aRU[i] == sULocation) sULocation = 'Russia';
		 
		if(sULocation != 'Europe' && sULocation != 'Russia') 
			sULocation = 'NA';

		CreateStoreList('platform', sPlatform);
		CreateStoreList('retail', sULocation);
	} 
	
	/*Only to fix double image problem in gallery, out of time!
	 */
	if(sName == 'Media'){
		if(mRefill != '') Shadowbox.clearCache();
		else mRefill = document.getElementById('bookMedia').innerHTML;
		
		document.getElementById('bookMedia').innerHTML = '';
		
		Shadowbox.setup("a.gallery", { 
			gallery: "Amnesia Images" 
		});
		
		document.getElementById('bookMedia').innerHTML = mRefill;
	} 
	
	/*Only for temporary sidebar
	 */

	PopSideBarClose();
} 

/*Change background images for pages
 */
function BackGroundImage(sName)
{
	document.getElementById('s_Main').style.visibility = 'hidden';
	document.getElementById('s_Game').style.visibility = 'hidden';
	document.getElementById('s_Media').style.visibility = 'hidden';
	document.getElementById('s_Demo').style.visibility = 'hidden';
	document.getElementById('s_Buy').style.visibility = 'hidden';
	
	document.getElementById('s_'+sName).style.visibility = 'visible';
} 

/*Fill buy & demo lists with content
 */
function CreateStoreList(sType,sList)
{
	if(sType == 'platform'){
		document.getElementById('Windows').style.backgroundColor  =  sIdleColor;
		document.getElementById('Mac').style.backgroundColor  =  sIdleColor;
		document.getElementById('Linux').style.backgroundColor  =  sIdleColor;
	} 
	else if(sType == 'retail'){
		document.getElementById('Europe').style.backgroundColor  =  sIdleColor;
		document.getElementById('NA').style.backgroundColor  =  sIdleColor;
		document.getElementById('Russia').style.backgroundColor  =  sIdleColor;
	}
	
	document.getElementById(sList).style.backgroundColor  = sCurrentColor;
	
	document.getElementById(sType+'StoreList').innerHTML = document.getElementById('book'+sList).innerHTML  
}

/*Fetch text from hidden divs
 */
function SiteTexts(sName)
{	
	sPageContent = 'book'+sName;

	sPageContent = document.getElementById(sPageContent).innerHTML;

	return sPageContent;
}

/*Show html messages in a small window
 */
function PopText(sName,iSizeH,iSizeW){
	if(iSizeH === undefined)
      iSizeH = 350;
	  
	if(iSizeW === undefined)
		iSizeW = 350;
	  
	if(sPage == 'Main')
		document.getElementById('video_main_div').style.visibility = 'hidden';
		
	sTitle = document.getElementById(sName).innerHTML;
	sContent = SiteTexts(sName);
	
    Shadowbox.open({
        content:    '<div class="PopMessage">'+sContent+'</div>',
        player:     'html',
        title:      '<div class="PopTitle">'+sTitle+'</div>',
        height:     iSizeH,
        width:      iSizeW,
		options:{ 
        	onClose: function(){ document.getElementById('video_main_div').style.visibility = 'visible'; } 
        }
    });
}

/*Show content from other sites in a window
 */
function PopExt(sLocation,sTitle,iSizeW,iSizeH){
	if(sPage == 'Main')
		document.getElementById('video_main_div').style.visibility = 'hidden';
		
    Shadowbox.open({
        content:    sLocation,
        player:     'iframe',
        title:      sTitle,
		height:     iSizeH,
        width:      iSizeW,
		options:{ 
        	onClose: function(){ document.getElementById('video_main_div').style.visibility = 'visible'; } 
        }
    });
}

/*Only for temporary sidebar
 */
function LoadGallery()
{
	Shadowbox.setup("a.gallery_side", { 
		gallery: "Amnesia Images 2"
	});
} 
function PopSideBar(){
	document.getElementById('video_main_div').style.visibility = 'hidden';
}
function PopSideBarClose(){
	document.getElementById('video_main_div').style.visibility = 'visible';
}
///////////////////////////


////////////////////////////
//ELEMENT EFFECTS - MouseOver
function PreLoadButtons() 
{
	//US// "images/Message1_over.png", "images/Message1_reached.png", 
	
	var imgArray = ["images/PreOrder_over.jpg",
					"images/Main_over.jpg", "images/Main_current.jpg",
					"images/Game_over.jpg", "images/Game_current.jpg",
					"images/Buy_over.jpg", "images/Buy_current.jpg",
					"images/Media_over.jpg", "images/Media_current.jpg",
					"images/Demo_over.jpg", "images/Demo_current.jpg"];
			
	while(imgArray.length > 0) { 
		tempImg = new Image(); 
		tempImg.src = imgArray.shift();
	}
} 
	
/*Change mouse cursor for areas
 */
function Area(bState) 
{
	if(bState) document.body.style.cursor = 'pointer';
	else document.body.style.cursor = 'auto';
} 


/*Button mouse on/off switch
 */
function ButtonGFX(sName,bState) 
{
	if(bState)
		document.getElementById(sName).src = "images/"+sName+"_over.jpg";
	else{
		if(sPageActive != sName) document.getElementById(sName).src = "images/"+sName+".jpg";
		else document.getElementById(sName).src = "images/"+sName+"_current.jpg";
	} 
}
/*US//function ButtonGFXMeter(sName,bState) 
{
	if(bState)
		document.getElementById(sName).src = "images/"+sName+"_over.png";
	else{
		if(iMeterLoop < 200) document.getElementById(sName).src = "images/"+sName+".png";
		else document.getElementById(sName).src = "images/"+sName+"_reached.png";
	} 
}*/
/*Change the buttons to reflect what page is active
 */
function ButtonSet(sName)
{
	for(var i=0;i<aButtons.length;i++)
		document.getElementById(aButtons[i]).src = "images/"+aButtons[i]+".jpg";
		
	document.getElementById(sName).src = "images/"+sName+"_current.jpg";
} 


////////////////////////////
//ANIMATION EFFECTS - Content FADE & METER
/*Fade In Content
 */
function FadeIn(sArea,sName)
{	
	if(fFadeIn <= 0.0)
		document.getElementById(sArea).innerHTML = sName;
	
	if(fFadeIn >= fMaxOpacity) {
		fFadeIn = fMinOpacity; 	
		return;
	}

	fFadeIn += 0.25;
	
	document.getElementById(sArea).style.opacity = fFadeIn;
	document.getElementById(sArea).style.filter = 'alpha(opacity=' + fFadeIn*100 + ')';
	
	tArea = sArea;
	tName = sName;
	
	setTimeout('FadeIn(tArea,tName)',iFadeSpeed);
}

/*Animating the pre-order meter
 */
/*US// function DrawMeterLevel()
{
	if(iMeterLoop < fSoldUnits-4)
		document.getElementById('MeterValue').innerHTML = iMeterLoop*10;
	else
		document.getElementById('MeterValue').innerHTML = iSoldUnits; 
		
	document.getElementById('MeterLevel').style.height = iMeterLoop+'px'; 	

	switch(iMeterLoop){
		case 200:
			document.getElementById('Message1').src = "images/Message1_reached.png";
		break;
	}
	
	iMeterLoop+=4;
	
	if(iMeterLoop <= fSoldUnits) setTimeout('DrawMeterLevel()', 50);
}*/
