// Written by Neil Mendoza - djapex [at] uk2 [dot] net
// www.ninjazoo.com
var Peak = Class.create();
var currNav;
Peak.prototype = {

    initialize: function(open)
    {
    	this.matchColumns(55);
        if (open)
        {
        	this.running = true;
        	setTimeout('myPeak.openM()', 1500);
        }
        else
    	{
    		this.open = true;
    		this.running = false;
    	}
        this.pic = 0;
    },
    
    jsNav: function(num)
    {
    	if (currNav && currNav != num && $('jsNav' + currNav)) Element.hide('jsNav' + currNav);
    	if ($('jsNav' + num)) Element.show('jsNav' + num);
    	currNav = num;
    },
    
    openM: function()
    {
    	this.running = true;
	    new Effect.Parallel([
			new Effect.MoveBy('mandalaL', 0, -452, { sync: true }),
			new Effect.MoveBy('mandalaR', 0, 454,{ sync: true } )],
			{ duration: 1.5 } );
		new Effect.Parallel([
			new Effect.MoveBy('smallL', 0, 85, { sync: true }),
			new Effect.MoveBy('smallR', 0, -87,{ sync: true } )],
			{ duration: 1, delay: 0.5, afterFinish: function() {myPeak.fadeBg(false)} } );
    },
    
    closeM: function()
    {
    	this.running = true;
    	myPeak.fadeBg(function()
	    	{
		    	new Effect.Parallel([
					new Effect.MoveBy('mandalaL', 0, 452, { sync: true }),
					new Effect.MoveBy('mandalaR', 0, -454,{ sync: true } )],
					{ duration: 0.8, afterFinish: function() {myPeak.open = false; myPeak.running = false;}} );
				new Effect.Parallel([
					new Effect.MoveBy('smallL', 0, -85, { sync: true }),
					new Effect.MoveBy('smallR', 0, 87,{ sync: true } )],
					{ duration: 0.4} );
			});
    },
    
    fadeBg: function(afterIn) 
    {
	    if (afterIn)
	    {
			// if you fade something to 0 it seems to disappear altogether
			new Effect.Parallel([
				new Effect.Fade('bgCont', {from: 0.3, to: 1, sync: true}),
				new Effect.Fade('nav', {from: 1, to: 0.1, sync: true}),
				new Effect.Fade('content', {from: 1, to: 0.1, sync: true}),
				new Effect.Fade('jsNavCont', {from: 1, to: 0.1, sync: true})],
				{
					duration: 0.6, afterFinish: function()
						{
							Element.setOpacity('nav', 0);
							Element.setOpacity('content', 0);
							Element.setOpacity('jsNavCont', 0);
							afterIn.apply();
						}
				}
			);
			//new Effect.Fade('bgCont', {from: 0.2, to: 1, duration: 0.1, afterFinish: afterIn});
		}
		else
		{
			//Element.setOpacity('content', 1);
			//Element.setOpacity('nav', 1);
			new Effect.Parallel([
				new Effect.Fade('bgCont', {from: 1, to: 0.3, sync: true}),
				new Effect.Fade('nav', {from: 0.1, to: 1, sync: true}),
				new Effect.Fade('content', {from: 0.1, to: 1, sync: true}),
				new Effect.Fade('jsNavCont', {from: 0.1, to: 1, sync: true})],
				{duration: 0.6, afterFinish: function(){ myPeak.open = true; myPeak.running = false;}}
			);
		}
    },
    
    toggleM: function()
    {
    	if (!this.running)
    	{
	    	if (this.open) this.closeM();
	    	else this.openM();
    	}
    },
    
    showContent: function()
    {
    	if (!this.started)
    	{
    		new Effect.Fade('startImg', {to: 0, duration: 0.7});
    		this.started = true;
    	}
    },
    
    fadeToPic: function(newPic)
    {
    	
    	if (!this.running && newPic != this.pic)
    	{
	    	var _this = this;
	    	var oldPic = this.pic;
	    	new Effect.Parallel([
	    		new Effect.Fade('genrePic' + newPic, {from: 0.1, to:1.0, sync: true}),
	    		new Effect.Fade('genrePic' + oldPic, {from: 1.0, to:0.1, sync: true})],
	    		{duration: 0.7, afterFinish: function(){_this.running = false;}});
	    	this.pic = newPic;
	    }
    },

	matchColumns: function(extra)
	{ 
		var els, contDivs, maxHeight, divHeight, d; 
		// get all <div> elements in the document 
		els = document.getElementsByClassName('column');
		contDivs=[];
		// initialize maximum height value 
		maxHeight=0; 
		// iterate over all <div> elements in the document 
		var tableFound = false;
		for(var i=0; i<els.length; i++)
		{ 
			// make collection with <div> elements with class attribute 'container' 
			if(Element.hasClassName(els[i], "column"))
			{
				d=els[i]; 
				contDivs[contDivs.length]=d; 
				divHeight=Element.getHeight(d);
				/*if (d.nodeName == 'TABLE')
				{
					maxHeight = divHeight;
					tableFound = true;
				}*/
				// calculate maximum height 
				//if (!tableFound) maxHeight=Math.max(maxHeight,divHeight);
				maxHeight=Math.max(maxHeight,divHeight); 
	          } 
		} 
		if (maxHeight < 1200) maxHeight = 1200;
		if (extra) maxHeight += extra;
		// assign maximum height value to all of container <div> elements 
		for(var i=0;i<contDivs.length;i++)
		{ 
			var inc = 200;
			switch (contDivs[i].id)
			{
				case 'frameTileL':
				case 'frameTileR':
	     	  		inc = -200;
	     	  		break;
	     	  	case 'bgCont':
	     	  		inc = 250;
	     	  		break;
			}
			if (contDivs[i].nodeName != 'TABLE') contDivs[i].style.height = (maxHeight + inc) + "px"; 
		}
		$('cright').style.top = (maxHeight + 186) + 'px';
		Element.show('cright');
	},
	
	showRelease: function(url)
	{
		this.releaseLoaded = 0;
		new Ajax.Updater('releaseUpdate', url, {asynchronous:true, evalScripts:true, onComplete: function()
			{
				/*if (++myPeak.releaseLoaded == 2) myPeak.matchColumns();
				else */ myPeak.matchColumns(270);
			}}); 
	},
	
	coverLoaded: function()
	{
		// give the image 1/20 sec to render
		this.releaseLoaded++;
		//if (++this.releaseLoaded == 2) setTimeout('myPeak.matchColumns()', 400);
	},
	
	joinNodeLists: function(list1,list2)
	{
		var i = list2.length - 1;	
		do
		{
			list1[list1.length] = list2[i];
		}
		while(i--);
		return list1;
	}
};
function coverLoaded()
{
	if (myPeak) myPeak.coverLoaded();
}
function popUp(id, url,w, h)
{
	var w = window.open(url, id, 'width=' + w + ',height=' + h + ',directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,screenx=150,screeny=150');
	w.focus();
}
var imgSrc = new Array('/img/frLeft.png', '/img/frRight.png', '/img/frTileRight.jpg',
				'/img/frTileLeft.jpg', '/img/mLeft.png', '/img/mRight.png', '/img/mTile.jpg', '/img/molMouseOn.jpg');
var imgs = new Array();
for (var i = 0; i < 9; i++)
{
	imgs[i] = document.createElement('img');
	imgs[i].src = '/img/nav' + (i + 1) + 'on.jpg';
}
for (var i = 0; i < imgSrc.length; i++)
{
	imgs[i + 9] = document.createElement('img');
	imgs[i + 9].src = imgSrc[i];
}

