/* image reels */

	
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

/* 
var reelBtnOver = function (a, dir) {
	if (dir == 'prev') {
		var dir = 'prev';
	}
	var prevBtn = '#portfolioThumbs'+a+' a.prev';
	var nextBtn = '#portfolioThumbs'+a+' a.next';
}

var reelBtnOut = function (a, dir) {
	var prevBtn = '#portfolioThumbs'+a+' a.prev';
	var nextBtn = '#portfolioThumbs'+a+' a.next';
}


('portfolioThumbs'+a+' a.prev').mouseover(function () { reelBtnOver (a); }));
			('portfolioThumbs'+a+' a.next').mouseover(function () { reelBtnOver (a); }));
			('portfolioThumbs'+a+' a.prev').mouseout(function () { reelBtnOut (a); }));
			('portfolioThumbs'+a+' a.next').mouseout(function () { reelBtnOut (a); }));
			
			
*/

function initVReel (indxVReel) {
	jQuery(function( $ ){
		for (a=0; a<=indxVReel; a++) {
			$('ul#thumbList'+a).serialScroll({
				items:'li',
				prev:'#portfolioThumbs'+a+' a.prev',
				next:'#portfolioThumbs'+a+' a.next',
				axis: 'y',
				offset:0, 
				start:0,
				duration:700,
				force:true,
				stop:true,
				lock:false,
				cycle:false,
				easing:'easeOutQuart', 
				jump: false
			});	
		};	
	});
};


function initHReel (indxHReel) {
	jQuery(function( $ ){
		for (a=0; a<=indxHReel; a++) {
			$('#imageScroller'+a).serialScroll({
				items:'li',
				prev:'#portfolioThumbs'+a+' a.prev',
				next:'#portfolioThumbs'+a+' a.next',
				axis: 'x',
				navigation:'#imagePager'+a+' li a',
				offset:0, 
				start:0,
				duration:700,
				force:true,
				stop:true,
				lock:false,
				cycle:false,
				easing:'easeOutQuart', 
				jump: false
			});
		};	
	});
};



/* sitemap functions */

var sitemapStat;
var sitemapShowHeight;
var sitemapHideHeight;

var stafStat;
var stafShowHeight;
var stafHideHeight;


var coverOff;
var coverOn;

function initSitemap () {
	$("#sitemap").css('display','block');
	if (!sitemapStat) {
		sitemapStat = null;
	}
	
	sitemapShowHeight = $("#sitemapContent").height();
	sitemapHideHeight = 6;
	if ( sitemapStat == null && stafStat == null ) {
		$("#sitemapContent").height(sitemapHideHeight);
		$("#fadeCover").hide();
		$("#fadeCover").fadeTo("0", coverOff);
	} else if (sitemapStat && !stafStat) {
		$("#sitemapContent").height(sitemapShowHeight);
		$("#fadeCover").show();
		$("#fadeCover").fadeTo("0", coverOn);
	} else {
		$("#sitemapContent").height(sitemapShowHeight);
	};	
};

function initStaf () {
	$("#staf").css('display','block');
	if (!stafStat) {
		stafStat = null;
	}
	stafShowHeight = $("#stafContent").height();
	stafHideHeight = 6;
	if ( stafStat == null ) {
		$("#stafContent").height(stafHideHeight);
		$("#fadeCover").hide();
		$("#fadeCover").fadeTo("0", coverOff);
	} else {
		$("#stafContent").height(stafShowHeight);
		$("#fadeCover").show();
		$("#fadeCover").fadeTo("0", coverOn);
	};	
};

function initCover () { 
	coverOff = 0;
	coverOn = 0.9;
};

function toggleSitemap () {
	if (sitemapStat == null) {
		$("#sitemapContent").animate({"height": sitemapShowHeight}, "1000" );
		$("#fadeCover").show();
		$('#staf').css('zIndex', 998);
		$('#fadeCover').css('zIndex', 999);
		$('#sitemap').css('zIndex', 1000);
		$("#fadeCover").fadeTo("1000", coverOn);
		sitemapStat = 1;
	} else {
		$("#sitemapContent").animate({"height": sitemapHideHeight}, "1000" );
		$("#fadeCover").fadeTo("1000", coverOff, function () { $("#fadeCover").hide();});
		sitemapStat = null;
	};
};

function toggleStaf () {
	if (stafStat == null) {
		$("#stafContent").animate({"height": stafShowHeight}, "1000" );
		$("#fadeCover").show();
		$('#sitemap').css('zIndex', 998);
		$('#fadeCover').css('zIndex', 999);
		$('#staf').css('zIndex', 1000);
		$("#fadeCover").fadeTo("1000", coverOn);
		stafStat = 1;
	} else {
		$("#stafContent").animate({"height": sitemapHideHeight}, "1000" );
		$("#fadeCover").fadeTo("1000", coverOff, function () { $("#fadeCover").hide();});
		stafStat = null;
	};
};

function toggleCover () {
	if (sitemapStat) {
		toggleSitemap ();
	};
	if (stafStat) {
		toggleStaf ();
	};
};

function initPanels () {
	initCover ();
	initSitemap ();
	initStaf ();
}

function fixMacOpacity () {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    var yourShade = document.getElementById("fadeCover");
    yourShade.style.backgroundImage="url(/images/common/fadeCover.png)";
    yourShade.style.backgroundRepeat="repeat";
  };
};



function main_view_setup() {
	//Show the paging and activate its first link
	$(".paging").show();
	$(".paging a:first").addClass("active");
	
	//Get size of the image, how many images there are, then determin the size of the image reel.
	var imageHeight = $(".window").height();
	var imageSum = $(".image_reel img").size();
	var imageReelHeight = imageHeight * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'height' : imageReelHeight});
	
	//Paging  and Slider Function
	rotate = function(){
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageHeight; //Determines the distance the image reel needs to slide

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

		//Slider Animation
		$(".image_reel").animate({
				top: -image_reelPosition
		}, 400
		);
	
	}; 
	
	//Rotation  and Timing Event
	rotateSwitch = function(){
		play = setInterval(function(){ //Set timer - this will repeat itself every 4 seconds
			$active = $('.paging a.active').next(); //Move to the next paging
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 6000); //Timer speed in milliseconds (4 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation timer
	});	
	
	//On Click
	$(".paging a").click(function() {
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation timer
		return false; //Prevent browser jump to link anchor
	});
}

