/*
 * @version 1.0
 */

$(document).ready(function(){
						   
	// Get current year
	now = new Date;
	theYear = now.getYear();
	if (theYear < 1900)	theYear = theYear+1900;
	$('#currentYear').html(theYear);
	
	
	//	Replace font
	Cufon.replace('h2, .font');
	
	
	// Reset textarea
	/*$('textarea').each(function(){
		var defaulValue = $(this).html();
		$(this).focus(function(){
			if ($(this).html() == defaulValue) $(this).html('');
		})
	});*/
	$('textarea').live('focus', function(){
		var defaulValue = $(this).html();
		if ($(this).html() == defaulValue) $(this).html('');
	});
	
	
	// Navigation
	$('.nav a').not('.active').hover(
		/*function(){
			$(this).find('img').stop(true, true).animate({ height:"31px"}, 300);
		},
		function(){
			$(this).find('img').stop(true, true).animate({ height:"0"}, 300);
		}*/
		function(){
			$(this).stop(true, true).animate({ backgroundPosition:"(50% 100%)"}, 200);
		},
		function(){
			$(this).stop(true, true).animate({ backgroundPosition:"(50% 0%)"}, 200);
		}
	);
	
	
	// Sub navigation
	jQuery('ul#nav > li').hover(function() {
		jQuery('ul:first', this).stop(true,true).slideDown(150);
	},
	function() {
		jQuery('ul:first', this).stop(true,true).slideUp(150);
		//jQuery('ul#nav ul').stop(true,true).hide();
	});

	
	
	// Tooltip
	$.easing.bouncy = function (x, t, b, c, d) {
		var s = 1.70158;
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	}	
	$.tools.tooltip.addEffect("bouncy",
		function(done) {
			this.getTip().animate({top: '+=10', opacity: '0.8'}, 500, 'bouncy', done).show();
		},
		function(done) {
			this.getTip().animate({top: '+=10', opacity: '0'}, 500, 'bouncy', function()  {																			   				$(this).hide();
				done.call();
			});
		}
	);
	$(".top10 a").not('.remove').tooltip({effect: 'bouncy'});
	
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	//	Home
	//////////////////////////////////////////////////////////////////////////////////////////////////////////	
	
	// setup horizontal scrollbar
	var totalHotNews = $('#hotNews li').length;
	$('#hotNews ul').width(totalHotNews*218);
	$('#hotNews').jScrollHorizontalPane({scrollbarHeight:29, showArrows:false, arrowSize:15, wheelSpeed:0, resize: false, maintainPosition: false, reset: false});
	/*$('.hotnews').hover( function(){
		document.onmousewheel=doNothing;
		function doNothing(){ return false; }
	});*/
	
	
	// Set active stage tab
	$('.bbox-tabLabel a').click(function(){
		$(this).parent().find('.active').removeClass('active');
		$(this).addClass('active');
	});
	
		
	// Comments section
	moment_cm();	
	psmoment_cm();
	hotstar_cm();
	
	$('.cm_postForm').click(
		function(){
			$(this).parent().animate({ marginLeft: '260px'}, 200, function(){
				$(this).next().fadeIn();
			})
		}
	);
	$('.cm_closeForm').click(
		function(){	
			if (closeComment) clearTimeout(closeComment);
			$(this).parent().parent().fadeOut(200, function(){
				$(this).prev().animate({ marginLeft: '0'}, 200 );
			})
		}
	);	
	
	
	// Judge and Contestants: other slide box
	var totalSlideItem	= $('.slideCover ul').find('li').length;
	var maxRight		= (totalSlideItem-5)*126;
	
	if (totalSlideItem>5){
		$('.slideCover ul').css('width',totalSlideItem*126).addClass('original').clone().prependTo('.slideCover').attr('class','clone').css({ left: '-'+totalSlideItem*126+'px'});
	}
	else{
		$('#judget_right, #judget_left').hide();
	}
	
	$('#judget_right').click(function(){
		$('.slideCover ul').stop(true, true).animate({ left:'-=126'}, 300, function(){
			if ($('.slideCover ul.clone').css('left') == "-"+maxRight+"px") $('.slideCover ul.original').css({ left: '630px'});
			if ($('.slideCover ul.original').css('left') == "-"+maxRight+"px") $('.slideCover ul.clone').css({ left: '630px'});																		
		});
		return false;
	})
	$('#judget_left').click(function(){
		$('.slideCover ul').stop(true, true).animate({ left:'+=126'}, 300, function(){
			if ($('.slideCover ul.clone').css('left') == "0px") $('.slideCover ul.original').css({ left: '-'+totalSlideItem*126+'px'});
			if ($('.slideCover ul.original').css('left') == "0px") $('.slideCover ul.clone').css({ left: '-'+totalSlideItem*126+'px'});
		});		
		return false;
	})
	
	
	// Contestan and Judge other 
	$('.otherContestant li').hover(
		function(){
			$(this).find('span').stop(true, true).animate({ bottom: '0px'}, 150);
		},
		function(){
			$(this).find('span').stop(true, true).animate({ bottom: '-23px'}, 150);
		}
	);
	
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	//	Photo
	//////////////////////////////////////////////////////////////////////////////////////////////////////////	
	$('.main-photoList').masonry({ columnWidth: 205, itemSelector: 'li:visible' });
	
	$('.hBtnTab a').click(function(){
		$(this).parent().find('.active').removeClass('active');
		$(this).addClass('active');
	});
	
	$('.comments .replyForm').live("click", function(){
		$(this).parent().find('.commentForm').show().find('input:first').focus();
		return false;
	});
	
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	//	Video
	//////////////////////////////////////////////////////////////////////////////////////////////////////////	
	var numImagesLoad=5;
	var speedScroll=1000;
	var numPageIndex=1;
	var numItems=$('.slideItem').length;
		if (numItems<6) $('.slide_btnLeft, .slide_btnRight').hide();
	var numImgBlockWidth=$('.slideItem').width();
	var numImgBlockHeight=$('.slideItem').height();
	for(var i=0;i<numItems;i++) $('.slideItem:eq('+i+')').css("left",(i*(Number(numImgBlockWidth)+5)));
	$('#productImg_gal').width(Number(numImagesLoad * numImgBlockWidth)+4);
	$('#productImg_gal').height(numImgBlockHeight);
	
	$(".slide_btnRight").click(function(){								 
		if(numPageIndex<(numItems/numImagesLoad)){
			$('.slide_btnLeft').show();
			$(".slideItem").animate({left:'-='+(Number(numImgBlockWidth)+5)*numImagesLoad+'px'}, speedScroll, 'easeOutQuart');
			numPageIndex++;
			if (numPageIndex>=numItems/numImagesLoad) $('.slide_btnRight').hide();
		}
		return false;
	});
	$(".slide_btnLeft").click(function(){
		if(numPageIndex>1){
			$('.slide_btnRight').show();
			$(".slideItem").animate({left:'+='+(Number(numImgBlockWidth)+5)*numImagesLoad+'px'}, speedScroll, 'easeOutQuart');
			numPageIndex--;
			if (numPageIndex==1) $('.slide_btnLeft').hide();
		}
		return false;
	});
	
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	//	Buzz
	//////////////////////////////////////////////////////////////////////////////////////////////////////////		
	if ($('.buzzCover').html() != null){
		
		$('.buzzItem').each(function(i){
			var buzzItem_meta 	= $(this).attr('title');
			var buzzItem_x		= Number(buzzItem_meta.substring(0,1));
			var buzzItem_y		= Number(buzzItem_meta.substring(1,2));
			var buzzItem_w		= Number(buzzItem_meta.substring(2,3));
			var buzzItem_h		= Number(buzzItem_meta.substring(3,4));
			$(this).css({
				left	: buzzItem_x * buzzItem_size,
				top		: buzzItem_y * buzzItem_size,
				width	: buzzItem_w * buzzItem_size,
				height	: buzzItem_h * buzzItem_size
			});	
			
			$(this).find('a').css({
				width	: buzzItem_w * buzzItem_size,
				height	: buzzItem_h * buzzItem_size
			});	
			
			
			$(this).before('<div class="buzzItemFake"></div>').prev().css({
				left	: buzzItem_x * buzzItem_size,
				top		: buzzItem_y * buzzItem_size,
				width	: buzzItem_w * buzzItem_size,
				height	: buzzItem_h * buzzItem_size
			});
				
			for (i=0; i< Number(buzzItem_w*buzzItem_h); i++){
				$(this).prev().append('<div class="buzzFake"></div>');
			}
			
			
			$(this).find('a').append('<div class="buzzFlash"></div>');		
			$(this).find('.buzzFlash').css({
				width	: buzzItem_w * buzzItem_size,
				height	: buzzItem_h * buzzItem_size
			})
			
			var imgMoveLeft = Number($(this).find('img').attr('width')) / 2;
			var imgMoveTop 	= Number($(this).find('img').attr('height')) / 2;
			if ($.browser.msie){
				$(this).find('img').css({ position:'absolute', left:'0', top:'0' });
			}
			else{
				$(this).find('img').css({ position:'absolute', left:'50%', top:'50%', marginLeft: -imgMoveLeft, marginTop: -imgMoveTop });
			}
		
			
			//$(this).attr('title', $('.buzzItem-title').text());
			$(this).attr('title', '');
			if (buzzItem_w==1) $(this).find('.buzzItem-title').remove();
		});
			
		/*for (i=0; i<72; i++){
			$('.buzzCover').append('<div class="buzzFake"></div>');
		}*/
				
		buzzInit(0);
		buzzRandom();
		
		 $(".buzzItem").hover(
			function(){
				$(this).find('.buzzItem-title').animate({ bottom:'0px'}, 150)
				$(this).find('.buzzFlash').show().fadeOut(700);
			},
			function(){
				$(this).find('.buzzItem-title').animate({ bottom:'-30px'}, 150)
				$(this).find('.buzzFlash').hide();
			}
		);
		
	}
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	//	Buzz Detail
	//////////////////////////////////////////////////////////////////////////////////////////////////////////		
	if ($('.buzzDetail').html() != null){
		//$('.photo').width($('.buzzMain_photo img').width());
	}	
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	//	Contest info
	//////////////////////////////////////////////////////////////////////////////////////////////////////////		
	if ($('.contestInfo').html() != null){
		var top = $('#contestMenu').offset().top - parseFloat($('#contestMenu').css('marginTop').replace(/auto/, 0));
		  $(window).scroll(function (event) {			
			var y = $(this).scrollTop();
		  
			if (y >= top) {
				if (y < (getDocumentSize(1)-755)){
					$('#contestMenu').removeClass('fixedBottom').addClass('fixed').css('top', '10px');
				}
				else{
					$('#contestMenu').removeClass('fixed').addClass('fixedBottom').css('top', getDocumentSize(1)-1000);
				}
			} else {
				$('#contestMenu').attr('class','');
			}
		  });
	}
	
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	//	Contestant List
	//////////////////////////////////////////////////////////////////////////////////////////////////////////	
	if ($('.contestantList').html() != null){
		$('.contestantList li').hover(
			function(){
				$(this).find('span').stop(true, true).animate({ bottom: '-1px'}, 200).find('cite').show();
			},
			function(){
				$(this).find('span').stop(true, true).animate({ bottom: '-15px'}, 200).find('cite').hide();
			}
		);
		
		
		$.easing.bouncy2 = function (x, t, b, c, d) {
			var s = 1.70158;
			if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
			return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
		}	
		$.tools.tooltip.addEffect("bouncy2",
			function(done) {
				this.getTip().animate({top: '+=10', opacity: '1'}, 400, 'bouncy2', done).show();
			},
			function(done) {
				this.getTip().animate({top: '-=10', opacity: '0'}, 400, 'bouncy2', function()  {																			   				$(this).hide();
					done.call();
				});
			}
		);
		$(".graphicGraph a").tooltip({effect: 'bouncy2', position: 'top right', tipClass: 'tooltip2'});
	}
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	//	Contestant Detail
	//////////////////////////////////////////////////////////////////////////////////////////////////////////	
	if ($('.contestantDetail').html() != null){
		$('.contestantComment').click(function(){
			$(this).parent().parent().next().slideDown();
		});
		
		// Judge comment
		/*$('.judge_comment').hover(
			function(){				
				setInterval( $(this).animate({ top: '-=1px'}),1000 );
			},
			function(){
			}
		);*/
		
		// tooltip
		$.easing.bouncy2 = function (x, t, b, c, d) {
			var s = 1.70158;
			if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
			return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
		}	
		$.tools.tooltip.addEffect("bouncy2",
			function(done) {
				this.getTip().animate({top: '+=10', opacity: '1'}, 400, 'bouncy2', done).show();
			},
			function(done) {
				this.getTip().animate({top: '-=10', opacity: '0'}, 400, 'bouncy2', function()  {																			   				$(this).hide();
					done.call();
				});
			}
		);
		$(".graphicGraph a").tooltip({effect: 'bouncy2', position: 'top right', tipClass: 'tooltip2'});
	}
	
});



