var arrow_hovered = false;
jQuery(document).ready(function($){
	
	Cufon.replace('.quote-item H3, .quote-item P', {textShadow: '#000 3px 3px'});
	Cufon.set('fontFamily', 'Trajan Pro').replace('.contact-info H3,.gallery H3,.gallery-categories, .txt H3, '+
	'#player H3, .newsletter-box H3, .page-reviews H3, #footer .menu-footer H3, .menu-footer UL LI, .contact H4, '+
	'.sidebar H3, #footer .about H4, .about-ticket A, .about-phone .text-about, .buy-ticket SPAN, .home-header .phone, '+
	'.footer .phone P, .right-col-box H3, .single-page-title, .mediakit-article-info H3');
	
	Cufon.replace('.mediakit-articles-thumbs .mediakit-article-qv, .mediakit-articles-thumbs .mediakit-article-pdf, .mediakit-articles-thumbs .mediakit-radio-url',{hover: true});
	
	$('.mediakit-articles-thumbs .mediakit-article-qv, .mediakit-articles-thumbs .mediakit-article-pdf, .mediakit-articles-thumbs .mediakit-radio-url').append('<span class="icon"></span>'); // Add span after cufon to prevent error with cufon in IE
	
	Cufon.replace('.more-photos-link',{hover: true});
	
	jQuery('.featured-photos-box ul li a[rel="featured_photos"]').fancybox({
		'titleShow' : false
	});	
	
	// Mediakit
	jQuery('#mediakit-photos-thumbs a[rel="mediakit-photos"]').fancybox({
		'titleShow' : true
	});	
	
	// Mediakit Menu
	$('.mediakit-menu a').click(function(){
		var href = $(this).attr('href');
		var extension = href.substr( (href.lastIndexOf('.') +1) );
		if (extension == 'pdf') {
			$.fancybox({
				'type' : 'iframe',
				'width' : 800,
				'height' : 650,
				'href' : 'https://docs.google.com/viewer?url='+href+'&embedded=true',
				'titleShow' : true
			});
		} else {
			$.fancybox({
				'href' :href,
				'titleShow' : true
			});
		}
		/*$.fancybox({
			'type' : 'iframe',
			'href' : href,
			'titleShow' : true
		});	*/
		return false;
	});
	
	jQuery('#player-control').click(function(){
		if (jQuery('#player').hasClass('pause')) {
			AudioPlayer.open('audioplayer_1');
			jQuery('#player').removeClass('pause');
		} else {
			AudioPlayer.close('audioplayer_1');
			jQuery('#player').addClass('pause');
		}
		return false;
	});

	jQuery('.wpcf7-form .wpcf7-response-output').remove();
	jQuery('.wpcf7-form').submit(function(){
		jQuery(this).find('INPUT').each(function(){	
			if (jQuery(this).attr('value') == jQuery(this).parents('.bg-input').attr('title')) jQuery(this).attr('value', '');
		});
	});

	jQuery('.autohint').focus(function(){
		if (jQuery(this).attr('value') == jQuery(this).attr('title')) jQuery(this).attr('value', '');
	});
	jQuery('.autohint').blur(function(){
		if (jQuery(this).attr('value') == '') jQuery(this).attr('value', jQuery(this).attr('title'));
	});
	
	jQuery('.contact TEXTAREA').focus(function(){
		if ($(this).attr('value') == jQuery(this).parents('p').attr('title')) jQuery(this).attr('value', '');
	});
	jQuery('.contact TEXTAREA').blur(function(){
		if (jQuery(this).attr('value') == '') jQuery(this).attr('value', jQuery(this).parents('p').attr('title'));
	});
	
	jQuery('.contact INPUT').focus(function(){
		if (jQuery(this).attr('value') == jQuery(this).parents('.bg-input').attr('title')) jQuery(this).attr('value', '');
	});
	jQuery('.contact INPUT').blur(function(){
		if (jQuery(this).attr('value') == '') jQuery(this).attr('value', jQuery(this).parents('.bg-input').attr('title'));
	});
	
	if (jQuery('.newsletter-box').length) {
		var input_email = jQuery('.email-address','.newsletter-box');
		jQuery(input_email).attr('title', 'Enter email address').attr('value', 'Enter email address');
		input_autohint(input_email);
	}
	
	//init_gallery();
	
	/*  Menu  */
	/*if (jQuery('.menu ul li a').length) {
		jQuery('.menu ul li a').click(function(event){		
			var full_url = this.href;
			var parts = full_url.split("#");
			if (parts.length < 2) return true;
			event.preventDefault();
			var trgt = parts[1];
			var target_offset = jQuery("#"+trgt).offset();
			var target_top = target_offset.top;
			jQuery('html, body').animate({scrollTop:target_top}, 500);
		});
	}*/
	
	/* Category list*/
	/*jQuery('#content UL#cats-list LI A').click(function(){
		if (jQuery(this).parent().find('UL.children').length) {
			if (jQuery(this).parent().hasClass('show')){
				jQuery(this).parent().find('UL.children').slideUp(600);
				jQuery(this).parent().removeClass('show');
			} else {
				jQuery(this).parent().find('UL.children').slideDown(600);
				jQuery(this).parent().addClass('show');
			}
			return false;
		} else return true;
	});*/

	
	if (jQuery('.quote').length) {
		jQuery('.quote').cycle({
			fx: 'fade'
		});
	}
	
	/*jQuery('.promo-video').click(function(){
		jQuery('.promo-video .coming-soon').removeClass('hidden');
		return false;
	});*/
	jQuery('#promo-video-link,#promo-video-link2').click(function(){
		jQuery.fancybox({
			'padding'		: 0,
			//'content'		: 'coming soon',
			'title'   		: 'Intimate Illusions Promo Video',
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'overlayOpacity': 0.6,
			'overlayColor' 	: '#000',
			//'type'			: 'iframe',
			'width'			: 600,
			'content'		: '<div style="font-size: 0px;line-height: 0px;"><iframe src="http://player.vimeo.com/video/24964949?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff&amp;autoplay=1" width="601" height="338" frameborder="0"></iframe></div>'
			//'href'			: 'http://player.vimeo.com/video/24964949'
			//'src'			: 'http://player.vimeo.com/video/24964949'
		});
		return false;
	});
	
	jQuery('.photos-nav .gallery-categories a:first').click();
	
	jQuery('a[rel=external]').attr('target','_blank');
	
	// Media Kit Video
	if ($('#mediakit-video-thumbs').length) {
		$('#mediakit-video-thumbs a').click(function(){
			var li = $(this).parents('li:first');
			$('#mediakit-video-thumbs li').removeClass('active');
			$(li).addClass('active');
			var id = $(this).attr('href');
			//$('.mediakit-video-item').hide();
			$('.mediakit-video-item').addClass('videohidden');
			//$(id).show();
			$(id).removeClass('videohidden');
			return false;
		});
		
		$('.mediakit-video-nav #next').click(function(){
			var currentLi = $('#mediakit-video-thumbs li.active');
			var nextLi = $(currentLi).next();
			if (!$(nextLi).length) {
				var nextLi = $('#mediakit-video-thumbs li:first');
			}
			$('a',$(nextLi)).trigger('click');
			return false;
		});
		$('.mediakit-video-nav #prev').click(function(){
			var currentLi = $('#mediakit-video-thumbs li.active');
			var nextLi = $(currentLi).prev();
			if (!$(nextLi).length) {
				var nextLi = $('#mediakit-video-thumbs li:last');
			}
			$('a',$(nextLi)).trigger('click');
			return false;
		});
	}
	
	// Media Kit Quick View
	$('.mediakit-articles-thumbs .mediakit-article-qv').click(function(){
		if ($(this).hasClass('disable-fancybox')) return true;
		var id = $(this).attr('href');
		var content = $(id).html();
		$.fancybox({
			content: '<div class="quick-view-content">'+content+'</div>'
		});
		
		return false;
	});
});

