/**
 * @author dboz
 */
//home intro functions	
function showHomeIntro(){
    $('.homeIntro').slideDown(500, contentShow);
    // set cookie by number of days
    $.cookie('homeIntro', 'open', {
        path: '/',
        expires: 99
    });
}

function showHomeIntroFast(){
    $('.homeIntro').show(1, contentShow);
    $.cookie('homeIntro', 'open', {
        path: '/',
        expires: 99
    });
}

function contentShow(){
    $('.homeIntro .content').fadeIn(500, closeLinkOpen);
}

function closeLinkOpen(){
    $('.topWide .closeLink a').addClass('open');
}

function hideHomeIntro(){
    $('.homeIntro .content').fadeOut(500, slideUpHomeIntro);
    $('.topWide .closeLink a').removeClass('open');
    $.cookie('homeIntro', 'closed', {
        path: '/',
        expires: 99
    });
}

function slideUpHomeIntro(){
    $('.homeIntro').slideUp(500);
}




// various stuff to do when the page is ready
$(document).ready(function(){


	//sifr text replacement
	$.sifr({path:'swf'});
	$('h2.sectionTitle').sifr({font:'stratno1reg',textTransform: 'uppercase'} );
	//$('.news .post h3').sifr({font:'stratno1reg',textTransform: 'uppercase'} );
	//$('#navMain h3 a').sifr({font:'stratno1bol',textTransform: 'uppercase',zoomLeft: 2} );

	
	
    //***************************************************
    //poster animation	
    $('#posterAnim').innerfade({
        animationtype: 'slide', //Type of animation 'fade' or 'slide' (Default: 'fade'), 
        speed: 1,
        timeout: 5000,
        type: 'sequence',
        containerwidth: '',
        children: 'div'
    });
    
    
    $(function(){
    
        //awards thing 
        $('#awardsCarousel').show();
        if($('#awardsCarousel').length){
       		$('#awardsCarousel').jcarousel({start: 9,easing: 'swing',scroll: 3,visible: 4});
        }
        //modal dialogues
        $('div.alert').boxy();
        
        $('.homeIntro,.homeIntro .content').hide();
    });
    
    
    
    $('a').click(function(){
        this.blur();
    });
    $('a img').focus(function(){
        this.parent.blur();
    });
    
    $('li:odd').addClass('odd');
    
    
    
 
    
    $('.topWide').append('<div class="closeLink"><a href="#"><span></span></a></div>');
    
    if ($.cookie('homeIntro') == 'open' || $.cookie('homeIntro') == null) {
        showHomeIntroFast();
    }
    if ($.cookie('homeIntro') == 'closed') {
        hideHomeIntro();
    }
    
    $('.topWide .closeLink a').click(function(){
        if ($(this).hasClass('open')) {
            hideHomeIntro();
        }else {
            showHomeIntro();
        }
        this.blur();
        return false;
    });
    
    
    
    //gallery animation	
    $('#galleryAnim').innerfade({
        animationtype: 'slide', //Type of animation 'fade' or 'slide' (Default: 'fade'), 
        speed: 500,
        timeout: 5000,
        type: 'sequence',
        containerheight: '215px',
        containerwidth: '',
        children: 'a img'
    });
    
    //lightbox functions		
    // any link with rel=lightbox
    $('a[@rel*=lightbox]').lightBox({
        overlayBgColor: '#333'
    });
    
    
    //Event Listing views 
    $('a.listView').click(function(){
        $('.eventList').removeClass('detail');
        $('.eventList').addClass('list');
        $.cookie('calendarView', 'list', {
            path: '/'
        });
        if ($(this).hasClass('active')) {
            //do nothing
        }
        else {
            $(this).addClass('active');
            $('a.detailView').removeClass('active');
        }
        return false;
    });
    
    $('a.detailView').click(function(){
        $('.eventList').removeClass('list');
        $('.eventList').addClass('detail');
        $.cookie('calendarView', 'detail', {
            path: '/'
        });
        if ($(this).hasClass('active')) {
            //do nothing
        }
        else {
            $(this).addClass('active');
            $('a.listView').removeClass('active');
        }
        return false;
    });
    
    
    //***************************************************
    //Main NAV Collapsable
    
    $('#navMain .tickClosed,#navMain .tickOpen').click(function(){
        var sectionNode = $(this).attr("title");
        var sectionDiv = '#navMain #' + sectionNode;
        if ($(sectionDiv).hasClass('expanded')) {
            $(sectionDiv).removeClass('expanded'); //close subnav
        }
        else {
            $(sectionDiv).addClass('expanded'); //open subnav
        }
        return false;
    });
    
    //truncator
    $(function(){
        $('.contentBlock.truncate .cont').truncate({
            max_length: 325
        });
        $('.news.home .newsContent').truncate({
            max_length: 500
        });
    });
    
    //sidebar player button
    $('.sideBlock.audioPlayer .sideButton').append('<a href="#"><img src="images/sideAdListen.jpg" /></a>');
    $('.sideBlock.audioPlayer .close').append('<div class="playerClose" valuestyle="display:none;"><span><a href="#">Close Player</a></span></div>');
    $('.xxxsideBlock.audioPlayer .sideButton a').click(function(){
        $('.sideBlock.audioPlayer .sideButton').hide();
        $('.sideBlock.audioPlayer .player').show();
        $('.sideBlock.audioPlayer li.playerClose').show();
        $(this).blur();
        return false;
    });
	
    $('.sideBlock.audioPlayer .close .playerClose span a').click(function(){
        $('.sideBlock.audioPlayer .player').hide();
        $('.sideBlock.audioPlayer .sideButton').show();
        return false;
    });
    
    //sidebar ads - last style
    $('.sideBlock:last').addClass('last');
    
    //event list label just a css fix
    $('.eventList .label:first').css('margin-top', '-20px');
    
    //Event List More Button
    $('.eventList .moreLink a').click(function(){
        var eventNode = $(this).attr("title");
        var thisEventD = '.eventList #' + eventNode + ' .details';
        $(thisEventD).toggle();
        return false;
    });
    
    //Event List details close button
    $('.eventList .details .hideLink a').click(function(){
        var eventNode = $(this).attr("title");
        var thisEventD = '.eventList #' + eventNode + ' .details';
        $(thisEventD).hide(20);
        return false;
    });
    
    
    
    
    
    //***************************************************
    //form validation	
    
    var container = $('.cont .errors');
    
    $("#contactForm").validate({errorContainer: container, errorLabelContainer: $("ol", container),wrapper: 'li',meta: "validate"});
    
    
    //news alerts (if they close the alerts, a cookie will keep it closed for 1 day)
    
    $('.news.alerts .closeButton').append('<a href="#" class="closeLink"><img src="images/alertButtonClose.jpg" alt="CLOSE X" /></a>');
    if ($.cookie('alerts')) {
        $('.news.alerts').hide();
    }
    $('.news.alerts .closeButton a').click(function(){
        $('.news.alerts').hide();
        // set cookie by number of days
        $.cookie('alerts', 'closed', {
            path: '/',
            expires: 1
        });
    });
	
	
	//***************************************************
	//audio player links
	$('div.audioLink').each(function(i){
		$(this).click(function(){
			if(streampadPlayer.vars.isPlaying){
				streampadPlayer.Play.queueNumber(i);
			}else{
				streampadPlayer.UI.build();
				streampadPlayer.Play.queueNumber(i+1);
			}
			return false;
		});	
	});
	$('.sideBlock.audioPlayer .sideButton a').click(function(){
        if(streampadPlayer.vars.isPlaying){
				//streampadPlayer.Play.queueNumber(i);
		}else{
				streampadPlayer.UI.build();
				//streampadPlayer.Play.queueNumber(i+1);
		}
        $(this).blur();
        return false;
    });
	//if its the popup player, hide the awards cuz they were messing with it
	var winHash = window.location.hash;
	if (winHash.match("showplaylist")) {
		$('.awards').hide()
	};
	
	//if theres no mp3 links on the page, hide the player bar
	if(!$("a[href $='mp3']").length){
		$('#streampadBottomBar').hide();
		$('.sideBlock.audioPlayer').hide();
	}
	
	
	//truncate last fm bios
	$('.lastfmContent').truncate({max_length:'650'});
	



});