// On Load
/*$(window).load(function () {
	if ($('.buzzMain photo').html() != null){
		var ImgSrc = $('#bg img').attr('src');
		var bgImg = new Image();
		bgImg.src = ImgSrc;	
		bgImg.onload = function(){			
			//IE 
			bgImg.onload=function(){};
		}
		
		bgImgWidth = bgImg.width;
		bgImgHeight = bgImg.height;	
		
		initBg(bgImgWidth, bgImgHeight);
	}
});*/



// On Resize
//$(window).resize(function(){});
	


// Contestant detail : slide judge's comment
var slideJudgeComment;
var slideJudgeSpeed=0;
function startJudge( currentComment ){	
	$(currentComment).addClass('judgeOver');	
	
	var getCommentHeight = $('.judgeOver').height();
	var limitSlide		 = -(getCommentHeight - 41); 
	
	slideJudgeSpeed = Number(slideJudgeSpeed)-1;	
	if (slideJudgeSpeed>limitSlide){
		$('.judgeOver').css({ top: ""+slideJudgeSpeed+"px"});
		slideJudgeComment = setTimeout("startJudge()",100);
	}
}
function stopJudge( currentComment ){
	slideJudgeSpeed=0;
	$('.judgeOver').removeClass('judgeOver');
	$(currentComment).stop(true, true).animate({ top: '0px'});	
	clearTimeout(slideJudgeComment);
}



