﻿/********************************************************/
// 	Language
/********************************************************/
var lang = readCookie("lang");
$(function(){
updateLang();
	$("#lang_website").bind('change', hChangeLanguage);
	$("#lang_video").bind('change', hChangeLanguage);
});

/********************************************************/
// 	电视直销滚动
/********************************************************/
$(function(){
	$("#tv_d_scroll").smoothDivScroll({
		scrollingSpeed: 1,
		autoScroll: "always",
		autoScrollDirection: "endlessloop",
		pauseAutoScroll: "mouseover"
	});
});

/********************************************************/
// 	顶部横条广告
/********************************************************/
$(function(){
	window.setTimeout(function(){
		$('#topadv').animate( { height:"50px" }, 2000, "linear", topadv_switch );
		focus_play(0);
	}, 5000);
});

function topadv_switch()
{
	$('#topadv > .mini').fadeIn();
	floatadv();
}

/********************************************************/
// 	浮动广告
/********************************************************/
var floatadvimg;
var h = (new Date()).getHours();
h = (h > 12 ? h - 12 : h);
//根据当前时间选择广告图片 l是大图， s是小图
if ( h >= 0 && h <=4 )
{
	floatadvimg = {
		l: '/2010/resource/images/floatadv/1.jpg',
		s: '/2010/resource/images/floatadv/1s.jpg',
		flink: 'http://www.kingsquare.ca/'
	};
}

if ( h > 4 && h <= 8 )
{
	floatadvimg = {
		l: '/2010/resource/images/floatadv/2.jpg',
		s: '/2010/resource/images/floatadv/2s.jpg',
		flink: 'http://www.kingsquare.ca/'
	};
}

if ( h > 8 && h <= 12 )
{
	floatadvimg = {
		l: '/2010/resource/images/floatadv/2.jpg',
		s: '/2010/resource/images/floatadv/2s.jpg',
		flink: 'http://www.kingsquare.ca/'
	};
}

/*if ( h > 8 && h <= 12 )
{
	floatadvimg = {
		l: '/2010/resource/images/floatadv/fidol.jpg',
		s: '/2010/resource/images/floatadv/fidos.jpg'
	};
}*/

function floatadv(){
	var t = '#floatadv';
	$(t).find('img').attr('src', floatadvimg.l);
	//$(t).find('a').attr({'href':'http://www.yorkbbs.ca/','target':'_blank'});

	var _btnstyle = "position:absolute;top:0;left:0;background-color:#000;display:block;color:#FFF;font-family:'Verdana';font-size:9px;font-weight:bold;padding:2px;text-decoration:none;";
	var _w = {h:$(window).height(), w:$(window).width()};
	var _t = {h:$(t).height(), w:$(t).width()};
	
	$(t).css({'z-index': 2, position:'absolute', top:(_w.h - _t.h) / 2, left:0}).show()
		.animate({top:0, left:(_w.w - _t.w) / 2})
		.animate({top:(_w.h - _t.h) / 2, left:_w.w - _t.w})
		.animate({top:_w.h - _t.h, left:(_w.w - _t.w) / 2})
		.animate({top:(_w.h - _t.h) / 2, left:0})
		.animate({top:(_w.h - _t.h) / 2, left:(_w.w - _t.w) / 2}, {complete:hidefloatadv});
}

function hidefloatadv() {
	var _p = $('#episode').offset();
	window.setTimeout(function(){
		$('#floatadv').animate({height:$('#episode').height() + 22, width:$('#episode').width() + 22, top:_p.top, left:_p.left}, {complete:function(){
				/*
				$("<a>CLOSE</a>")
					.attr("style", _btnstyle)
					.attr("href", "javascript:void(0);")
					.click(function(){$(t).fadeOut();})
					.appendTo(t);	
				*/
				$('#floatadv').find('img').attr({
						src:floatadvimg.s,
						height:$('#episode').height() + 22, 
						width:$('#episode').width() + 22
					});
				$('#floatadv').find('a').attr({
						href:floatadvimg.flink
					});
			}
		});
	}, 2000);
}

/********************************************************/
// 	Flash视频播放器
/********************************************************/
var play_id = 0;
var adv_inited = false;
//循环播放热点
function focus_play(id)
{
	swfobject.getObjectById("VideoPlayer").load(play_list[id].url);
	if (!adv_inited)
	{
		$.ajax({
		  url: '/2010/resource/js/videoadv.js',
		  dataType: 'script',
		  success: set_videoadv
		});
		adv_inited = true;
	}
	$('.video_title').text(play_list[id].title);
	$('.video_desc').text(play_list[id].desc);
	play_id = id;
}

//设置播放器广告
function set_videoadv()
{
	swfobject.getObjectById("VideoPlayer").set_adv(videoadv_setting.file, videoadv_setting.link);
}

function flashReady(){
	/* ExternalInterface ready */
	//focus_play(0);
}

function playComplete()
{
	focus_play((play_id + 1 < play_list.length) ? play_id + 1 : 0);
}

/********************************************************/
// 	标签切换
/********************************************************/
function promo_content(c, obj)
{
	$("#new_program").find('.container').load("../../web/index.php/home/get_promo/" + c);
	$("#p_switch").find('.current').removeClass('current');
	$(obj).parent().addClass('current');
}

function news_content(c, obj)
{
	$("#news_video").find('.container').load("../../web/index.php/home/get_news/" + c + "/13");
	$("#n_switch").find('.current').removeClass('current');
	$(obj).parent().addClass('current');
}

/********************************************************/
// 	文字新闻
/********************************************************/
$(function(){
	$("#news > .container").load('../resource/ajax.php?action=news');
	$("#txt_news > .container").load('/web/index.php/blocks/home_txt_news/13');
});
