$(document).ready(function(){	
	
	if ($("#hpi-btn")){
		
		sdegree = 45
		
		setInterval(function() {
            
			
			var srotate = "rotate(" + sdegree + "deg)";
			
			$("#imageWheel img").css({"-moz-transform" : srotate, "-webkit-transform" : srotate});
			
			sdegree = sdegree + 45 
			
			
        },4000);
  	
		setInterval(function() {
			
				$("#hpi-btn").css({"-moz-transform" : "rotate(25deg)", "-webkit-transform" : "rotate(25deg)"});
				
				window.setTimeout(function() {  
				    resetHpiBtn();
				}, 500);
				
			},4000);
			
			
		function resetHpiBtn(){
			$("#hpi-btn").css({"-moz-transform" : "rotate(-0deg)", "-webkit-transform" : "rotate(-0deg)"});	
		}
	}
		
	if ($(".email")){
			//var a2a_config	

			$(".null").remove();

			lbl = $("#footer a.email").text();
			
			$('.email').attr('href', 'mailto:' + lbl);
		}
	
	$('ul#nav li').hover(function () {
		
		$(this).children('ul').fadeIn("medium");
	},
		// on mouse out
		function () { $(this).children('ul').hide();});

		$('#hp-c-slides li').hide();

		//home page carousel slides
		$('#hp-c-nav ul li a').click(function(){
			
			clearInterval(play);
			
			$('#hp-c-nav ul li').removeClass('active');
			$(this).parent().addClass('active');
			$('#hp-c-slides li').removeClass('active');	

			var slideTrig = $(this).attr('data-rel');

			i = 0;

			$('#hp-c-slides li').each(function(){

				if (slideTrig == $(this).attr('id')) {

					$('#hp-c-slides li').hide();
					$(this).fadeIn('slow').addClass('active');

					if(i == 0){highlight1(i);}
					if(i == 1){highlight2(i);}
					if(i == 2){highlight3(i);}
				}

				i++
			});	
			return false
		});
				
		$('a#hp-c-next').click(function(){
			clearInterval(play);
			nextSlide();
			return false
		});
		
		$('a#hp-c-prev').click(function(){
			clearInterval(play);
			prevSlide();
			return false
		});
		
		function resetSlide(){
			
			//reset the animation position
			i = 0;
			highlight1(i);
			$('#hp-c-nav ul li').removeClass('active')
			$('#hp-c-nav ul li').first().addClass('active');
			$('#hp-c-slides li.active').hide().removeClass();
			$('#hp-c-slides li').first().fadeIn('slow').addClass('active');
			
		}
		
		
		function nextSlide(){
			
			if ($('#hp-c-nav ul li').last().hasClass('active')){ resetSlide(); }

			else {
				
				$('#hp-c-nav ul li.active').removeClass().next().addClass('active');
				$('#hp-c-slides li.active').fadeOut('slow').removeClass().next().fadeIn('slow').addClass('active');
				
				var slideTrig = $('#hp-c-nav ul li.active a').attr('data-rel');
				
				setActiveSlide(slideTrig);
			}
		}
		
		function prevSlide(){
			if ($('#hp-c-nav ul li').first().hasClass('active')){ return false }
			else {
			
				$('#hp-c-nav ul li.active').removeClass().prev().addClass('active');
				$('#hp-c-slides li.active').fadeOut('slow').removeClass().prev().fadeIn('slow').addClass('active');
				
				var slideTrig = $('#hp-c-nav ul li.active a').attr('data-rel');
				
				setActiveSlide(slideTrig);
			}
			
		}

		
		function setActiveSlide(slideTrig){
			i = 0;

			$('#hp-c-slides li').each(function(){

				if (slideTrig == $(this).attr('id')) {
					if(i == 0){highlight1(i)}
					if(i == 1){highlight2(i)}
					if(i == 2){highlight3(i)}
				}
				i++
			});
			
		}
		
	
		// highlighter animation anchor points
		function highlight1(i) {		
			$('#highlighter').animate({
				'left' : '-83%'
			}, {"duration" : "200", "easing": "easeOutCubic"});
			setActiveSlideInfo(i);	
		}
		
		function highlight2(i) {		
			$('#highlighter').animate({
				'left' : '-50%'
			}, {"duration" : "200", "easing": "easeOutCubic"});
			setActiveSlideInfo(i);

		}

		function highlight3(i) {		
			$('#highlighter').animate({
				'left' : '-17%'
			}, {"duration" : "200", "easing": "easeOutCubic"});
			setActiveSlideInfo(i);
		}
		
		function setActiveSlideInfo(i) {
			$('#hp-c-s-cols .col').removeClass('active');
			var count = 0
			$('#hp-c-s-cols .col').each(function(){
				if (i == count) {		
					$(this).addClass('active');
				}		
				count ++
			});
		}
		//END homepage carousel slides

		//next slide currently not required
		function nextSlideTitle(i){

			var nextSlide = $('#hp-c-s-cols .active').next().children('h2').text();

			if (i < 2){ $('#hp-c-title').text('Next: ' + nextSlide);}

			else {$('#hp-c-title').text('');}

		}
		
		function rotateImage(){
			play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
			    nextSlide();
				}, 6000); //Timer speed in milliseconds (7 seconds)
			}
		
		rotateImage()
		
		$('#hp-c-slides li, .cols3-even').hover(function() {
			
		  clearInterval(play);
		}, function() {
		  rotateImage();
		});
	
		
		
	
		if ($('#postTest').length) {
			$('.cat-item-3').addClass('current-cat');
		}
	
	
		/* This is basic - uses default settings */ 
		$("a.galleryImg").fancybox();

		$("a.test").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false });
	
		
		if ($("#fotobook-photo").length){
			//dont do anything on the navigation if were in the fotobook section
			$('#navMark, #navMarkGhost').hide();
		}
		
		else {
			//navigation marker position
			if ($('.home').length){
				$('#navMark, #navMarkGhost').css({'left' : -530});
			}
			else {
				var p = $('nav#mainNav ul li.current-cat, .current_page_item').position();
				var w = $('nav#mainNav ul li.current-cat, .current_page_item').width();
				$('#navMark, #navMarkGhost').css({'left' : p.left + w / 3 - 10});
			}
		
			var r = $('#navMarkGhost').position();
			
			function resetNav() {
				$('#navMarkGhost').animate({'opacity' : 0}, {duration : 300});
			
				//resetNav(r);
			}
			
			function marketsHov() {
				var p = $(this).position();
				var w = $(this).width();
			
				$('#navMarkGhost').css({'opacity' : 1}).animate({'left' : p.left + w / 3 -10}, {duration : 300, "easing" : "easeOutCubic"});
			}
			
			var marketConfig = {    
			     over: marketsHov, // function = onMouseOver callback (REQUIRED)    
			     timeout: 2000, // number = milliseconds delay before onMouseOut    
			     out: resetNav // function = onMouseOut callback (REQUIRED)    
			};

			

			$("nav#mainNav ul li" ).hoverIntent(marketConfig);
		}
		
		
				
});