var buzzInitNum = 0;
var buzzDelay;
var buzzRandomDelay;
var buzzRandomReduce = 0.1;
var buzzItem_size = 77;	

function buzzInit(buzzInitNum){
	
	var buzzItem_len = $(".buzzItem").length;	
	
	//$('.buzzItem').each(function(i){		
		//var buzzItem_meta 	= $(this).attr('title');
		
		/*var buzzItem_meta 	= $('.buzzItem:eq('+buzzInitNum+')').attr('title');
		var buzzItem_x		= Number(buzzItem_meta.substring(0,1));
		var buzzItem_y		= Number(buzzItem_meta.substring(1,2));
		var buzzItem_w		= Number(buzzItem_meta.substring(2,3));
		var buzzItem_h		= Number(buzzItem_meta.substring(3,4));*/
		
		$('.buzzItem:eq('+buzzInitNum+')')/*.css({
			left	: buzzItem_x * buzzItem_size,
			top		: buzzItem_y * buzzItem_size,
			width	: buzzItem_w * buzzItem_size,
			height	: buzzItem_h * buzzItem_size
		})*/.fadeIn(400)/*.find('a').append('<div class="buzzFlash"></div>');
		
		$('.buzzFlash:eq('+buzzInitNum+')').css({
			width	: buzzItem_w * buzzItem_size,
			height	: buzzItem_h * buzzItem_size
		})*/;
	//});
	
	buzzInitNum=Number(buzzInitNum)+1;
	
	if (buzzInitNum < buzzItem_len){
		buzzDelay = setTimeout("buzzInit("+buzzInitNum+")", 40);
		buzzRandomReduce = buzzRandomReduce + 0.05;
	}
	else{
		clearTimeout(buzzRandomDelay);
		clearTimeout(buzzDelay);		
		$('.buzzFake').stop(true, true).fadeOut(100);
	}
};

