// Black Fox iScroll

            var myScroll;
			var maxScrollCycles = 16;
			var scrollCounter = 0;
			var scrollPage = 0;
			var totalScrollPages;
			var autoScrolling;
			var linkEnabled = true;
			var hasTouch = 'ontouchstart' in window;
			

			
			 $(document).ready(function(){
					InitScroll();
             });
			 
			 function InitScroll()
			 {
				 
				   var scrCount = $("#iscroll .screenshots img").length;
				   var scrImgWidth = $("#iscroll .screenshots img").eq(0).width();
				   var scrImgHeight = $("#iscroll .screenshots img").eq(0).height();
				   var csrMarginSum = $("#iscroll .screenshots img").length *0;
				   
				    totalScrollPages = new Number(scrCount);
				   
				   $(".screenshots, #scroller").width(scrCount * scrImgWidth + csrMarginSum);
				   $(".screenshots").height(scrImgHeight + 5);
				   $("#scroller").height(scrImgHeight + 5);
				   
			   				   
					myScroll = new iScroll('iscroll', {
							snap: true,
							momentum: false,
							hScrollbar: true,
							vScrollbar: false,
							vScroll: false,
							hideScrollbar: true,
							lockDirection: true,
							onScrollStart: function () {
								setDescription();
								
							},
							onScrollMove: function () {
								linkEnabled = false;
							},
							onScrollEnd: function () {
								$('#indicator > li.active').removeClass("active");
								$('#indicator > li').eq(this.currPageX).addClass("active");
								
								linkEnabled = true;
							}
						 });
						 
						 //Indicator circles creation
						   for(i = 0; i < scrCount; i++)
						   {
								if($("#indicator li").size() < scrCount)
								{
									$("#indicator").append("<li>" + (i +1) + "</li>");
								}
						   }
						   $("#indicator li").removeClass("active");
						   $("#indicator li:first").addClass("active");
						   $("#indicator").width($('#indicator > li').size() * $('#indicator > li').eq(0).width() + 5);
								 
						   $("#indicator li").click(function(){
							     stopAutoScroll();
								 myScroll.scrollToPage((Number($(this).text()) - 1), 0, 400);
							});
							
							//Previous / Next buttons
							 $("#screenshots .slide-next").click(function(){
							     stopAutoScroll();
								 scrollPage++;
								 if(scrollPage >= totalScrollPages)
								 {
									scrollPage = 0;
								 }
								 myScroll.scrollToPage(scrollPage, 0, 400);
							});
							
							 $("#screenshots .slide-prev").click(function(){
							     stopAutoScroll();
								 scrollPage--;
								 if(scrollPage < 0)
								 {
									scrollPage = totalScrollPages-1;
								 }
								 myScroll.scrollToPage(scrollPage, 0, 400);
							});
							
							
							//Start autoscroll and set descriptions on desktops
							if(!hasTouch)
							{
								startAutoScroll();
								setDescription();
							}
							
							
							// Show description
							$("#screenshots").hover(
								function() {
									stopAutoScroll();
									$("#screenshots .descriptor").slideDown();
									$("#screenshots .slide-prev, #screenshots .slide-next").fadeIn();
								},
								function() {
									scrollCounter = 0;
									$("#screenshots .descriptor").slideUp('slow', function(){startAutoScroll()});
									$("#screenshots .slide-prev, #screenshots .slide-next").fadeOut();
								}
							);
														
							//Disable link while scrolling							
							$("#screenshots li a").click(function(){
								if(linkEnabled == false)
								{
									return false;
								}
							});
							
			 }
			 
			  function setDescription()
			  {
				  $("#screenshots .descriptor .title > a:first").text($(".iscroll a").eq(Number(scrollPage)).attr('rel'));
			  }
			 
			 function startAutoScroll()
			 {
				 clearInterval(autoScrolling);
				 
				 autoScrolling = setInterval(function () {
					  autoScroll();
				  }, 3000);
			 }
			 
			function stopAutoScroll()
			{
				 clearInterval(autoScrolling);
			}
			 
			 function autoScroll()
			 {
				 scrollPage++;
				 scrollCounter++
				 if(scrollPage > totalScrollPages)
				 {
				 	scrollPage = 0;
				 }
				 myScroll.scrollToPage(scrollPage, 0, 400);
				 
				 if(scrollCounter > maxScrollCycles)
				 {
					 stopAutoScroll();
				 }
			 }
