/*MMOsite top & mmosite footer*/
function rohanHeader(){
	mmoHeader()
}
function rohanFooter(){
	mmoFooter()
}

/*MMOsite flash*/
function playFlash(flashid){
    var fpic =document.getElementById(flashid).getElementsByTagName("img");
	var flink =document.getElementById(flashid).getElementsByTagName("a");
	var texts =document.getElementById(flashid).getElementsByTagName("a");
	var pic_width="280";
           var pic_height="210"; 
	var button_pos=fpic.length;
	var stop_time=5000; 
	var show_text=1; 
	var txtcolor="dddddd";
	var bgcolor="000000";
	var imag=new Array();
	var link=new Array();
	var text=new Array();

	var flashUrl = 'http://images.mmosite.com/aion/focus/viewer.swf';


   for(var i=0;i<fpic.length;i++){
   imag[i]=fpic[i].src;
   }  

	var swf_height=pic_height;
	var pics="", links="", texts="";
	for(var i=0; i<imag.length; i++){
		pics=pics+("|"+imag[i]);
		links=links+("|"+flink[i]);
		

		//links=links+("|"+flink[i*2]);
		
		links = links.replace(/(&)/g,"+");
		texts=texts+("|"+text[i]);
		//alert(flink[i*2]);
	}
	
	pics=pics.substring(1);
	links=links.substring(1);
	texts=texts.substring(1);
	
	
	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ pic_width +'" height="' + pic_height +'" /><param name="allowScriptAccess" value="always" />';
	flash = flash + '<param name="movie" value="'+ flashUrl +'" />';
	flash = flash + '<param name="quality" value="high" />';
	flash = flash + '<param name="menu" value="false" />';
	flash = flash + '<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&picwidth='+pic_width+'&picheight='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">';
    flash = flash + '<param name="wmode" value="transparent" />';
	flash = flash + '<embed wmode="transparent" src="' + flashUrl + '" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&picwidth='+pic_width+'&picheight='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" quality="high" width="'+ pic_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"allowScriptAccess="always"  />';
	flash = flash + '</object>';
	document.writeln(flash); 
	//document.writeln(links+"<br />"); 
}

/* switch*/

function $( id ){ return document.getElementById( id ); }
var switchpage = function(o, n, p){
   var ol = $(o+p);
   var cl = $(o+n);
   ol.style.display="none";
   cl.style.display="";
}
var doStyle = function( num,id_name,style_name ){
	var self = $( id_name ).getElementsByTagName("a");
    for( var i = 0; i < self.length; i++ ){
   		self[i].className = "";
		self[i].onfocus = function(){ this.blur() };
    }
    self[num-1].className = style_name;
}
var p1 = 1;
function page1(num){  
   doStyle( num,"top-search-tabs","tab-style1" );
   switchpage("top-tab-cnt", num, p1);
   p1 = num;
   
   return false;
}
var p2 = 1;
function page2(num){
   doStyle( num,"the-tab2","tab-style");
   switchpage("guide-cnt", num, p2);
   p2 = num;
   
   return false;
}
var p3 = 1;
function page3(num){  
   switchpage("question-tab-cnt", num, p3);
   p3 = num;
   
   return false;
}

/* switch2*/

var currentSection = "screenchots-pane"; // The default loaded section on the page
var tabTag = "-tab";
var paneTag = "-pane";

// Scroll the page manually to the position of element "link", passed to us.

function ScrollSection(link, scrollArea, offset)
{

	// Store the last section, and update the current section

	if (currentSection == link) {
		return;
	}
	lastSection = currentSection;
	currentSection = link;
	
	// Change the section highlight.
	// Extract the root section name, and use that to change the background image to 'top', revealing the alt. state

    sectionTab = currentSection.split("-")[0] + tabTag;
    document.getElementById(sectionTab).className = 'active';
    if (lastSection) {
	   lastTab = lastSection.split("-")[0] + tabTag;
	    document.getElementById(lastTab).className = "inactive";
	}
    
	// Get the element we want to scroll, get the position of the element to scroll to
	
	theScroll = document.getElementById(scrollArea);
	position = findElementPos(document.getElementById(link));
	
	// Get the position of the offset div -- the div at the far left.
	// This is the amount we compensate for when scrolling
	
	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		position[0] = position[0] - offsetPos[0];
	}

	
	scrollStart(theScroll, theScroll.scrollLeft, position[0], "horiz");
	// return false;
}
function ScrollArrow(direction, toolbar, scrollArea, offset) {

	toolbarElem = document.getElementById(toolbar);
	toolbarNames = new Array();
    
	// Find all the <li> elements in the toolbar, and extract their id's into an array.
    
	if (toolbarElem.hasChildNodes())
	{
		var children = toolbarElem.childNodes;
		for (var i = 0; i < children.length; i++) 
		{
			if (toolbarElem.childNodes[i].tagName == "LI") {
				toolbarNames.push(toolbarElem.childNodes[i].id.split("-")[0]);
			}
		}
	}

	// Now iterate through our array of tab names, find matches, and determine where to go.

	for (var i = 0; i < toolbarNames.length; i++) {
		if (toolbarNames[i] == currentSection.split("-")[0]) {
			if (direction == "left") {
				if (i - 1 < 0) {
					gotoTab = toolbarNames[toolbarNames.length - 1];
				} else {
					gotoTab = toolbarNames[i - 1];
				}
			} else {
				if ((i + 1) > (toolbarNames.length - 1)) {
					gotoTab = toolbarNames[0];
				} else {
					gotoTab = toolbarNames[i + 1];
				}
			}
		}
	}
	
	// Go to the section name!
	
	ScrollSection(gotoTab+paneTag, scrollArea, offset);

}
var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function scrollStart(elem, start, end, direction)
{
	//console.log("scrollStart from "+start+" to "+end+" in direction "+direction);

	if (scrollanim.timer != null) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	scrollanim.time = 0;
	scrollanim.begin = start;
	scrollanim.change = end - start;
	scrollanim.duration = 25;
	scrollanim.element = elem;
	
	if (direction == "horiz") {
		scrollanim.timer = setInterval("scrollHorizAnim();", 15);
	}
	else {
		scrollanim.timer = setInterval("scrollVertAnim();", 15);
	}
}

function scrollVertAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollTop = move; 
		scrollanim.time++;
	}
}

function scrollHorizAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollLeft = move;
		scrollanim.time++;
	}
}
function findElementPos(elemFind)
{
	var elemX = 0;
	var elemY = 0;
	do {
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} while ( elemFind = elemFind.offsetParent )

	//console.log("Found element "+elemFind+" at "+elemY+"/"+elemX);

	return Array(elemX, elemY);
}
function sineInOut(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}