function buzzRandom(){	
	$('.buzzFake').each(function(){
		//$(this).fadeTo(0, randomFade);
		//for (i=0; i<72; i++){
			//$('.buzzFake:eq('+i+')').fadeTo(0, randomFade);
			var randomFade = Math.floor( Math.random() * (1.9-buzzRandomReduce)); 
			$(this).fadeTo(100, randomFade);
		//}
	});
	
	buzzRandomDelay = setTimeout("buzzRandom()", 5);
}



var closeComment;
// Home | setup box 'KHOANH KHAC THANG HOA'
var moment_cm_length;
var moment_cm_speed = 700;
function moment_cm(){	
	moment_cm_length = $('#moment_cm_scroll ul').length;
	
	$('#moment_cm_scroll ul').each( function(i){
		$(this).attr('rel',i);
	});
	$('#moment_cm_scroll ul:first').addClass('moment_cm_selected').show();

	moment_cm_bind();
}
function moment_cm_bind(){
	$('#KKTH_btnUp').live('click', moment_cm_Up);
	$('#KKTH_btnDown').live('click', moment_cm_Down);
}	
function moment_cm_unBind(){
	$('#KKTH_btnUp').die('click', moment_cm_Up);
	$('#KKTH_btnDown').die('click', moment_cm_Down);
}
function moment_cm_Up(){
	moment_cm_unBind();
	if ($('.moment_cm_selected').attr('rel') == "0"){
		$('.moment_cm_selected').animate({ top: '130px'}, moment_cm_speed, 'easeOutQuart').removeClass('moment_cm_selected');
		$('#moment_cm_scroll ul:last').show().css({ top:'-130px'}).addClass('moment_cm_selected').animate({ top: '0'}, moment_cm_speed, 'easeOutQuart', function(){
			moment_cm_bind();
		});
	}
	else{
		$('.moment_cm_selected').animate({ top: '130px'}, moment_cm_speed, 'easeOutQuart');
		$('.moment_cm_selected').prev().show().css({ top:'-130px'}).animate({ top: '0'}, moment_cm_speed, 'easeOutQuart', function(){
			$('.moment_cm_selected').removeClass('moment_cm_selected');
			$(this).addClass('moment_cm_selected');
			moment_cm_bind();
		});
	}		
	return false;
};
function moment_cm_Down(){
	moment_cm_unBind();
	if ($('.moment_cm_selected').attr('rel') == moment_cm_length-1){
		$('.moment_cm_selected').animate({ top: '-130px'}, moment_cm_speed, 'easeOutQuart').removeClass('moment_cm_selected');
		$('#moment_cm_scroll ul:first').show().css({ top:'130px'}).animate({ top: '0'}, moment_cm_speed, 'easeOutQuart', function(){
			moment_cm_bind();
		}).addClass('moment_cm_selected');
	}
	else{
		$('.moment_cm_selected').animate({ top: '-130px'}, moment_cm_speed, 'easeOutQuart');
		$('.moment_cm_selected').next().show().css({ top:'130px'}).animate({ top: '0'}, moment_cm_speed, 'easeOutQuart', function(){
			$('.moment_cm_selected').removeClass('moment_cm_selected');
			$(this).addClass('moment_cm_selected');
			moment_cm_bind();
		});
	}		
	return false;
};
function moment_close(){
	$('#moment_form').fadeOut( function(){
		$('#moment_cm').animate({ marginLeft:'0px', opacity:'1'}, 300, function(){
			//$('#moment_form').show();
			$('#post_past').show();
			$('#moment_success').hide();
		});
	});
}
function moment_callback(){
	$('#post_past').hide();
	$('#moment_success').show();
	
	$('#moment_cm_scroll ul').each( function(i){
		$(this).attr('rel',i);
	});
	$('#moment_cm_scroll ul:first').addClass('moment_cm_selected').show();
	
	closeComment = setTimeout("moment_close()", 3000);
}


