jQuery(function($){	
	$.supersized({
		slideshow : 0,
		transition: 0,
		slides 	:  	[
						{image : 'http://clients.pappasgroup.com/eventsdc/site/_images/_bg/home_bg.jpg', url:''}
					]
									
	});
	
});




var scrollwhat = 'html, body';
scrollpadding = 0;
var height = "";
var width = "";
var pos = "";
var slide;

var minH = "560";


function adjustHeight(docH){
	if(docH <= minH){
		$('.page').height(minH);
		$('.page').eq(2).height(minH-65);
	} else {
		$('.page').height(docH);
		$('.page').eq(2).height(docH-160);
	}
	$('#wrapper').height(($('.page').height()*3)+190);
	$('#footer').css({'top':($('#wrapper').height()+15)+'px'});
}



$(document).ready(function(){
	
	var docH = $(window).height();
	
	adjustHeight(docH);
	
	$(window).resize(function(){
		docH = $(window).height();
		adjustHeight(docH);
	});

	jwplayer('mediaspace').setup({
	    'flashplayer': '_js/jwplayer/player.swf',
	    'file': 'http://clients.pappasgroup.com/eventsdc/pg/_video/EVENTS_DC-SIZZLE-FINAL_480p_2.mp4',
	    'controlbar': 'bottom',
	    'image': 'http://clients.pappasgroup.com/eventsdc/pg/_images/_img/EVENTS-DC-POSTER.jpg',
	    'width': '620',
	    'height': '374'
	  });
	
	// get the length of the list before the carousel is rendered (which adds additional items)
	var controlLength = $('.list_carousel li').length;
	$('.list_carousel').jCarouselLite({
		visible: 1,
		speed:500,
		auto:false,
		btnNext:'#next1',
		btnPrev:'#prev1',
		btnGo:[
			'.control-1', '.control-2', '.control-3'
		],
		afterEnd: function(el) {
			// get index of list item that is currently shown on the screen
			// will always be the item on the screen after the animation is complete
			var index = $('.list_carousel li').index(el);
			
			// update tabs
			$('#pagination li').removeClass('cur-tab');
			$('#pagination li').eq(index-1).addClass('cur-tab');
			
			// if the index is equal the original length of the list plus one
			// it will be equal to the first element in the list (because it got cloned and moved to the end)
			if(index == controlLength+1){
				$('#pagination li').eq(0).addClass('cur-tab');
			}
			changeBg(index);
		}
	});
	
	$('#global-nav a, #logo a').click(function(event) {
		event.preventDefault();
		var target = $(this.hash);
		if(target.length && this.hash) {
			scrollToElement(target);
		}
		return false
	});
	
	// onload
	changeBg();
	
	// scroll event
	$(window).scroll(function(){
		changeBg()
	});
	
	
	// set up variables for images
	$(window).bind('load', function(){
	height = $('#supersized .activeslide img').height();
	width = $('#supersized .activeslide img').width();
	pos = $('#supersized .activeslide img').position();

	});
	
	// resize event
	$(window).resize(function(){
		height = $('#supersized .activeslide img').height();
		width = $('#supersized .activeslide img').width();
		pos = $('#supersized .activeslide img').position();
	});
	
	
});

function scrollToElement(el) {				
	$(scrollwhat).stop().animate(
		{ scrollTop: el.offset().top - scrollpadding }, 600);
}

////
	function changeBg(image){
		// get the height of #wrapper
		var h = $('.page').outerHeight()*$('.page').size();
		var y = $(window).scrollTop();
		
		if( y >= (h*0) && y < (h*.15) ){
			$('#global-nav li').removeClass('active');
			$('#nav-who').addClass('active');
			updateBg(1);
		
		} else if( y > (h*.20) && y < (h*.45) ){
			$('#global-nav li').removeClass('active');
			$('#nav-our').addClass('active');
			if(slide != 3 || slide != 4) updateBg(2);
		
		} else if( y > (h*.55)){
			$('#global-nav li').removeClass('active');
			$('#nav-get').addClass('active');
			updateBg(5);
		}
		if(image == 1 || image == 4){
			updateBg(2);
		}
		if(image == 2){
			updateBg(3);
		}
		if(image == 0 || image == 3){
			updateBg(4);
		}

	}
	
	function updateBg(slide){
		slide = slide;
		if(slide == 1){
			image = 'http://clients.pappasgroup.com/eventsdc/site/_images/_bg/home_bg.jpg';
		}
		if(slide == 2){
			image = 'http://clients.pappasgroup.com/eventsdc/site/_images/_bg/divisions_conventions_bg2.jpg';
		}
		if(slide == 3){
			image = 'http://clients.pappasgroup.com/eventsdc/site/_images/_bg/divisions_sports_ent_bg.jpg';
		}
		if(slide == 4){
			image = 'http://clients.pappasgroup.com/eventsdc/site/_images/_bg/divisions_events_bg.jpg'
		}
		if(slide == 5){
			image = 'http://clients.pappasgroup.com/eventsdc/site/_images/_bg/contact_bg.jpg'
		}
		
		if(slide != null && $('.activeslide img').attr('src') != image){
			//$('#supersized .activeslide img').attr('src', image);
			$('#supersized .activeslide').removeClass('activeslide').remove();
			$('#supersized').append('<a class="activeslide"><img src="'+image+'" style="height:'+height+'px; width:'+width+'px;top:'+pos.top+'px;left:'+pos.left+'px;" /></a>');
		}
	}