function input_autohint(obj){
	obj.each(function(){
		jQuery(this).focus(function(){
			if (jQuery(this).attr('value') == jQuery(this).attr('title')) jQuery(this).attr('value', '');
		});
		jQuery(this).blur(function(){
			if (jQuery(this).attr('value') == '') jQuery(this).attr('value', jQuery(this).attr('title'));
		});
	});
}

function init_gallery(){
	jQuery('#scroller').removeClass('loading');
	if (!jQuery('#scroller').length) return;
	var width_li_gallery = 473;
	var pane = jQuery('#scroller').jScrollPane({
		showArrows: false,
		verticalArrowPositions: 'split',
		horizontalArrowPositions: 'split',
		animateScroll: true,
		horizontalDragMaxWidth: 58,
		horizontalDragMinWidth: 58
	});
	var api = pane.data('jsp');
	
	jQuery('.page-photos .left').unbind('click');
	jQuery('.page-photos .left').click(function(){
		var width = api.getContentWidth();
		var li_size = jQuery('#scroller li').length - 1;
		var current_pos = api.getContentPositionX();
		
		var t = parseInt(current_pos/width_li_gallery);
		current_pos = t*width_li_gallery;
		
		if (current_pos == width) current_pos -= width_li_gallery;
		var scroll_to = current_pos - width_li_gallery;
		
		if (!scroll_to || scroll_to < 0) scroll_to = 0;
		api.scrollToX(scroll_to);
		return false;
	});
	jQuery('.page-photos .right').unbind('click');
	jQuery('.page-photos .right').click(function(){		
		var width = api.getContentWidth();
		var li_size = jQuery('#scroller li').length;
		var current_pos = api.getContentPositionX();
		
		if (current_pos == 0) current_pos = 1;

		var t = parseInt(current_pos/width_li_gallery);
		
		current_pos = t*width_li_gallery;
		
		var scroll_to = current_pos + width_li_gallery;
		
		if (!scroll_to || scroll_to < 0) scroll_to = 0;
		api.scrollToX(scroll_to);
		return false;
	});

}

