//Author: Mohamed Aly
//Date: June 27, 2007



window.addEvent('domready', function() {
	
	//navigation effects
	//initNavEffects();
	
	//periodic color on navitems
	//navItemPeriodic();
	
	//accordion effect for content
	initContentAccordionEffect();
	
	//init the gallery
    //initGallery();
    
    //Lightbox duration
    Lightbox.options.timerDuration = 5000;
    
    //add scroll to links pointing to the top of the page
    initTopLinks();    
});




//function to periodically change color of nav items
function navItemPeriodic()
{
	//colors
	var color1 = '#CC6633';
	var color2 = '#FF9900';//'#773311';//'#EEEEEE';#CC6633

	//get list of <a> items
	var list = $$('#nav a');
	//loop	
	list.each(function(e){
		//get effect
		var effect = e.effect('color', {duration:800});
		//var effect2 = e.effect('font-weight', {duration: 800});
		//function to start it
		var fx = function() {
			//start it
			effect.start(color1).chain(function() {
				effect.start(color2);
			});
			/*effect2.start('normal').chain(function() {
			    effect2.start('bold');
			});*/					
		};
		
		//call it
		fx();
		//make periodic
		var per = fx.periodical(1700);

	});
}

//function to start accordion effect
function initContentAccordionEffect()
{
    //start scrolling effect on the window
    var winScroll = new Fx.Scroll(window, {
    	wait: false,
    	duration: 500,
    	//offset: {'x': -200, 'y': -50},
    	transition: Fx.Transitions.Quad.easeInOut
    });
    
  /*      	//create the accordion on h2.accordion2 and div.accordion2 for "accordion2-1" 
        	//on pages having another level
        	var accordion2 = new Accordion($$('h2.accordion2'), 
        	    $$('div.accordion2'), {
        		//opacity transtion
        		opacity: true,
        		//can hide all contents
        		alwaysHide: false,
        		//display first item by default
        		display: 0,
        		//set active flag
        		onActive: function(toggler, element) {
        		    this.active = toggler;
        		},
        		//reset flag
        		onBackground: function(toggler, element) {
        		    this.active = null;
        		},
        		//scroll
        		onComplete: function() {
        			//tog = this.togglers[this.previous];
        			//if(tog && this.firstTime)	
        			if(this.active && this.firstTime)
        				winScroll.toElement(this.active);    				
        			this.firstTime = true;
        		}
        	}, $('content'));

	*/

  /*
	//create the accordion on h1.accordion1 and div.accordion1 for "content"
	var accordion1 = new Accordion($$('h1.accordion1'), $$('div.accordion1'), {
		//opacity transtion
		//opacity: true,
		//can hide all contents
		alwaysHide: false, //true,
		//display first item by default
		display: 0,
		//show: false,
		openAll: true, //false,
		onActive: function(toggler, element){
        		
        	
    	},
		onComplete: function() {
		    //scroll window to this toggler
		    index = this.previous;
			tog = this.togglers[index];
			if(tog && this.firstTime)	
				winScroll.toElement(tog);
			this.firstTime = true;
		}
	}, $('content'));		
	
  */
	
}


//initialize gallery
function initGallery()
{
    //look for all items with name galleryxx
    numGalleries = 10;
    for(var i=1; i<=numGalleries; i++)
    {
        //get the item
        var g = $('gallery' + String(i));
        //init the gallery if exists
        if(g)
        {
            var myGallery = new gallery(g, {
				timed: false,
				embedLinks: false,
        		thumbHeight: 75,
        		thumbWidth: 100,
    			fadeDuration: 100,
    			timed: false,
    			delay: 9000,	
    			carouselMaximizedOpacity: 0.9
			});
			
        }
    }
}

//function to give effects to navigation menu
function initNavEffects ()
{
	//get list of <a> items
	var list = $$('#nav a');
	/*//get the default values
	marginLeft = list[0].getStyle('margin-left').toInt();
	marginRight = list[0].getStyle('margin-right').toInt();
	paddingLeft = list[0].getStyle('padding-left').toInt();
	paddingRight = list[0].getStyle('padding-right').toInt();
	marginTop = list[0].getStyle('margin-top').toInt();*/
	fontSize = list[0].getStyle('font-size').toInt();


	list.each(function(element) { 
		//get width
		//left = element.getStyle('left'); 
		//get the effect			
		var fx = new Fx.Styles(element, {duration:500, wait:false});
 		//apply mouse event
		element.addEvent('mouseenter', function(){
			fx.start({
			    'font-style': 'italic'
				/*'width' : String(width+20) + 'px',
				'font-size': String(fontSize+2) + 'px'
				/*'padding-left': String(paddingLeft-10) + 'px',
				'padding-right': String(paddingRight-10) + 'px',
				/*'margin-left': String(marginLeft+5) + 'px',
				'margin-right': String(marginRight+5) + 'px'
				'margin-top': String(marginTop+5) + 'px'*/
			});
		});	 
		element.addEvent('mouseleave', function(){
			fx.start({
			    'font-style': 'normal'
				/*'width' : String(width) + 'px',
				'font-size': String(fontSize) + 'px'
				/*'padding-left': String(paddingLeft) + 'px',
				'padding-right': String(paddingRight) + 'px',
				/*'margin-left': String(marginLeft) + 'px',
				'margin-right': String(marginRight) + 'px'
				'margin-top': String(marginTop) + 'px'*/
			});
		});
	 
	});
}


//function to initialize the "top" links to scroll to the top of the page
function initTopLinks()
{
    //get a window scroll
    var winScroll = new Fx.Scroll(window, {
    	wait: false,
    	duration: 1000,
    	transition: Fx.Transitions.Quad.easeInOut
    });
    //ge the links
    var links = $$('div.top a');
    //iterate and scroll to top of element 'thebox'
    links.each( function(link) {
        link.onclick = function() { 
            winScroll.toElement($('thebox'));
            return false;
        };
    });

}

