﻿// Easing equation, borrowed from jQuery easing plugin
// http://gsgd.co.uk/sandbox/jquery/easing/
//#screen #sections img.scrollable:eq(1)
//$(document).ready(function(){alert($('#screen #sections img.scrollable').css('height'));})

var timer;
var  amou=0;
var pos=0;
var times=52200;
var ribbonArray=new Array();
var ProjectTitle;
var videofile=0;
var audiofile=0;
function createArray(){
	setLength=$(".scrollable").length;
	for(aw=0;aw<setLength;aw++){
			if($('.scrollable:eq('+aw+'):first h3').length >0){
				ribbonArray[aw]=new Object();
				ribbonArray[aw].Ptitle=$('.scrollable:eq('+aw+')>h3' ).html();
				ribbonArray[aw].width=$('.scrollable:eq('+aw+')').width();
				ribbonArray[aw].Plink='';
				ProjectTitle=ribbonArray[aw].Ptitle;
				
				}else{
					ribbonArray[aw]=new Object();
					ribbonArray[aw].Ptitle=$('.scrollable:eq('+aw+')').attr("alt");
					ribbonArray[aw].width=$('.scrollable:eq('+aw+')').width();
					ribbonArray[aw].Plink=$('.scrollable:eq('+aw+')').attr("id");
					}
				//hunt out video and sound file titles
				try{	
				ribbonArray[aw].Ptitle.length 
				}
				catch(e){
					
					
					//nothing
					
					
					
					
				}/* */
				
				
				
		}
	
	
	}

$('.scrollable:first').css({marginLeft:"140px"});

createArray();

$(document).ready(function(){

 $("div.scrollable p a").bind("click", function(){window.location=this.href;})
$('#sections').hide("fast");
//$('#ribNav').hide("fast");
$('#titleWork').html(ribbonArray[0].Ptitle);
$("#sectionsLoading").animate({opacity:0},500);

$('#sections').animate({opacity:1},500).show("fast");/**/

})