function disable_gallery_nav(selector){
	jQuery(selector).removeClass('disabled').addClass('disabled');
	Cufon.set('fontFamily', 'Trajan Pro').replace('.gallery H3,.gallery-categories');
}
function enable_gallery_nav(selector){
	jQuery(selector).removeClass('disabled');
	Cufon.set('fontFamily', 'Trajan Pro').replace('.gallery H3,.gallery-categories');
}

function preload_images(images_selector,function_callback) {
	var imgs = jQuery(images_selector);
	var countImgs = jQuery(imgs).length;
	var loadedImgs = 0;
	if (countImgs) {
		jQuery(imgs).each(function() {
			var src = jQuery(this).attr('src');
			if (src == '') {
				loadedImgs++;
				if (loadedImgs >= countImgs) function_callback();
			}
			var img = new Image();
			jQuery(img).load(function() {
				loadedImgs++;
				if (loadedImgs >= countImgs) function_callback();
			}).error(function () {
				loadedImgs++;
				if (loadedImgs >= countImgs) function_callback();
			}).attr('src', src);
		});
	}else
		function_callback();	
}

jQuery(window).focus(function() {
	if (typeof AudioPlayer != 'undefined') {
		AudioPlayer.open('audioplayer_1');
		jQuery('#player').removeClass('pause');	    
	}
});

jQuery(window).blur(function() {
	if (typeof AudioPlayer != 'undefined') {
		AudioPlayer.close('audioplayer_1');
		jQuery('#player').addClass('pause');
	}
});

