// JavaScript Document

jQuery(function(){
	
	jQuery('.postEntry a:has(img)').fancybox();
	jQuery('.fancybox').fancybox();
	
	jQuery(function() {
		jQuery("#menu ul.menu li").hover(function() {
			jQuery(this).find('ul.sub-menu').stop(true, true).slideDown(235, 'easeOutCubic');
		}, function(){
			jQuery(this).find('ul.sub-menu').stop(true, true).slideUp(125, 'easeInCubic');
		});
	});	

	// Google +1 Script
	(function() {
		var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
		po.src = 'https://apis.google.com/js/plusone.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
	})();
		
	jQuery('.mainScroller').anythingSlider({
		theme			: "hart",
		width           : 960,
		height			: 300,
		delay           : 8000,
		resumeDelay		: 8000,
		startPanel 		: 1,
		autoPlay        : isFrontPage,
		showNavArrows	: true,
		autoPlayLocked 	: false,
		titleShow		: true,
		resumeOnVideoEnd: true,
		pauseOnHover	: true,
		resizeContents	: false,
		easing          : "easeOutCubic",
		buildNavigation : true,
		enableStartStop : false,
		buildStartStop  : false
	});
	
	//Tooltips
	$('.helpLink').live('mouseenter',function () {
		$(this).children('.toolTip').show();
	});
	$('.helpLink').live('mouseout',function () {
		$(this).children('.toolTip').hide();
	});
	
	//Sharebar Hovers
	$('.shareBar div').live('mouseenter',function () {
		$(this).addClass('hover');
	});
	$('.shareBar div').live('mouseout',function () {
		$(this).removeClass('hover');
	});
	
	$('a').live('focus',function () {
		$(this).blur();
	});
		
});

jQuery('.trimodule .item').live('mouseenter', function() {
	jQuery(this).find('img').stop(true, true).animate({opacity: 0.85}, {duration: 235, queue: false});
	jQuery(this).find('.infobar').slideDown(235, 'easeOutCubic');
})
jQuery('.trimodule .item').live('mouseleave', function() {
	jQuery(this).find('img').stop(true, true).animate({opacity: 1}, {duration: 125, queue: false});
	jQuery(this).find('.infobar').stop(true, true).slideUp(125, 'easeInCubic');
});

function SetFilter(cat)
{
	var filterLink = $("#filter_"+cat);
	var filterCat = cat;
	if(filterLink!=null&&filterLink.length>0)
	{
		FilterPage(filterLink, filterCat);
		$(filterLink).addClass('current');
	}
}

function FilterPage(link, cat)
{
	var catname = $(link).html();
	$('.filterHldr a').removeClass('current');
	$('.filterDescriptions').hide('');
	
	if(cat!='')
	{
		$('.filterBoxHldr').fadeOut('300', function(){
			$("div.item").addClass('filtered');
			$("div."+cat).removeClass('filtered');
			$('.filterBoxHldr').fadeIn('300');
		});
                
		$('.postEntry').hide();
		$('#description_'+cat).show();
		$('.postTitle h2').html(pageTitle+' - '+catname);
                $(document).attr('title','Hart - '+pageTitle+' - '+catname);                
	}
	else
	{

		$('.filterBoxHldr').fadeOut('300', function(){
			$("div.item").removeClass('filtered');
			$('.filterBoxHldr').fadeIn('300');
		});
		
		$('.postEntry').show();
		$('.postTitle h2').html(pageTitle);
                $(document).attr('title','Hart - '+pageTitle);                
	}
	$(link).addClass("current");
}

var done = false;
var player;
var started = false;

function onYouTubePlayerAPIReady() {
    $(document).ready(function(){
		$("#player").click(function(){startYT();});
		//startYT();
	}
	);
}



function startYT()
{
    if (started) return;
    started = true;
    player = new YT.Player('player', {
      height: '300',
      width: '960',
      videoId: 'ZzN-DL-X6cc',
      playerVars: {'autohide': 1,
        'theme': 'dark',
        'wmode': 'transparent',
        'rel': 0,
        'modestbranding': 1,
		'autoplay': 1,
        'showinfo':0},//'theme=dark&autoplay=1&wmode=transparent&rel=0&autohide=1&modestbranding=1&showinfo=0',
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange
      }
    });
}

function onPlayerReady(evt) {
	$("#player").html("");
    evt.target.playVideo();
}
function onPlayerStateChange(evt) {
	player.setPlaybackQuality('hd720');
    if (evt.data == YT.PlayerState.PLAYING && !done) {
        setInterval("CheckTime();", 500);
        done = true;
    }
}
function CheckTime()
{
    if (player) {
	if (player.getCurrentTime() > 77)
		player.pauseVideo();
	}
}