// Home | setup box 'P/S VA NHUNG KHOANH KHAC VUI NHON'
var psmoment_cm_length;
var psmoment_cm_speed = 700;
function psmoment_cm(){	
	psmoment_cm_length = $('#psmoment_cm_scroll ul').length;
	
	$('#psmoment_cm_scroll ul').each( function(i){
		$(this).attr('rel',i);
	});
	$('#psmoment_cm_scroll ul:first').addClass('psmoment_cm_selected').show();

	psmoment_cm_bind();
}
function psmoment_cm_bind(){
	$('#KKVN_btnUp').live('click', psmoment_cm_Up);
	$('#KKVN_btnDown').live('click', psmoment_cm_Down);
}	
function psmoment_cm_unBind(){
	$('#KKVN_btnUp').die('click', psmoment_cm_Up);
	$('#KKVN_btnDown').die('click', psmoment_cm_Down);
}
function psmoment_cm_Up(){
	psmoment_cm_unBind();
	if ($('.psmoment_cm_selected').attr('rel') == "0"){
		$('.psmoment_cm_selected').animate({ top: '130px'}, psmoment_cm_speed, 'easeOutQuart').removeClass('psmoment_cm_selected');
		$('#psmoment_cm_scroll ul:last').show().css({ top:'-130px'}).addClass('psmoment_cm_selected').animate({ top: '0'}, psmoment_cm_speed, 'easeOutQuart', function(){
			psmoment_cm_bind();
		});
	}
	else{
		$('.psmoment_cm_selected').animate({ top: '130px'}, psmoment_cm_speed, 'easeOutQuart');
		$('.psmoment_cm_selected').prev().show().css({ top:'-130px'}).animate({ top: '0'}, psmoment_cm_speed, 'easeOutQuart', function(){
			$('.psmoment_cm_selected').removeClass('psmoment_cm_selected');
			$(this).addClass('psmoment_cm_selected');
			psmoment_cm_bind();
		});
	}		
	return false;
};
function psmoment_cm_Down(){
	psmoment_cm_unBind();
	if ($('.psmoment_cm_selected').attr('rel') == psmoment_cm_length-1){
		$('.psmoment_cm_selected').animate({ top: '-130px'}, psmoment_cm_speed, 'easeOutQuart').removeClass('psmoment_cm_selected');
		$('#psmoment_cm_scroll ul:first').show().css({ top:'130px'}).animate({ top: '0'}, psmoment_cm_speed, 'easeOutQuart', function(){
			psmoment_cm_bind();
		}).addClass('psmoment_cm_selected');
	}
	else{
		$('.psmoment_cm_selected').animate({ top: '-130px'}, psmoment_cm_speed, 'easeOutQuart');
		$('.psmoment_cm_selected').next().show().css({ top:'130px'}).animate({ top: '0'}, psmoment_cm_speed, 'easeOutQuart', function(){
			$('.psmoment_cm_selected').removeClass('psmoment_cm_selected');
			$(this).addClass('psmoment_cm_selected');
			psmoment_cm_bind();
		});
	}		
	return false;
};
function psmoment_close(){
	$('#psmoment_form').fadeOut( function(){
		$('#psmoment_cm').animate({ marginLeft:'0px', opacity:'1'}, 300, function(){
			//$('#moment_form').show();
			$('#spotForm').show();
			$('#psmoment_success').hide();
		});
	});
}
function psmoment_callback(){
	$('#spotForm').hide();
	$('#psmoment_success').show();
	
	psmoment_cm_length = $('#psmoment_cm_scroll ul').length;
	
	$('#psmoment_cm_scroll ul').each( function(i){
		$(this).attr('rel',i);
	});
	$('#psmoment_cm_scroll ul:first').addClass('psmoment_cm_selected').show();
	
	closeComment = setTimeout("psmoment_close()", 3000);
}


