// DO NOT REMOVE THE COMMENT BLOCK BELOW THIS LINE //
/*global addEventListener: false, blur: false, clearInterval: false, clearTimeout: false, close: false, closed: false, defaultStatus: false,  
document: false, event: false, focus: false, frames: false, getComputedStyle: false, history: false, Image: false, length: false, location: false,  
moveBy: false, moveTo: false, name: false, navigator: false, onblur: true, onerror: true, onfocus: true, onload: true, onresize: true,  
onunload: true, open: false, opener: false, Option: false, parent: false, print: false, resizeBy: false, resizeTo: false, screen: false,  
scroll: false, scrollBy: false, scrollTo: false, setInterval: false, setTimeout: false, status: false, top: false, XMLHttpRequest: false,  
hs: false, $: false, VideoJS: false, $f: false, window: false, iScroll: false, videoJSPlayers: false,  */
// DO NOT REMOVE THE COMMENT BLOCK ABOVE THIS LINE //

/**
* Site-specific configuration settings for Highslide JS
*/
hs.graphicsDir = '/img/highslide/';
hs.outlineType = 'rounded-white';
hs.captionEval = 'this.a.title';
hs.dimmingOpacity = 0.66;
hs.dimmingDuration = 250;
hs.align = 'center';
hs.showCredits = false;
hs.registerOverlay({
	html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
	position: 'top right',
	useOnHtml: true,
	fade: 2 // fading the semi-transparent overlay looks bad in IE
});

// gallery config object
var config1 = {
	slideshowGroup: 'group1',
	dimmingOpacity: 0.75,
	dimmingDuration: 25000,
	transitions: ['expand', 'crossfade']
};

function bindHighslide(){
	$('.highslide').each(function() {
		this.onclick = function() {
			return hs.expand(this, config1);
		};
	});
}

