
/* ----- scrollable.js ----- */
jq(function() {
		
	jq("#nav ul").tabs("#panes > div", {effect: 'fade', fadeOutSpeed: 400});

		//cache the ticker
		var ticker = jq("#ticker");
		  
		//wrap dt:dd pairs in divs
		ticker.children().filter("dt").each(function() {
		  
		  var dt = jq(this),
		    container = jq("<div>");
		  
		  dt.next().appendTo(container);
		  dt.prependTo(container);
		  
		  container.appendTo(ticker);
		});
				
		//hide the scrollbar
		ticker.css("overflow", "hidden");
		
		//animator function
		function animator(currentItem) {
		    
		  //work out new anim duration
		  var distance = currentItem.height();
			duration = (distance + parseInt(currentItem.css("marginTop"))) / 0.025;

		  //animate the first child of the ticker
		  currentItem.animate({ marginTop: -distance }, duration, "linear", function() {
		    
			//move current item to the bottom
			currentItem.appendTo(currentItem.parent()).css("marginTop", 0);

			//recurse
			animator(currentItem.parent().children(":first"));
		  }); 
		};
		
		//start the ticker
		animator(ticker.children(":first"));
				
		//set mouseenter
		ticker.mouseenter(function() {
		  
		  //stop current animation
		  ticker.children().stop();
		  
		});
		
		//set mouseleave
		ticker.mouseleave(function() {
		          
          //resume animation
		  animator(ticker.children(":first"));
		  
		});
	  });

 jq(document).ready(function() {
                //Set Default State of each portfolio piece
                jq(".paging").show();
                jq(".paging a:first").addClass("active");

                //Get size of images, how many there are, then determin the size of the image reel.
                var imageWidth = jq(".window").width();
                var imageSum = jq(".image_reel img").size();
                var imageReelWidth = imageWidth * imageSum;

                //Adjust the image reel to its new size
                jq(".image_reel").css({'width' : imageReelWidth});

                //Paging + Slider Function
                rotate = function(){
                    var triggerID = jqactive.attr("rel") - 1; //Get number of times to slide
                    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

                    jq(".paging a").removeClass('active'); //Remove all active class
                    jqactive.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

                    //Slider Animation
                    jq(".image_reel").animate({
                        left: -image_reelPosition
                    }, 500 );

                };

                //Rotation + Timing Event
                rotateSwitch = function(){
                    play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
                        jqactive = jq('.paging a.active').next();
                        if ( jqactive.length === 0) { //If paging reaches the end...
                            jqactive = jq('.paging a:first'); //go back to first
                        }
                        rotate(); //Trigger the paging and slider function
                    }, 7000); //Timer speed in milliseconds (3 seconds)
                };

                rotateSwitch(); //Run function on launch

                //On Hover
                jq(".image_reel a").hover(function() {
                    clearInterval(play); //Stop the rotation
                }, function() {
                    rotateSwitch(); //Resume rotation
                });

                //On Click
                jq(".paging a").click(function() {
                    jqactive = jq(this); //Activate the clicked paging
                    //Reset Timer
                    clearInterval(play); //Stop the rotation
                    rotate(); //Trigger rotation immediately
                    rotateSwitch(); // Resume rotation
                    return false; //Prevent browser jump to link anchor
                });
    });

jq(document).ready(function() {
        jq('#slider1').s3Slider({
            timeOut: 3000
        });
        jq('#slider2').s3Slider({
            timeOut: 3000
        });
        jq('#slider3').s3Slider({
            timeOut: 3000
        });
        jq('#slider4').s3Slider({
            timeOut: 3000
        });
        jq('#slider5').s3Slider({
            timeOut: 3000
        });
        jq('#slider6').s3Slider({
            timeOut: 3000
        });
        jq('#slider7').s3Slider({
            timeOut: 3000
        });
        jq('#slider8').s3Slider({
            timeOut: 3000
        });
 });