// Home | setup box 'NHAN VAT NOI BAT'
var hotstar_cm_length;
var hotstar_cm_speed = 700;
function hotstar_cm(){	
	hotstar_cm_length = $('#hotstar_cm_scroll ul').length;
	
	$('#hotstar_cm_scroll ul').each( function(i){
		$(this).attr('rel',i);
	});
	$('#hotstar_cm_scroll ul:first').addClass('hotstar_cm_selected').show();

	hotstar_cm_bind();
}
function hotstar_cm_bind(){
	$('#NVNB_btnUp').live('click', hotstar_cm_Up);
	$('#NVNB_btnDown').live('click', hotstar_cm_Down);
}	
function hotstar_cm_unBind(){
	$('#NVNB_btnUp').die('click', hotstar_cm_Up);
	$('#NVNB_btnDown').die('click', hotstar_cm_Down);
}
function hotstar_cm_Up(){
	hotstar_cm_unBind();
	if ($('.hotstar_cm_selected').attr('rel') == "0"){
		$('.hotstar_cm_selected').animate({ top: '130px'}, hotstar_cm_speed, 'easeOutQuart').removeClass('hotstar_cm_selected');
		$('#hotstar_cm_scroll ul:last').show().css({ top:'-130px'}).addClass('hotstar_cm_selected').animate({ top: '0'}, hotstar_cm_speed, 'easeOutQuart', function(){
			hotstar_cm_bind();
		});
	}
	else{
		$('.hotstar_cm_selected').animate({ top: '130px'}, hotstar_cm_speed, 'easeOutQuart');
		$('.hotstar_cm_selected').prev().show().css({ top:'-130px'}).animate({ top: '0'}, hotstar_cm_speed, 'easeOutQuart', function(){
			$('.hotstar_cm_selected').removeClass('hotstar_cm_selected');
			$(this).addClass('hotstar_cm_selected');
			hotstar_cm_bind();
		});
	}		
	return false;
};
function hotstar_cm_Down(){
	hotstar_cm_unBind();
	if ($('.hotstar_cm_selected').attr('rel') == hotstar_cm_length-1){
		$('.hotstar_cm_selected').animate({ top: '-130px'}, hotstar_cm_speed, 'easeOutQuart').removeClass('hotstar_cm_selected');
		$('#hotstar_cm_scroll ul:first').show().css({ top:'130px'}).animate({ top: '0'}, hotstar_cm_speed, 'easeOutQuart', function(){
			hotstar_cm_bind();
		}).addClass('hotstar_cm_selected');
	}
	else{
		$('.hotstar_cm_selected').animate({ top: '-130px'}, hotstar_cm_speed, 'easeOutQuart');
		$('.hotstar_cm_selected').next().show().css({ top:'130px'}).animate({ top: '0'}, hotstar_cm_speed, 'easeOutQuart', function(){
			$('.hotstar_cm_selected').removeClass('hotstar_cm_selected');
			$(this).addClass('hotstar_cm_selected');
			hotstar_cm_bind();
		});
	}		
	return false;
};
function hotstar_close(){
	$('#hotstar_form').fadeOut( function(){
		$('#hotstar_cm').animate({ marginLeft:'0px', opacity:'1'}, 300, function(){
			//$('#moment_form').show();
			$('#judgeForm').show();
			$('#hotstar_success').hide();
		});
	});
}
function hotstar_callback(){
	$('#judgeForm').hide();
	$('#hotstar_success').show();
	
	hotstar_cm_length = $('#hotstar_cm_scroll ul').length;
	
	$('#hotstar_cm_scroll ul').each( function(i){
		$(this).attr('rel',i);
	});
	$('#hotstar_cm_scroll ul:first').addClass('hotstar_cm_selected').show();
	
	closeComment = setTimeout("hotstar_close()", 3000);
}




/*
 * Lightbox use jQuery library - Require $ 1.2+
 * @Version:	1.0.5
 * History: 	[05/19] update caobox position with pagescroll

Usage: 	caobox.show('boxID', 'overlayColor', 'overlayOpacity', 'overlayDisable', 'leftPosition', 'topPosition')
Exp:	caobox.show('testID', '000', '50', '', '10', '10')
Arguments:
	divID : [char] Div's id
	overlayColor : [hex number] Used to define the overlay background color.  '000' (black) is default
	overlayOpacity : [int 0~100] Used to define the overlay opacity. '50' is default.
	overlayDisable : ['false'] Used to disable click on overlay to close popup. null is default
	leftPosition : [int] The padding CSS information used in the left position of image box. null mean center is default. [int]<0 is padding-right position
	topPosition : [int] The padding CSS information used in the top position of image box. null mean middle is default. [int]<0 is padding-bottom position
*/

