/* Author: 

*/

(function($) {
		
	$(document).ready(function() {
		//console.log('ready');
		
		// vars
		var nav = {  0:'home',1:'locations',2:'atwork',3:'clients',4:'about',5:'contact', 6:'news' };
		
		// utils
		$('span.mailme').mailme();
		
		// this slideshow needs to init() before hashchange
		$('#MasterShow').cycle({
			fx:'fade',
			timeout:0,
			speedIn: 600, 
			speedOut: 600,
				sync: 0
  	});
		
		
		// browser back btn
	  $(window).hashchange( function(){
	    
	    var hash = location.hash.replace( /^#!\//, '' ).toLowerCase();
	    
	    if (hash) { gotoScreen(hash); }
	    
	  })
	  $(window).hashchange();

		
		function gotoScreen(hash) {
			
			//console.log('gotoScreen::hash::'+hash);
			
			var displayhash = hash=='atwork' ? '@work' : hash ;
			document.title = 'thesearch: ' + displayhash;
			
			if (hash=='home') {
			
				$('.nav').hide(500);
				$('.slideshow').cycle('destroy');
				$('#MasterShow').cycle(0);
				
			} else {
			
				for (key in nav) {
					if (nav[key]==hash) {
						
						//console.log('gotoScreen::key::'+key);
						
						$('.slideshow').cycle('destroy');
						$('.nav').show(500);
						$('#MasterShow').cycle(key*1); 
						
						if (	$('.'+hash).is(':visible') ) {
							//console.log('gotoScreen::slideshow::'+hash);
							
							if (hash=='clients') {
								/*$('.'+hash).cycle({ 
									fx:'scrollLeft',
									timeout: 2000,
									speed:500
									//pause: true
				      	});*/
				      	
				      	$('.'+hash).serialScroll({
											items:'p',
											duration:1500,
											force:true,
											axis:'y',
											easing:'linear',
											lazy:true,// NOTE: it's set to true, meaning you can add/remove/reorder items and the changes are taken into account.
											interval:1, // yeah! I now added auto-scrolling
											step:2 // scroll 2 news each time
										});	
							
							} else if (hash=='news') {
								
								console.log('gotoScreen::scrollpane::'+hash);
								var sp = $('.'+hash+' .scrollpane').jScrollPane({ autoReinitialise: true, verticalGutter: 90 });

							} else {
								$('.'+hash).cycle({ 
									fx:'fade',
									timeout: 3000,
									speedIn: 500, 
    							speedOut: 500,
   								sync: 0
									//pause: true
				      	});
				      }
				      
			      } //visible 
					}							
					
				} // for
				
			} // else
			
		}
		
		
		// events
		
		// now handled by hashchange
		$('.goto').click(function() { 
		
			//var hash = $(this).attr('href').substring(1).toLowerCase();
			//gotoScreen(hash);
			
			//return false;  
		});
		
		
	});
	
})(jQuery);















