(function($){
	// I solemnly swear I'm up to no good...
	$(document).ready(function(){
		// Blinking Fields
		$('.blink').
		    focus(function() {
		        if(this.title==this.value) {
		            this.value = '';
		        }
		    }).
		    blur(function(){
		        if(this.value=='') {
		            this.value = this.title;
		        }
		    });
		    
		 $('#navigation > ul > li:last').addClass('last');
		 $('#navigation > ul > li > ul > li').each(function(){
		 	if ( $(this).find('ul').length != 0 ) {
		 		$(this).find('> a').addClass('dd');
		 	};
		 })

		// Navigation drop-down
		$('#navigation ul li').hover(function(){
			if ( $('body').hasClass('moviepage') && is_safari_mac() ) {
			//$(this).find('ul').eq(0).show();
			$(this).find('ul').eq(0).stop(true,true).slideDown();
			} else {
			$(this).find('ul').eq(0).stop(true,true).slideDown();
			};
		}, function(){
			if ( $('body').hasClass('moviepage') && is_safari_mac() ) {
			$(this).find('ul').eq(0).hide();
			} else {
			$(this).find('ul').eq(0).stop(true,true).slideUp();
			};
		});
		
		// Homepage jCarousel
		$('#slider .holder > ul').jcarousel({
			scroll: 1,
			visible: 1,
			buttonNextHTML: null,
			buttonPrevHTML: null,
			itemFirstInCallback: sliderCallback
		});
		
		$('a.back-to-top').click(function() {
			$('html').animate({scrollTop: 0},'slow');
			return false; 
		});

		// FAQ section tabbed content
		$('.movie-faq .nav li a').click(function(){
			$('.movie-faq .nav li').removeClass('active');
			$(this).parent().addClass('active');
			
			var url = $(this).attr('href');
			
			$('.movie-faq .tabbed-content .tab').css({
				visibility: 'hidden'
			});
			
			$(url).css({
				visibility: 'visible'
			});
			
			return false;
		});
		
		// FAQ section custom scroll
		$('.movie-faq .tabbed-content .container').each(function(){
			$(this).jScrollPane();
		});
		
		// Movie sidebar actions hover
		$('#movie .actions li.main').hover(function(){
			$(this).toggleClass('hover');
		});
		
		
	});

	function sliderCallback (carousel,item,idx,state) {
		$('#slider .thumbs a').bind('click', function() {
	        carousel.scroll($.jcarousel.intval($(this).parent().index() +1));
	        return false;
	    });
	    
	    $('#slider .thumbs li').removeClass('active');
		$('#slider .thumbs li').eq(idx-1).addClass('active');
		
		animatePointer();	
	}

	function animatePointer(){
		var itemOffset = $("#slider .thumbs li.active").position().top;
		var itemHeight = $("#slider .thumbs li.active").height();
		var pointerPos = Math.round(itemOffset + (itemHeight - 17)/2) - 1;
		$('#slider .thumbs .pointer').animate({
			top: pointerPos
		},{
			queue: false,
			duration: 300
		});
	}

	// performs a check for safari on Mac
	function is_safari_mac() {
	var userAgent = navigator.userAgent.toString().toLowerCase();
	if ((userAgent.indexOf('safari') != -1) && !(userAgent.indexOf('chrome') != -1) && navigator.platform.indexOf('Mac') != -1) {
	return true;
	}
	return false;
	}	
	
	
})(jQuery)
