/**
  * Define the base History Channel namespace
 **/
HC = {
};

$(document).ready(function(){
	
    //hover functionality for the main nav all shows drop down arrow
    //change the appearance of the tv shows arrow when hovering on the tv shows li item
    $("#tvShows a").hover(
        function () {
            $("#triggerShowsDrop").addClass("hoverReady");

        },function () {
            $("#triggerShowsDrop").removeClass("hoverReady");
        });

    //change the appearance of the tv shows arrow when hovering on the arrow itself
    $("#triggerShowsDrop").hover(
        function () {
            $(this).addClass("hoverOn");

        },function () {
            $(this).removeClass("hoverOn");
        });

        $("li#tvShows a").mouseleave(function () {
            $("#triggerShowsDrop").removeClass("hoverOn");
        });

    //trigger shows dropdown when clicking the tv shows arrow
    $("#triggerShowsDrop").click(function () {

        if ($("#showsDrop").hasClass("hidden")) {
        		$("#showsDrop").fadeIn(200);
            }
        $("li#tvShows").addClass("activeSub");
        $("#showSeriesDropdown").hide(100);
        return false;
    });

    //hide the shows drop down when the mouse leaves the dropdown area
    $("#showsDrop").mouseleave(function () {
        $(this).fadeOut(200);
        $(this).addClass("hidden");

        $("li#tvShows").removeClass("activeSub");
        	$("#showSeriesDropdown").show(100);
    });


    //reveal terms & conditions content on the newsletter page
    $("#nlTermsTrigger").click(function () {

      if ($("#termsConditionsFull").is(":hidden")) {

        $("#termsConditionsFull").slideDown("slow");
      } else {
        $("#termsConditionsFull").hide();
      }
    });

    //common reveal more
    $('.fullText').hide();
    
    $("a.showFullText").click(function () {


        $('.summaryText').removeClass('hidden');

        $(this).parent().addClass('hidden');

        $('div.fullText').hide();


        if(document.getElementById('aboutDayCopy')) {

            $("#aboutDayCopy").removeClass("setHeight");
        }

        $(this).parent().next($('div.fullText')).fadeIn(400);

    });
    //bio eventlist reveal more
    $("a.revealFullText").click(function () {

        $('.fullText').hide();
        $(this).parent().children(".fullText").fadeIn(400);

    });

	try
    {
        //initiate tabs
	    $("#tabs").tabs();
    }
    catch (e) { }

    //clear our specific inputs with specific copy
    //so we don't clear inputs once the user has entered their own copy
    $("#headerSearchInput,#promNewsSignupFName,#promNewsSignupEmail,#newsletterEmail,#newsletterFname").click(function () {

        if ($(this).val().match(/^[Ss]earch/)) { $(this).val(''); }

        if ($(this).val() == 'First Name') { $(this).val(''); }

        if ($(this).val() == 'E-mail') { $(this).val(''); }
    });

    try
    {
        // init jQModal redirect Lightbox
        $('#lightboxRedirect').jqm();
        $('#lightboxRedirect').jqmShow();
    }
    catch (e) { }

    try
    {
        // init jQModal info Lightbox
        // $('#lightboxInfo').jqm({trigger: 'a.infoLightbox'});
        // $('#lightboxInfo').jqm({trigger: 'a.infoLightbox'});
        
        $('#lightboxInfo').jqm({ajax:'@href',trigger:'a.infoLightbox'});
    }
    catch (e) { }

    try
    {
        if(document.getElementById('carousel')){
            // init homepage carousel
            HC.carousel.init("items","featureShow",3);
        }
    }
    catch (e) { }
	
	try
    {
        if(document.getElementById('carouselTopic')){
            // init homepage carousel
            HC.carousel.init("items","featureShow",7);
			jQuery('#carouselTopic ul').css('left', 0);
        }
    }
    catch (e) { }
	
    try
    {
        if(document.getElementById('content-scroll')){
            // init shows carousel
            HC.carousel.init("items","subpanel",4);
        }
    }
    catch (e) { }

	
	//Onload Hide Tootltip elements
	$("#mystickytooltip").hide();
	$('.infoHide').hide();
	$('.tlInfo').hide();
	
	
	//Video Thumnail - Video Information Tooltip
	jQuery("#utils li").mouseover(function(){
		var videolineLink = '#'+$(this).attr('id')+'-info';
		$(videolineLink).removeClass('videoTooltipMove');
	});
	jQuery("#utils li").mouseout(function(){
		var videolineLink = '#'+$(this).attr('id')+'-info';
		$(videolineLink).addClass('videoTooltipMove');
	});
	// end Video Information Tooltip
	
	
	
	//Timeline - Information Tooltip
	jQuery("#tlLinks li").mouseover(function(){
		var timelinelineLink = '#'+$(this).attr('id')+'-tlInfo';
		$(timelinelineLink).removeClass('tooltipMove');
		jQuery(timelinelineLink).mouseover(function(){
			$(this).parent().addClass('timelineSelected');
		})
	});
	jQuery("#tlLinks li").mouseout(function(){
		var timelinelineLink = '#'+$(this).attr('id')+'-tlInfo';
		$(timelinelineLink).addClass('tooltipMove');
		jQuery(timelinelineLink).mouseleave(function(){
			$(this).parent().removeClass('timelineSelected');
		})
	});
	// end Timeline Information Tooltip
	
	
	// Image Opacity - Hero and Video Thumbnails
	jQuery('#heroOverlayBG').css('opacity', 0.7);
	
	jQuery('#utils .thumbPlay').css('opacity', 0.8);
	
	// to set a disabled state for image links, if desired:
	jQuery('#utils .thumbOpacity').css('opacity', 1.0);
	
	// this adds hover to show image links at full opacity:
	jQuery('#utils a.thumbLink').hover(
        // hover state
       	function() {
			if ($.browser.msie && $.browser.version.substr(0,1)<7) {

			}else{
				jQuery(this).css('opacity', 0.7);
				jQuery('#utils a.thumbPlay').hover(function() {
					jQuery(this).css('opacity', 1.0);
				});
			}
		},
		// back to off
		function() {
			if ($.browser.msie && $.browser.version.substr(0,1)<7) {
			}else{
				jQuery(this).css('opacity', 1.0);
				jQuery('#utils .thumbPlay').css('opacity', 0.8);
			}
		}
	);
	//End - Hero & Video Thumbnail Opacity Buttons

	try {
	$('#container-1').tabs();
	}
	catch(err) 
	{
		//console.log("ww2 gallery bug ", err);		
	}
	// WW2 Image Gallery Initial Gallery Load
	$('.items div.subpanel:first').addClass('active');
	
	//Initial load of the WW2 gallery/lightbox to populate elements from the first thumbnail info 
	jQuery('.largePhoto').ready(function(){
		var lImage = $('.items .active a').attr('href');
		var lbImage = $('.items .active').find('em').html();
		var lCaption = $('.items .active .cPhotoCaption').html();
		var title = $('.items .active').find('strong').html();
		var description = $('.items .active').find('div').html();
		
		
				var img = new Image();
				var imgLoc = $('.largePhoto img').attr('src');
				img.src = imgLoc;
				$('.largePhoto').empty();
				$('.largePhoto').append("<p class='ceebox'><a href='"+lbImage+"' rel='lightbox' id='largePhotoEnlargeIcon' class='enlarge'>&#160;</a></p>");
				
				setTimeout(function(){ 
					//$('.largePhoto').append("<img alt='"+title+"' src='"+lImage+"' width='"+img.width+"' height='"+img.height+"'>");
					$('.largePhoto').append("<img alt='"+title+"' src='"+lImage+"' class='galImage'>");
				}, 1000 );
			
		
		$('.galleryInfo').empty();
		$('.galleryInfo').append("<h1>"+title+"</h1><p>"+description+"</p>");
	});
	
});