var inner_boxID ;
var cloneTemp;
var caobox = {		
	fadeEffectDuration : 0,
	fade:"#fade",
	light:"#light",
	boxID:"",
	overlayBgColor:"#000000",
	overlayOpacity:"70",
	
	show:function(boxId, getCurrentOffset, callback)
	{
		/*$("*", document.body).click(function (e) {
		  var offset = $(this).offset();
		  e.stopPropagation();
			currentOffsetTop = offset.top;
		});*/
		
		/*var offset = getCurrentOffset.offset();
		e.stopPropagation();
		alert(offset.top);*/
		
		
		// Get layer Background color & opacity
		//if (overlayBgColor) this.overlayBgColor = "#"+ overlayBgColor;
		//if (overlayOpacity) this.overlayOpacity = overlayOpacity;
		
		// Add layer
		if ($('#light').html() == null){
			$('body').prepend('<div id="light"></div><div id="fade"></div>');
		}
		$('#light, #fade').css('display','none');
		$('#light').css({	'position':'absolute',
							'zIndex':'10002',
							'height':'auto'/*, 'overflow':'hidden'*/});
		$('#fade').css({	'position':'absolute',
					   		'zIndex':'10001',
					   		'left':'0',
							'top':'0',
					   		'backgroundColor': ''+ this.overlayBgColor +'',
					   		'opacity':'.'+ this.overlayOpacity+'',
							'filter':'alpha(opacity='+ this.overlayOpacity +')'
						}).click(	function(){
										//if (overlayDisable) return true;
										//else caobox.hide();
										caobox.hide();
									});
	
		// Show layer
		this.boxID='#'+boxId;		
		$('object, embed, select').css('visibility','hidden');
		$('object, embed').css('display','none');

						
		// Auto dectect Ajax loading
		var autodectect = boxId.substring(boxId.lastIndexOf(".")+1, boxId.length).toLowerCase();
		switch (autodectect)
		{
			case "aspx":
			case "php":
			case "html":
				$(this.light).css({ width:"338px"}).load(boxId, function(){});
				break;
				
				
			case "jpg":
			case "gif":
			case "png":				
				var ImgSrc = boxId;
				var bgImg = new Image();
				bgImg.src = ImgSrc;	
				bgImg.onload = function(){			
					
					bgImgWidth = bgImg.width;
					bgImgHeight = bgImg.height;	
					
					//IE 
					bgImg.onload=function(){};
					
					$('#light')
						.css({ width:bgImgWidth+14, height:bgImgHeight+14, marginLeft: -(bgImgWidth+14)/2})
						.append('<div class="caobox-image"><em class="caobox-close" onclick="caobox.hide()" /><img width='+bgImgWidth+' height='+bgImgHeight+' src='+boxId+' /></div>');					
				}
				break;
				
				
			case "mp3":
				$('#light')
						.css({ width:"414px", height:"314px"})
						.append('<div class="caobox-image"><em class="caobox-close" onclick="caobox.hide()" />'+
								'<object width="400" height="300">'+
									'<param value="swf/MP3Player.swf" name="movie">'+
									'<param value="true" name="allowFullScreen">'+
									'<param value="always" name="allowscriptaccess">'+
									'<param value="'+boxId+'" name="flashvars">'+
									'<param value="opaque" name="wmode">'+
									'<embed width="400" height="300" flashvars="'+boxId+'" allowfullscreen="true" wmode="opaque"  allowscriptaccess="always" type="application/x-shockwave-flash" src="swf/MP3Player.swf">'+
								'</object>'+
								'</div>');
				break;
				
			
			case "flv":
				$("#light")
						.css({ width:"414px", height:"314px"})
						.append('<div class="caobox-image"><em class="caobox-close" onclick="caobox.hide()" />'+
								'<object width="400" height="300">'+
									'<param value="swf/VideoPlayer_v03.swf" name="movie">'+
									'<param value="true" name="allowFullScreen">'+
									'<param value="always" name="allowscriptaccess">'+
									'<param value="opaque" name="wmode">'+
									'<param value="'+boxId+'" name="flashvars">'+
									'<embed width="400" height="300" flashvars="'+boxId+'" allowfullscreen="true" allowscriptaccess="always" wmode="opaque" type="application/x-shockwave-flash" src="swf/VideoPlayer_v03.swf">'+
								'</object>'+
								'</div>');
				break;
				
				
			default:
				var oClone = $(this.boxID).clone();
				$(this.boxID).remove();
				$(this.boxID+'_hidden').remove();
				oClone.appendTo($(this.light));
				break;
		}
		
		
		
		//$(this.boxID).show();
		//$(this.light).fadeIn('slow', function(){
			 //$(this.light).css({display:'block'}); 
		//});
		
		
		//$(this.light).fadeIn( this.fadeEffectDuration, function(){	
		$(this.light).slideDown('0', function(){		
			//callback
			if (callback){
				var callbackFunction = callback;
				window[callbackFunction]();				
			}
		});
		

		
		
	// Left position, default is center
		_left = Math.round((getDocumentSize(2) - $('#light').width())/2);
		//_left = Math.round((getDocumentSize(2) - $(this.light).width())/2);
		//_left = Math.round((getDocumentSize(2) - 338) / 2);			
		//$(this.light).css({left: _left+ "px"});		
		
	// Top position, default is middle
		$(this.light).css({	top:getDocumentSize(5)+100,	left: _left+ "px" });
		//var offset = $(getCurrentOffset).parent().offset();
		//var _top = Math.round((getDocumentSize(3) - $(this.light).height()) / 2);
		//_top = offset.top - 150;
		//$(this.light).css({top: _top+ "px"});
		
		

		
		
		//$(this.light).css({left: _left});
		//$(this.light).css({top: _top});
		
		$('#light object, #light embed, #light select').css({visibility:"visible", display:"block"});
		caobox.showAlertLayer();
		
		//alert($('.lightbox').attr('id'));
		//$('body').children().find('#'+boxId).html('');
		
		//caobox.setFocusElement();
		//window.scrollTo(0,0);
		window.onresize=caobox.resizeLayers;
	},
	
	hide:function(){
		//$(this.fade).fadeOut(this.fadeEffectDuration);
		$(this.fade).hide();
		
		//$(this.light).fadeOut(this.fadeEffectDuration, function(){
		$(this.light).hide(function(){
			$('object, embed, select').css('visibility','visible');
			$('object, embed, select').css('display','');
			$('#fade, #light').remove();
			
		});
		
		var lightboxID = $(this.boxID).attr('id');
		$('#'+lightboxID+':last').html(inner_boxID);		
		returnBoxID = $('.lightbox').attr('id');
		var oClone = $(this.boxID).clone();
		$('#light').remove();
		var boxhidden = this.boxID.substr(1)+'_hidden';
		$('body').append('<div id="'+boxhidden+'" style="display: none;"></div>');
		oClone.appendTo($('#'+boxhidden));
		
		
		
/*		cloneTemp = $(this.boxID).parent().html();
		$(this.boxID).parent().html('');
		$('body').append('<div style="display:none">'+cloneTemp+'</div>');
*/		
		
		
	},
	
	showAlertLayer : function(){
		var _height=getDocumentSize(1);
		var _width =getDocumentSize(0);
		
		if(_width < 974) 
			 _width = 974;	
		
		if($(this.boxID).height() > getDocumentSize(1))
			_height=parseInt($(this.boxID).height()) + 65;		
		
		$(this.fade).css({width:_width +'px'});
		$(this.fade).css({height:_height +'px'});	
		
		//$(this.fade).css({display:'block'}); 
		//$(this.fade).fadeIn( this.fadeEffectDuration);
		$(this.fade).show();
	},
	
	resizeLayers : function(){
		if($(this.boxID).height() > getDocumentSize(1)){
			var _height = parseInt($(this.boxID).height());
			var pageHeight = _height;
		}
		else{
			if (getDocumentSize(1) > getDocumentSize(3)){ var pageHeight=getDocumentSize(1)}
			else{ var pageHeight=getDocumentSize(3);}
		};
		
		if(getDocumentSize(0) < 974) $('#fade').css({width:974 + "px"});
		else $('#fade').css({width:getDocumentSize(0) + "px"});
		$('#fade').css({height:pageHeight + 'px'});
		$('#light').css({left: Math.round((getDocumentSize(2) - $('#light').width()) / 2)+"px"});
		
		var _top=Math.round((getDocumentSize(3) - $(this.light).height()) / 2);
		if(_top < 0) _top = 20;
		$(this.light).css({top:_top+"px"});
	},
	
	findFucusElement:function(){
		$("#light").find('object, embed, select').css({'visibility':'visible'});
		$("#light").find('input[@type!=hidden], a, select, textarea').addClass('setFocusAble');			
		return $('.setFocusAble');
	},
	
	setFocusElement:function(){
		var i = 0;
		var cntElement = 0;	
		var allFocusElement = caobox.findFucusElement();
		var len=allFocusElement.length;	
		
		if (len>0){
			for(var temJ = 0; temJ<len-1; temJ++){
				$(allFocusElement[temJ]).attr('rel',temJ+1);
			}
			
			// fix focus on 1st hidden element
			if ( allFocusElement[0].style.display == 'none') 
				allFocusElement[1].focus();
			else
				allFocusElement[0].focus();
	
	
			allFocusElement.focus(function(){ cntElement=this.getAttribute('rel'); });
			$("#light").keydown(function(event){									 
				if(event.shiftKey){
					if(event.keyCode == 9){					
						if (i!=cntElement) i=cntElement;
						i--;			
						if (i == 0) {
							i = len-1;
							allFocusElement[i].focus();
							return false;
						}
					}
				}
				else{
					if(event.keyCode == 9){
						if (i != cntElement) i = cntElement;
						if (i == len-1){
							i=0;
							allFocusElement[0].focus();						
							return false;
						}
						else{
							i++;
						}
					}
				}			
			}); 
		}
	},
	
	unbindClickFace:function(){
		$(this.fade).unbind('click');
	},
	
	init:function()
	{		
		$(document).ready(function(){
		})		
	}
};
caobox.init({							
});

// Get ducument size
// @param int 0 ~ 5
// @return array [width of page] [height of page] [width of window] [height of window] [x scroll] [y scroll]
function getDocumentSize(val){
	var xScroll, yScroll, value, pageScrollx, pageScrolly;
	
	if(window.innerHeight&&window.scrollMaxY){
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight){
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
		}
		else{
			xScroll=document.body.offsetWidth;
			yScroll=document.body.offsetHeight;
		}
	
	var windowWidth,windowHeight;
	
	if(self.innerHeight){
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight){
			windowWidth=document.documentElement.clientWidth;
			windowHeight=document.documentElement.clientHeight;
		}
		else if(document.body){
			windowWidth=document.body.clientWidth;
			windowHeight=document.body.clientHeight;
		}
	
	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}
	
	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}
	
	if (self.pageYOffset) {
		pageScrolly = self.pageYOffset;
		pageScrollx = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		pageScrolly = document.documentElement.scrollTop;
		pageScrollx = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
		pageScrolly = document.body.scrollTop;
		pageScrollx = document.body.scrollLeft;	
    }
	
	arrayPageSize=new Array(pageWidth, pageHeight, windowWidth, windowHeight, pageScrollx, pageScrolly);
	return arrayPageSize[val];
};
