(function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);$.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=$.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=$.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this);

$(document).ready(function(){

/* fix to move content higher than space covered by minimized footer tabs + sidenav height fix*/
var content_h = $('#content_wrapper').height();
/*$('#sidenav').css('height', /*(content_h+75)+"px"'100%');
$('#content_wrapper').css('height', (content_h+75)+"px");*/


$.fv = {};
$.fv.currentState = 'up';
$.fv.visibleTab = 'info'; //or promo

$('#info_switch').click(function(){
if($.fv.currentState == "up" && $.fv.visibleTab == "info"){
footerControl('min', '/assets/images/infotab_down.png', 'infotab');
} else {
$.fv.visibleTab = 'info';
footerControl('max', '/assets/images/infotab_up.png', 'infotab');
}
});

$('#promo_switch').click(function(){
if($.fv.currentState == "up" && $.fv.visibleTab == "promo"){
footerControl('min', '/assets/images/promotab_down.png', 'promotab');
} else {
$.fv.visibleTab = 'promo';
footerControl('max', '/assets/images/promotab_up.png', 'promotab');
}
});

$('#info_toggle').click(function(){
if($.fv.currentState == "up" && $.fv.visibleTab == "info"){
footerControl('min', '/assets/images/show_infotab.png', 'infotab');
} else {
$.fv.visibleTab = 'info';
footerControl('max', '/assets/images/hide_infotab.png', 'infotab');
}
});

//footerControl
function footerControl(what, img, tab){

	var t = "#"+tab;
	var z = $(t).css('z-index');
		if(t == "promotab"){ 
		$(t).css('z-index', '1000');
		$('#infotab').css('z-index', '999');
		} else {
		$('#promotab').css('z-index', '999');
		$(t).css('z-index', '1000');
		}

	switch(what){
	case 'min':
	$('#tab_display').attr('src', img);
  	$('#footer').animate({"bottom": "-=205px"}, "fast", function(){	$('#footer_mask').css('height', '38px');});
	$.fv.currentState = 'down';
	break;
	case 'max':
	$('#tab_display').attr('src', img);
 	$('#footer').animate({"bottom": "0px"}, "fast");
	$('#footer_mask').css('height', '250px');
	$.fv.currentState = 'up';
	break;
	}
}



$('#nav > ul > li > ul').each(
function(){
$(this).hide(); 
});

$('#nav > ul > li > a').each(function(){
	 $(this).addClass('shadow navtext');
});

$('#nav > ul > li').each(function(){
var dd = $(this).find('ul');
$(this).hover(
		function(){ // display ul dd
		$('#nav > ul > li > ul').hide();
		$(this).css('cursor', 'pointer');
		var liLeft = $(this).find('a').position();
		$(dd).css('left', liLeft.left-18);
		$(dd).slideDown('fast');
		},
		
		function(){$(dd).hide(); }
		);
});

/* --------------------- SIDENAV ----------------------- */

function sidenav_init(what){
$(what).parent().find('a:first').after('<div class="subnav_arrow"><img src="/assets/images/sidebar_dd.png" /></div>');
$(what).parent().find('a:first').click(function(){ 
												$(what).parent().parent().find('ul').each(function(){
																						  $(this).hide('fast');
})

if($(what).is(':visible')){
 // nada
} else {
	$(what).toggle('fast');
}

});
}

$('#sidenav > ul > li').each(function(){
$(this).after('<img src="/assets/images/sidenav_separator.png" style="margin-left:-17px !important;"/>');
var topLevelLI = $(this);
$(topLevelLI).find('ul').each(function(){
sidenav_init($(this))
});
});

$('.current').parent().show();

/* ------------------------ MORE INFO ------------------- */

$('.moreinfo').each(function(){
	var hrf = $(this).attr('href');
	$(this).replaceWith('<a href="'+hrf+'"><img src="/assets/images/more_info.png" /></a>'); 
});

/* ------------------------ VIEW FLYER ------------------- */

$('.viewflyer').each(function(){
	var hrf = $(this).attr('href');
	$(this).replaceWith('<a href="'+hrf+'" rel="lightbox"><img src="/assets/images/view_flyer.png" /></a>'); 
});

/* ------------------------ GAME RULES ------------------- */

$('.gamerules').each(function(){
	var hrf = $(this).attr('href');
	$(this).replaceWith('<a href="'+hrf+'" rel="lightbox"><img src="/assets/images/game_rules.png" /></a>'); 
});

/* ------------------------ ARTIST INFO ------------------- */

$('.artistinfo').each(function(){
	var hrf = $(this).attr('href');
	$(this).replaceWith('<a href="'+hrf+'" target="_blank"><img src="/assets/images/artistinfo.png" /></a>'); 
});


$('#rotator_imgs').cycle();
/* --------------------- INTERNAL ROTATOR --------------- */
$('#internal_rotator_imgs').cycle();


//check if homepage
if($('#footer_controls').hasClass('home') == true){
	$.fv.visibleTab = 'info';
footerControl('min', '/assets/images/show_infotab.png', 'infotab');
} else {
footerControl('min', '/assets/images/infotab_down.png', 'infotab');
}


// header home button
$('#header_right').before('<div id="header_home"></div>');
$('#header_home').click(function(){
								 
								 window.location.href="/";
								 
								 });

//lightbox
$('a[rel*=lightbox]').lightBox();

// browser height init
	var bh = $(window).innerHeight();
	$('body').css('height', bh+'px');
	/*$('#content_wrapper').css('height', bh+'px !important');*/
	$('#footer').css('bottom', '0px');
	
// browser width init
	var bw = $(window).width();
	$('#infotab').css('width', bw+"px");
	$('#promotab').css('width', bw+"px");

$(window).resize(function(e){
	var bh = $(window).innerHeight();
	//$('body').css('height', bh+'px');
	/*$('#footer').css('bottom', '0px');*/
	var bw = $(window).width();
	$('#infotab').css('width', bw+"px");
	$('#promotab').css('width', bw+"px");
});


});

window.onload = function(){
	$('body').css("visibility","visible");
	$('#promo_rotator').show();

$('#promo_rotator').jcarousel({
scroll: 4, wrap: 'circular', auto: 6
});	

}