jQuery(function( $ ){
	/**
	 * Most jQuery.serialScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://flesler.demos.com/jquery/scrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.serialScroll.
	 */

	/**
	 * The plugin binds 6 events to the container to allow external manipulation.
	 * prev, next, goto, start, stop and notify
	 * You use them like this: $(your_container).trigger('next'), $(your_container).trigger('goto', [5]) (0-based index).
	 * If for some odd reason, the element already has any of these events bound, trigger it with the namespace.
	 */		
	
	/**
	 * IMPORTANT: this call to the plugin specifies ALL the settings (plus some of jQuery.ScrollTo)
	 * This is done so you can see them. You DON'T need to specify the commented ones.
	 * A 'target' is specified, that means that #screen is the context for target, prev, next and navigation.
	 */
	$('#screen').serialScroll({
		target:'#sections',
		items:'.scrollable', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		//prev:'a.prevLink', Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		//next:'a.nextLink', Selector to the 'next' button (absolute too)
		axis:'xy',// The default is 'y' scroll on both ways
		//navigation:'#navigation li a',
		offset:-131,//-97
		duration:times,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		
		
		//queue:false,// We scroll on both axes, scroll both at the same time.
		//event:'mousemove', On which event to react (click is the default, you probably won't need to specify it)
		stop:true, //Each click will stop any previous animations of the target. (false by default)
		//lock:false, // Ignore events if already animating (true by default)		
		start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )	
		force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)	
		//cycle:true,// Cycle endlessly ( constant velocity, true is the default )
		step:68, // How many items to scroll each time ( 1 is the default, no need to specify )
		jump:true, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
		//easing:'easeOutSine',
		//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
		//interval:800,  It's the number of milliseconds to automatically go to the next
		constant:true, // constant speed
		
		onBefore:function( e, elem, $pane, $items, pos ){
			/**
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //those arguments with a $ are jqueryfied, elem isn't.
			 
					
			//determine if ribbon item is wide or thin
			if(ribbonArray[pos].width<=299){
				 times=200;
				// alert('fast')
			}
			else{
				times=400;
				//alert('slow')
				}
			
			//Set Project Title
			$('#titleWork').html(ribbonArray[pos].Ptitle);
			if(pos == 0){
					amou=1; 
					//$('.nextLink').click();return false;
				}else{
			
			
			amou=pos+1;}
			if(ribbonArray[pos].Plink.length>0){
				//alert(ribbonArray[pos].Plink)
				tesst="#"+ribbonArray[pos].Plink;
				$(tesst).bind("mouseup", gotoLink)
			}
			$('#num').html(amou);
			
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		
		}
	});
	
	
});

function gotoLink(linker){
		//alert(ribbonArray[amou-1].Plink+" - "+amou+" - "+linker)
		if(ribbonArray[amou-1].Plink==linker){
			//alert("success")
			var windowObject = window.open(linker); 
		}
	}

function scrollAlt(){
		
		$('div#sections').scrollTo('.scrollable:eq('+amou+')',0,{easing:'none',offset:-131} ) /*'.scrollable:eq('+amou+')'*/
		/*amou=amou+1;*/
		if(amou < $('.scrollable').length){
			amou=amou+1;}
		else{
			amou=1;
		}
		//Set Project Title
			pos=amou;
			$('#titleWork').html(ribbonArray[amou].Ptitle);
			$('#num').html(amou);
	}
	
function scrollAltB(){
		$('div#sections').scrollTo('.scrollable:eq('+amou+')',0,{easing:'none',offset:-131} ) /*'.scrollable:eq('+amou+')'*/
		/*amou=amou+1;*/
		if(amou > 0){
			amou=amou-1;}
		else{
			amou=1;
		}
		//Set Project Title
			//pos=amou;
			$('#titleWork').html(ribbonArray[amou].Ptitle);
			$('#num').html(amou);
	}

var senseContinuePress;
 $(document).keydown(function (e) {
     // alert(e.which)
	   
	   // left arrow key 37 .prevLink
	   if(e.which == 37){
		   		//$('.prevLink').click();
				//scrollAltB()
				$('div#sections').trigger('prev');
		   }
	   // right arrow key 39 .nextLink
	   if(e.which == 39){
		   		//times=10;	
		   		//$('.nextLink').click();
				$('div#sections').trigger('next');
				//scrollAlt();
		   }
	   
    });


function ResetScroll(xx){
	//reset the scroller
	$('div#sections').trigger('goto', [xx])
	
	}




function righter(){
	
	timer = setTimeout("righter()", 300);
	asl=$('.scrollable:eq('+amou2+')').offset().left;
	
	$('div#sections').scrollTo('.scrollable:eq('+amou2+')',570,  {easing:null,offset:-131} ) /*'.scrollable:eq('+amou+')'*/
		/*amou=amou+1;*/
		if(amou2 < $('.scrollable').length){
			amou2=amou2+1;}
		else{
			amou2=1;
		}
		//Set Project Title
			$('#titleWork').html(ribbonArray[amou2].Ptitle);
			$('#num').html(amou2);
	}
	
function lefter(){
	
	timer = setTimeout("lefter()", 300);
	$('div#sections').scrollTo('.scrollable:eq('+amou2+')',270, {easing:null,offset:-131} ) /*'.scrollable:eq('+amou+')'*/
		/*amou=amou+1;*/
		if(amou2 > 1){
			amou2=amou2-1;}
		else{
			amou2=1;
		}
		//Set Project Title
			$('#titleWork').html(ribbonArray[amou2].Ptitle);
			$('#num').html(amou2);
	}
	
function righterStop(){
	clearInterval(timer);
	}

function showLinks(){
	$('#ribNav').show("fast");
	}

function startAuto(){
	
	//$('div#sections').trigger('goto', [ribbonArray.length-1]);
	
	$('div#sections').trigger('prev');
	timetillend=times*ribbonArray.length;
	//setTimeout("showLinks()",timetillend);
}

$("a.nextLink").bind("click", function(e){
      $('div#sections').trigger('prev');
    });

$("a.prevLink").bind("click", function(e){
      $('div#sections').trigger('next');
    });

//window.onload=function(){setTimeout("startAuto()", 1000);}

