$(document).ready(function(){
	randomHannah();
	bindEvents();
});
function bindEvents(){
	$('div.scroller_info_bar')
		.find('a.next,a.prev')
			.addClass('disabled');
	$("#browsable").scrollable({size: 3}).navigator();
	
	//center scroller navi items
	var naviWidth = $('.navi').outerWidth();
	$('.navi_cont').css({'width' : naviWidth, 'margin' : '0px auto'});
	
	//homepage nav flash pause
	
	$('#pg_home .primary_nav li a').click(function(){
		//$('#homepage_lite').get(0).pauseTimer();
		$('#homepage_lite').parents('div.homepage_lite:first').html('');
	});
	
	// downloads -----------------------------------------
	// make divs links
	
	$('#big_links div.big_link').each(function(i){
		var linkPath = $(this).find('a').attr('href');									   
		$(this)
			.css({cursor:'pointer'})
			.bind({
				mouseenter: function(){$(this).addClass('hover')},
				mouseleave: function(){$(this).removeClass('hover')},
				click: function(){
					if($(this).data('active') == false) { return; }
					if( linkPath.match('.pdf') ) {
						window.open(linkPath);
						return
					} else {
						window.location = linkPath;	
					}
				}
			})
			.find('a').bind({
				mouseenter: function(){ $(this).parents('div.big_link:first').data('active',false);},
				mouseleave: function(){ $(this).parents('div.big_link:first').data('active',true);}
			});
	});
	
	// Competition -------------------------------------------- */
	$('div#answers li a').click(function(){
		$('input#answer').val($(this).find('span.chk').text());
		jQuery(this).parents('ul:first').find('a.active').not(jQuery(this)).removeClass('active');		
		jQuery(this).toggleClass('active');
	});
	
	// Characters -------------------------------------------- 
	if ($('#pg_characters').length){
		$('#pg_characters')
			.find('div.scroll_content')
			.jScrollPane({
				scrollbarWidth:17,
				dragMinHeight:31,
				dragMaxHeight:31
			})
			.end()
			.find('#ch_panels div.ch_panel').hide().first().show();
		
		$('#ch_test_btns a,#ch_panels div.ch_btn a,#welcome_back').click(
			function() {
				swapCharacter($(this).attr('class'));
				return false;
			}						   
		);
	}
	
	
	//leaving overlay ----------------------------------------- 
	
	$('a.leaving_ov').click(
		function(){
			// firefox remove any heavy flash
			
			if( getClient() == 'firefox' ) {
				$('#homepage_lite').parents('div.homepage_lite:first').html('');
			}
			
			lnk = this.href;
			$.colorbox({
				href:dotdotpath + 'include/leaving.jsp #leaving_ov',
				open: true,
				opacity: '.5',
				title: ' ',
				innerHeight: 205,
				scrolling: false,
				onComplete: function()
				{
					$('#continue_btn').attr('href',lnk);
					$('#ov_close').click(function(){
						if (getClient() == 'firefox') {location.reload(true);return;}
						$.colorbox.close();
						return false;
					});	
				}
			})
			return false;
		}
	);
	
}

function getMovie(movieName){
	return document.getElementById(movieName);
}

function swapCharacter(ch) {
	var getSwf = getMovie('video');
	items = $('#ch_panels');
	items.find('div.ch_panel').stop(true,true).slideUp("slow").end().find(('#'+ch)).stop(true,true).slideDown("slow");
	if (ch == "hannah_montana"){
		getSwf.gotoHannah();
		return false;
	}
	else if (ch == "miley_stewart"){
		getSwf.gotoMiley();
		return false;
	}
	else if (ch == "lola"){
		getSwf.gotoLola();
		return false;
	}
	else if (ch == "lilly"){
		getSwf.gotoLilly();
		return false;
	}
	else{}
}

function getClient() {
	if ( (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/iPod/i)) ) {
		return 'ios';
	}
	else if ( navigator.userAgent.match(/MSIE 7/i) ) {
		return 'IE7';
	}
	else if ( navigator.userAgent.match(/MSIE 8/i) ) {
		return 'IE8';
	}
	else if ( navigator.userAgent.match(/MSIE 6/i) ) {
		return 'IE6';
	}
	else if ( navigator.userAgent.match(/Mozilla/i) ) {
		return 'firefox';
	}
	else {
		return navigator.userAgent;
	}
}

function randomHannah(){
	var imgCount = 5;
	var rNum = Math.floor(Math.random()*imgCount) + 1;
	var hannah = jQuery('#hannah_bg');
	hannah.removeClass().addClass('hm0'+rNum);
}




