

SoftloopPageEngine = Class.create();
SoftloopPageEngine.prototype = {

	initialize: function() {
		this.contentLoaded = false;
	},
	
	initAccordion: function(){
	
		if($('nav')){
			var mainNavAccordion = new accordionNav('nav',
				{     
					classNames : 
						{
						/* 	toggle : 'softloop-accordion-toggle',
							toggleActive : 'softloop-accordion-toggle-active',
							content : 'softloop-accordion-content' */
						},
					onEvent : 'mouseover'
				}
			);
		}
	},
	
	initIntro: function(){
		this.introLoadingCont = null;
		if(this.introDiv) {
			this.introDiv.style.position = "relative";
			this.introLoadingCont = document.createElement("DIV");
			this.introLoadingCont.style.position = "absolute";
			this.introLoadingCont.style.visibility = "hidden";
			this.introLoadingCont.style.zIndex = "1000";
			this.introLoadingCont.className = "introLoadingImage";
			this.introLoadingCont.style.display = "block";
			this.introLoadingCont.style.textAlign = "center";
			this.introLoadingCont.style.padding = "2px";
			this.introLoadingCont.style.background = "#ffffff";
			this.introLoadingCont.style.border = "none";
			this.introLoadingCont.style.width = "126px";
			this.introLoadingCont.style.height = "35px";
			this.introLoadingCont.innerHTML = "<img border=\"0\" alt=\"Loading intro, please wait\" src=\"skin/frontend/default/renestorck/images/opc-ajax-loader.gif\"/>";
			this.introDiv.appendChild(this.introLoadingCont);
		}
	},
	
	introShowLoadingStat: function(){
		if (this.introLoadingCont != null && !this.contentLoaded && parseInt(this.introDiv.offsetWidth) != 0 && parseInt(this.introDiv.offsetHeight) != 0)
		{
			this.introLoadingCont.style.left = (parseInt(this.introDiv.offsetWidth) / 2 - parseInt(this.introLoadingCont.offsetWidth) / 2) + "px";
			this.introLoadingCont.style.top = (parseInt(this.introDiv.offsetHeight) / 2 - parseInt(this.introLoadingCont.offsetHeight) / 2) + "px";
			this.introLoadingCont.style.visibility = "visible";
		}
	},
	
	introHiddeLoadingStat: function(){
		if (this.introLoadingCont) {
			this.introLoadingCont.style.visibility = "hidden";
		}
	},
	
	introBlendIn: function(){
		
		if(this.introImages && this.introImages.length > 0)
		{
			this.introImages[this.introIndex].setOpacity(0.0);
			this.introImages[this.introIndex].style.display="block";
			new Effect.Opacity(this.introImages[this.introIndex],
				{
					from: 0.0,
					to: 1.0,
					duration: 0.5,
					afterFinish: function (){
						this.introBlendOut();
					}.bind(this)
				}
			);
		}
	},
	
	introBlendOut: function(){
		if(this.introImages && this.introImages.length > 0)
		{
			new Effect.Opacity(this.introImages[this.introIndex], 
				{ 
					from: 1.0, 
					to: 0.0, 
					duration: 1.0, 
					delay: 7.0,
					afterFinish: function (){
						this.introImages[this.introIndex].style.display="none";
						this.introBlendIn();
					}.bind(this)
				}
			);
			
			this.introIndex++;
			
			if(this.introIndex >= this.introImages.length){
				this.introIndex=0;
			}
		}
		
	},
	
	setContentLoaded: function(stat){
		if(stat == true){
			this.introDiv = $('intro-div');
			this.introImages = $$('#intro-div img');
			this.introIndex = 0;
		}
		this.contentLoaded = stat;
	}
};

sPE = new SoftloopPageEngine(); 

// pagelogig
Event.observe(window, 'load', function() 
	{   
		sPE.initAccordion();
		sPE.setContentLoaded(true);
		sPE.introHiddeLoadingStat();
		sPE.introBlendIn();
	}
);

Event.observe(document, 'dom:loaded', function()
	{
		if(sPE.contentLoaded == false){
			sPE.initIntro();
			sPE.introShowLoadingStat();
		}
	}
);
