/* 
	Jquery Function for Sir Tom Baker
	Produced by Christian Nolle Enterprieses
	info@cnolle.net / www.cnolle.net
	Version: 1.0.3
	15.11.2010
*/


$(document).ready(function () {

	$('section .frame .column:nth-child(3n)').addClass('end-column');
	$('.coller:nth-child(3n)').addClass('end-column');

	$('#flash_box_link').fancyZoom();

	/* Fix bug in IE7 with a bit of Jquery, yay! */

	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});

/*
	$("header ul li a").hover(function () {
	    var sectionText = $(this).text();
	    var section = '#'+sectionText+'area'.toLowerCase();
	    alert(section);
	    $(section).addClass('hover');
	  },
	function () {
	    $(section).removeClass("hover");
		$(this).removeClass("hover");
	});
*/
	
	/* Activate sections on nav hover on the homepage */
	if ($("body").hasClass("home")) {
	
		$("header ul li a").hover(function () {
			
			/* String clean up */
		   var section = $(this).text().replace(/ /g,'');;
		   section = section.toLowerCase();
		   		   
			$('#surround').find('#'+section+'area a.blank').addClass('hello').fadeIn(1000);
			$('#surround').find('#'+section+'area h3').css('display','block');
			
		   //$('#surround').find('#'+section+'area a.blank').fadeIn(500).css('opacity', 0.5);
		  },
		function () {
		   $('#surround').find('a.blank').removeClass('hello');
	   	   $('#surround').find('h3').css('display','none');
		});
	
	}

/*
	$("#surround a").hover(function () {
		$(this).('h3').css('display','block');
	  },
	function () {
		$(this).('h3').css('display','none');
	});
*/	

	// Slider on the Process page

	$('#coda-slider-1').codaSlider({
		dynamicArrows: false,
		dynamicTabs: false
	});

	if ($("body").hasClass("page-id-8")) {

		$("a.indexsuits").click(function(){
			$("#suits").hide();
			$("ul#thumbnails").show();
			return false;
		}); 
		
		$("ul#thumbnails li a").click(function(){
			$('ul#thumbnails').hide();
			$('#suits').show();
			return false;	
		})
	
		// Slideshow for the Tailoring page

		$('ul#singlephotos').cycle({ 
			nowrap: 0,
			continuous: 0,
			fx: 'fade', // Effect
			speed: 300, // Duration
			sync:0,  	// White between image, not crossfade
			height: 'auto',
			timeout: 0,
			containerResize: 1,
			cleartypeNoBg: true,
			prev: 	'a.prev',
			next: 	'a.next,a.imgnext',
			after:	onAfter,
			pager:  'ul#thumbnails', 
			pagerAnchorBuilder: function(idx, slide) { 
				// return selector string for existing anchor 
				return 'ul#thumbnails li:eq(' + idx + ') a'; 
			} 
		});

	}
	
	// The Press page
	
	if ($("body").hasClass("page-id-13")) {
	
		$('ul#pressscans').cycle({ 
			nowrap: 0,
			continuous: 0,
			fx: 'fade', // Effect
			speed: 300, // Duration
			sync:0,  	// White between image, not crossfade
			height: 'auto',
			timeout: 0,
			cleartypeNoBg: true,
			prev: 	'a.prev',
			next: 	'a.next,a.imgnext',
			pager:  'ul#presslist', 
			pagerAnchorBuilder: function(idx, slide) { 
				// return selector string for existing anchor 
				return 'ul#presslist li:eq(' + idx + ') a'; 
			} 
			
		});
	
	}
	
	// Counter, not zero padded
	function onAfter(curr,next,opts) {
	//var caption = (opts.currSlide + 1) + '/' + opts.slideCount;

	var caption = (opts.currSlide + 1);

		//var caption = (opts.currSlide + 1) + ' / ' + opts.slideCount;
		$('#counter').html(caption);
		window.location.hash = opts.currSlide + 1;

	var index = opts.currSlide;

    	$('a.prev')[index == 0 ? 'hide' : 'show']();
	    $('a.next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
	}

	// Keyboard control for Cycle (left and right keys)
	$(window).keydown(function(e){
		if(e.which == 37){ 
			$('.prev').click();
		} else if(e.which == 39){
			$('.next').click();
		}
	});

});
