window.addEvent('domready', function() {
	

	$$('.quotes_loop').setStyle('display','none');
	$$('.quotes_loop')[0].setStyle('display','block');
	
	var currentIndex = 1;
	
	var nextQuote = function(){	

		if(currentIndex == $$('.quotes_loop').length) {
			currentIndex = 0;
		}				

		$$('.quotes_loop').setStyle('display','none');
		$$('.quotes_loop')[currentIndex].setStyle('display','block');
	
		currentIndex++;
	};
	
	nextQuote.periodical(8000);
	

	if($('contact_form')) {

        $('sendform').addEvent('click',function(e) {
        	e.stop();
            contactFormRequest.post($('contact_form'));
        })        


     	var contactFormRequest = new Request.HTML({
         	url:'/index.php?type=ajax',
                link: 'cancel',
                update:'contact_form_response',
                onRequest: function() {
                 	$('contact_form_response').set('html','<p>Sending...</p>');
                },
                onSuccess: function(html){
                        if($('contact_form_response').get('html').test("Thank you")) {
                                $('contact_form').destroy();
                        }
                }
        });
         

	}

		/*
		// Portfolio
		*/
		
		if($('portfolio-wrapper')) {
			
			
			portfolioScroll = new Fx.Scroll('portfolio-wrapper', {
			    offset: {'x': 0,'y': 0},
			    link: 'cancel',
			    'transition': 'quad:out',
		        'duration':1000,	    
			    wheelStops : false
			});
			
			var portfolioWidth = 700;
			
			var current_item = 'home-content';
			
			var portfolioWrapper = 0;							
			$$('.portfolio').each(function(element) {
				portfolioWrapper += 700;
			})		
			$('portfolio-inner').setStyle('width',portfolioWrapper);		
			
			
			
			$$('.portfolio-next').addEvent('click',function(event) {			
				event.stop();
				if(current_item == 'contact-content') {
					gotoitem('home-content');			
				} else if(current_item == 'home-content') {
					gotoitem('media-content');			
				}  else if(current_item == 'media-content') {
					gotoitem('production-content');
				} else if(current_item == 'production-content') {
					gotoitem('design-content');
				} else if(current_item == 'design-content') {
					gotoitem('digital-content');
				} else if(current_item == 'digital-content') {
					gotoitem('about-content');
				} else if(current_item == 'about-content') {
					gotoitem('contact-content');
				} 
			});
			
			$$('.portfolio-previous').addEvent('click',function(event) {
				event.stop();
				if(current_item == 'contact-content') {
					gotoitem('about-content');					
				} else if(current_item == 'about-content') {
					gotoitem('digital-content');
				} else if(current_item == 'digital-content') {
					gotoitem('design-content');
				} else if(current_item == 'design-content') {
					gotoitem('production-content');
				} else if(current_item == 'production-content') {
					gotoitem('media-content');
				} else if(current_item == 'media-content') {
					gotoitem('home-content');
				} else if(current_item == 'home-content') {
					gotoitem('contact-content');
				}
			});
			
			
			function gotoitem(item) {
				
				$$('.jslink').removeClass('On');
				$(item+'-link').addClass('On');
				portfolioScroll.toElement(item);			
				current_item = item;
					
			}
			
			$$('.jslink').addEvent('click',function(evt){
				evt.stop();
				gotoitem(this.get('id').replace('-link',''));	
			});
				
			$$('.contact-link').addEvent('click',function(evt){
				evt.stop();
				gotoitem('contact-content');	
			});
			
			$$('.media-link').addEvent('click',function(evt){
				evt.stop();
				gotoitem('media-content');	
			});

			$$('.design-link').addEvent('click',function(evt){
				evt.stop();
				gotoitem('design-content');	
			});
			
			$$('.digital-link').addEvent('click',function(evt){
				evt.stop();
				gotoitem('digital-content');	
			});

			$$('.production-link').addEvent('click',function(evt){
				evt.stop();
				gotoitem('production-content');	
			});
			/* start web gallery */
			$$('.design-link').addEvent('click',function(evt){
				evt.stop();
	    
	            Slimbox.open(
		            [["/img/artworks/MM001.jpg"],
		            ["/img/artworks/MM002.jpg"],
		            ["/img/artworks/MM003.jpg"],
		            ["/img/artworks/MM004.jpg"],
		            ["/img/artworks/MM005.jpg"],
		            ["/img/artworks/MM006.jpg"],
					["/img/artworks/MM007.jpg"],
					["/img/artworks/MM008.jpg"],
					["/img/artworks/MM009.jpg"],
					["/img/artworks/MM010.jpg"],
					["/img/artworks/MM011.jpg"],
					["/img/artworks/MM012.jpg"],
					["/img/artworks/MM013.jpg"],
					["/img/artworks/MM014.jpg"],					
					["/img/artworks/MM015.jpg"],					
					["/img/artworks/MM016.jpg"],					
					["/img/artworks/MM017.jpg"],					
		            ["/img/artworks/MM018.jpg"]],0
	            );           

	           
			});
			/* start print gallery */
			$$('.gallery-link').addEvent('click',function(evt){
				evt.stop();
	    
	            Slimbox.open(
		            [["/img/digital/bluemax.jpg"],
		            ["/img/digital/cavity-trays.jpg"],
		            ["/img/digital/challenge.jpg"],
		            ["/img/digital/dpc.jpg"],
		            ["/img/digital/harris-fowler.jpg"],
		            ["/img/digital/senior-selections.jpg"],
					["/img/digital/johnsassoc.jpg"],
		            ["/img/digital/ttt.jpg"]],0
	            );           

	           
			});
			
		}
			
		/*
		// The shutters
		*/
		
		if($$('.shutter')) {
			$$('.shutter').addEvent('mouseenter',function() {			
				this.getFirst('.inner-shutter').set('tween',{duration: 700, transition: 'bounce:out'});
				this.getFirst('.inner-shutter').tween('top',0);
			})
			
			$$('.shutter').addEvent('mouseleave',function() {
				this.getFirst('.inner-shutter').set('tween',{duration: 500});
				this.getFirst('.inner-shutter').tween('top',0-this.getStyle('height').toInt());				
			})
		}
		
		/*
		// Contact form
		*/
			
		if($('contact')) {
			$('contact').addEvent('submit',function(event) {
				event.stop();				
				var sendform = new Request.HTML({url:'/ajax-email.php',update: $('email-response')}).post($('contact'));												
			})		
		}		
		
		/* ToolTips */
		$$('.ToolTips').each(function(element,index) {  
			var content = element.get('title').split('::');  
			element.store('tip:title', content[0]);  
			element.store('tip:text', content[1]);  
		});
		
		var ToolTips = new Tips('.ToolTips',{
			className: 'tips'
		});
		
		ToolTips.addEvent('show', function(tip){
			tip.fade('in');
		});
		
		ToolTips.addEvent('hide', function(tip){
			tip.fade('out');
		});
				
})