$(window).load(function(){
$('#featured_wrapper, .box_body,.smm_bar_wrapper').hide();

introVidID = window.location.pathname.replace(/\//,'').replace('.php','');
urlHref = window.location.href;
urlHashBang = urlHref.substring(urlHref.indexOf('#!')).replace(/#!\//,'');

// loads table games reports feed via ajax after DOM loaded to avoid functionality conflict
$('.east_report').load('../reports/tables_live_reports.php .east_feed');
$('.poker_report').load('../reports/tables_live_reports.php .poker_feed');

// triggers split list function 
splitEntList();

// detects parents of select nested divs
whichWrapper = $('.menu_wrapper,.myaccount_menu_wrapper').parents(':eq(1)').attr('id');
whichPgClass = $('#'+whichWrapper+'').parent().attr('class');

// sets default footer position
tO = $('.'+whichPgClass+'').height()-100;
$('.footer_spacer').css('top',tO);

if(fadeInPage == true){
	if(introVideo == true){
	onloadVidFade();	
	slideInMenu();
	}else if(introVideo == false){
	onloadAnim();
	};
}else if(fadeInPage == false){
	if(introVideo == true){
	startIntroVideo();	
	}else if (introVideo == false){
	slideInMenu();
	}
};	

function startIntroVideo(){
	jwSetup();
};

$(document).keyup(function(e){
  	if (e.keyCode == 27 && introVideo == true) {closeIntroVideo();};
});

$('#intro_close_btn').bind('click',function(){
	closeIntroVideo();
	$(this).addClass('vidClsClick');
});

function jwSetup(){
	jwplayer('video_player_file').setup({
	file: 'images/managed/intro-'+introVidID+'-web.mp4',
	autostart: 'true',
	'controlbar': "none",
	height:480,
  	width:848,
	modes: [{type:'html5'},{type:'flash', src: 'jwplayer/player.swf'}],
	events: {
  	onComplete: function() {closeIntroVideo();}}
	});
};


function closeIntroVideo(){
	jwplayer().stop();
	if($('#intro_close_btn').hasClass('vidClsClick')){
	}else{
	$('.footer_spacer').animate({top: tO});
	$('.video_player_page').fadeOut();
	$('.'+whichPgClass+'').fadeIn();
	};
};

function onloadVidFade(){
	$('#header_wrapper,#nav_wrapper,.'+whichPgClass+', .video_player_page, #featured_wrapper, .footer, .offers_btn').hide();
	setTimeout(function(){$('#header_wrapper,#nav_wrapper').fadeIn(500)},500);
	setTimeout(function(){$('.box_body,#featured_wrapper,.smm_bar_contain,.smm_bar_wrapper,.footer, #footer_wrapper').fadeIn(500)},800);
	setTimeout(function(){$('.footer_spacer').animate({top: 680}); $('.video_player_page').fadeIn(600)},1500);
	setTimeout(function(){startIntroVideo();},2000);
};

	
function onloadAnim(){
	$('#header_wrapper,#nav_wrapper, .'+whichPgClass+',.video_page, .offers_btn, .reserve_btn').hide();
	setTimeout(function(){$('#header_wrapper,#nav_wrapper').fadeIn(500)},500);
	setTimeout(function(){$('.video_page,.box_body, #featured_wrapper,.smm_bar_contain, .smm_bar_wrapper, #footer_wrapper').fadeIn(500)},1200);
	setTimeout(function(){$('.'+whichPgClass+',.fixed_footer').fadeIn(600)},1500);
	setTimeout(function(){
		if($('.myaccount_page_box').is(":visible")){
	
		}else{
			slideInMenu();
			$('.reserve_btn, .offers_btn').fadeIn(600);
		};
	},1800);
};

/* checks for thick style menu header and indents the list items 
if($('li').hasClass('menu_header_thick')){
$('.menu_item').css('width', 460);
};*/

// determines the default position of the floating footer//
$('.item_container').children().hide();

if(urlHashBang == 'events'){
	itemId = "events";
	setTimeout(function(){
	sizeFade();
	$('#events a').css('color','#FFF');
	$('#events').addClass('clicked');
	},1500);
}else if(urlHashBang == 'poker_game_report'){
	itemId = "poker_game_report";
	setTimeout(function(){
	sizeFade();
	$('#poker a').css('color','#FFF');
	$('#poker').addClass('clicked');
	},1500);
}else if(urlHashBang == 'tournament'){
	itemId = "tournament";
	setTimeout(function(){
	sizeFade();
	$('#tournament a').css('color','#FFF');
	$('#tournament').addClass('clicked');
	},1500);
}else if(urlHashBang == 'pows'){
	itemId = "pows";
	setTimeout(function(){
	sizeFade();
	$('#pows a').css('color','#FFF');
	$('#pows').addClass('clicked');
	},1500);
}else if(urlHashBang == 'happyhour'){
	itemId = "happyhour";
	setTimeout(function(){
	sizeFade();
	$('#happyhour a').css('color','#FFF');
	$('#happyhour').addClass('clicked');
	},1500);
};


$('.menu_item').bind('click',function(){
	$('.slide_up_list>li>a').children([1]).animate({top:0});
	itemId = this.id;
	if($(this).hasClass('clicked')){}else{
	$('.menu_item').children([1]).css('color','#CCC');
	$('.menu_item').removeClass('clicked');
	if(itemId == 'social'){
	sizeFade();	
	}else{
	sizeFade();
	};
	$(this).children([1]).css('color','#FFF');
	$(this).addClass('clicked');
	};
});

// resizes right side content area based on user selection and fades it in //
function sizeFade(){
	itemHeight = $('#'+itemId+'_contain').height();
	newHeight = itemHeight - tO;
	finalHeight = tO+newHeight+170;
	$('.item_container').children().hide();
	if(!$('.footer_spacer').is(':animated')){
		if(itemHeight >= 350){
			$('#'+whichWrapper+'').css('height',finalHeight);
			$('.footer_spacer').animate({top:finalHeight},function(){$('#'+itemId+'_contain').stop().fadeTo(500,1).show();});
		}else {
			$('.footer_spacer').animate({top:tO},function(){$('#'+itemId+'_contain').stop().fadeTo(500,1).show();});
		};
	};
};

// fades out sections and displays default when menu header is clicked
$('.menu_header').bind('click',function(){
	$('.menu_item').removeClass('clicked');
	$('.item_container').children().fadeOut();
	$('.footer_spacer').animate({top:tO});
});

// slides in left side navigation menu //
function slideInMenu(){
	var winWidth = $(window).width() / 2;
	$('.menu_wrapper,.myaccount_menu_wrapper').css('margin-left', -310 - winWidth);
	$('.menu_wrapper,.myaccount_menu_wrapper').show();
	$('.menu_item,.myaccount_menu_item').hide();
	if($('.menu_wrapper>ul>li,.myaccount_menu_wrapper>ul>li').hasClass('menu_header_thick')){
	$('.menu_wrapper,.myaccount_menu_wrapper').animate({left: winWidth + 90},800, function(){fadeLI();});
	}else if(whichPgClass == 'news_page'){
	$('.menu_wrapper').hide();	
	}else if(whichPgClass == 'vendors_page'){
	$('.menu_wrapper').hide();	
	}else if(whichPgClass == 'sitemap_page'){
	$('.menu_wrapper').hide();	
	}else if(whichPgClass == 'joinxclub_page'){
	$('.menu_wrapper').hide();	
	}
	else{
	$('.menu_wrapper,.myaccount_menu_wrapper').animate({left: winWidth},800, function(){fadeLI();});
	};

function fadeLI(elem) { 
 $(".menu_item,.myaccount_menu_item").each(function(index) {
    $(this).delay(200*index).fadeIn(300);
});
};
};
	
// takes php entertaiment list and splits it evenly
function splitEntList(){
$('.events_list').hide();
//listLength = $('.events_list>li:lt(20)').size();
listLength = $('.events_list>li').size();
splitPoint = Math.ceil(listLength/2);
$('#events_contain').append($('<ul></ul>',{"class": "first_list"}),$('<ul></ul>',{"class": "second_list"}));
//$('.events_list>li:lt(20)').each(function(i, item) {
$('.events_list>li').each(function(i, item) {
	if(i < splitPoint){$('.first_list').append(item);}else{$('.second_list').append(item);};
});
};



});