$(document).ready(function() {
	// open new window for ext links
	$("a").filter(function() {
		return this.hostname && this.hostname !== location.hostname;
	}).attr('target', '_blank');
	
	bindHighslide();
	
	var deviceAgent = navigator.userAgent.toLowerCase();
	if (!deviceAgent.match(/(iphone|ipod|ipad)/)) {
		$('#people #contentblock, #about #contentblock, #posts #contentblock, #cast_members #contentblock').wrapInner('<div class="scrollblock" />');
			//$('#people #contentblock, #about #contentblock, #posts #contentblock, #cast_members #contentblock, #other_characters.index .characters_list').wrapInner('<div class="scrollblock" />');
		$('div.scrollblock').jScrollPane({
			showArrows: true,
			horizontalGutter: 0,
			verticalGutter: 0,
			dragMaxHeight: 75, 
			dragMinHeight: 75, 
			scrollbarWidth: 25, 
			arrowButtonSpeed: 20, 
			animateTo: true
		});
		
		$('div.otherscrollblock').jScrollPane({
			showArrows: true,
			horizontalGutter: 0,
			verticalGutter: 0,
			dragMaxHeight: 75, 
			dragMinHeight: 75, 
			scrollbarWidth: 25, 
			arrowButtonSpeed: 20
		});
		
	};
	// fix the background on tall iphone pages
	if (deviceAgent.match(/(iphone|ipod)/)) {
		var contentblockheight;
		contentblockheight = $('#container').height();
		contentblockheight = parseInt(contentblockheight, 10);
		
		if (contentblockheight > 1100) {
			$('body').css('background-color','#000000');
		}
	}
	
	if ($('.notice').length) {
	    $('#ContactForm').hide();
	}
	
//	$('div.scrollblock').width('370px');
	
	$(".photographs").carousel({
		dispItems: 1, 
		animSpeed: 1000, 
		pagination:true, 
		paginationPosition:'outside', 
		blockType:"ul",
		addressIdentifier:'images'
	});
	
	$(".videos").carousel({
		dispItems: 1, 
		animSpeed: 1000, 
		pagination: true, 
		paginationPosition: 'outside', 
		blockType: "ul",
		addressIdentifier: 'images'
	});
	
	
	$('.videos .cover').css('top','3px').css('opacity','0');
	
	//Full Box Sliding (Hidden to Visible)
	$('.videos .video').hover(
		function() {
			if ($.support.rgba) {
				$(this).children('.cover').animate({opacity:1},{duration:360});
			} else {
				$(this).children('.slider').fadeTo(360, 0.35);//animate({opacity:1},{duration:360});
			}
			$(this).children('.text').fadeIn(400);
		}, 
		function() {
			if ($.support.rgba) {
				$(this).children('.cover').animate({opacity: 0},{duration:500});
			} else {
				$(this).children('.slider').fadeOut(200);//animate({opacity: 0},{duration:500});
			}
			$(this).children('.text').fadeOut(200);
		}
	);
	//hides pagination dots
	if ($("#photosets").length) {var n = $('.photoset').length;};
	if ($("#videos").length) {var n = $('.videoblock').length;};
	if (n == 1) {
		$('.center-wrap').css('visibility', 'hidden');
	}
	
	$('.pagination').show();
	//dropdown menu
	//$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	
	$(".dropdownbutton").click(function(event) {
		event.preventDefault();
		
		if ($('.navblock').is(":visible")) {
			$(".navblock").slideUp('fast');
			// $("#contentblock").fadeIn('fast');
		} else {
			$(".navblock").slideDown('slow', function() {
				// $('#other_characters .characters_list').wrapInner('<div class="otherscrollblock" />');
				// $('div.otherscrollblock').jScrollPane({
				// 	showArrows: true,
				// 	horizontalGutter: 0,
				// 	verticalGutter: 0,
				// 	dragMaxHeight: 75, 
				// 	dragMinHeight: 75, 
				// 	scrollbarWidth: 25, 
				// 	arrowButtonSpeed: 20
				// });
			});
			// $("#contentblock").fadeOut('slow');
			
			$('body').bind('click.dropDown', function(e){
				// e.preventDefault();
				
				if ($(e.target).parents('.navblock').length === 0 && !$(e.target).parent().is(".dropdownbutton")) {
					$(".navblock").slideUp('fast');
					$('body').unbind('click.dropDown');
				}
			});
		}
	});
	
	// hide/show the subnav on the main navigation block
	$("li.parentsub").hover(function () {
			$(this).children('.subnav').stop().css({'display': 'block', 'opacity': 0}).animate({opacity: 1}, 200);
		}, 
		function () {
			$(this).children('.subnav').stop().animate({opacity: 0}, 500, function(){
				$(this).hide();
			});
		}
	);
	//detecting internet explorer

	if ($.browser.msie && $.browser.version.substr(0,1) > 7) {	
		$('#contentblock').not('#posts #contentblock').not('#website-credits #contentblock').after('<div class="ie_content_bot"></div>');
		$('#posts .contentblock_foot').after('<div class="ie_content_bot"></div>');
	};

	// Check if map exists
	if ($('#map')) {
		if ($.support.rgba) {
			$('body').append('<div id="dimmer" />');
		}
		// Loop through each AREA in the imagemap
		$('#map area').each(function() {
			// Assigning an action to the mouseover event
			$(this).mouseover(function(e) {
				var character_id = $(this).attr('id').replace('area_', '');
				$('#'+character_id).show();
				// dim the background
				if ($.support.rgba) {
					$("#dimmer").stop().animate({
						"backgroundColor": "rgba(0, 0, 0, .5)"
					}, 500);
				}
			});
			
			// Assigning an action to the mouseout event
			$(this).mouseout(function(e) {
				var character_id = $(this).attr('id').replace('area_', '');
				$('#'+character_id).hide();
				// restore the background opacity
				if ($.support.rgba) {
					$("#dimmer").stop().animate({
						"backgroundColor": "rgba(0, 0, 0, 0.01)"
					}, 500);
				}
			});
			
			// Assigning an action to the click event
			// $(this).click(function(e) {
				// e.preventDefault();
				// var character_id = $(this).attr('id').replace('area_', '');
				// alert('You clicked ' + character_id);
			// });
		});
	}
	
	
	// $('a.season-switcher').bind('click', function(event) {
	// 		event.preventDefault();
	// 		$('a.season-switcher').removeClass('active');
	// 		$(this).addClass('active');
	// 		var targetElementSelectorString = $(this).attr('rel');
	// 		// if ($('.scrollblock').length > 0) {
	// 		// 	$('.scrollblock')[0].scrollTo('#' + targetElementSelectorString);
	// 		// } else {
	// 			$('.option').hide();
	// 			$('.' + targetElementSelectorString).fadeIn();
	// 		// }
	// 		return false;
	// 	}
	// );
});

function getAlpha(backgroundColor) {
	var rgba = backgroundColor.replace(/^(rgb|rgba)\(/,'').replace(/\)$/,'').replace(/\s/g,'').split(',');
	return rgba[3];
}

window.onload = function() {
	VideoJS.setupAllWhenReady();
};

hs.addSlideshow({
	slideshowGroup: 'group1',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: false,
	overlayOptions: {
		opacity: 0.6,
		position: 'middle left',
		hideOnMouseOut: true
	}
});




// detecting IE for pseudo selectors

//if (jQuery.browser.msie) {
// $("li").addClass("last");
//};

// Optional: a crossfade transition looks good with the slideshow
hs.transitions = ['expand', 'crossfade'];

hs.Expander.prototype.onAfterExpand = function() {
	$('.highslide-controls').parent().parent().css('width', '100%');
};
