$(document).ready(function () {
    $("input[name=comperecheck]").click(function () {
		if($("#chatroom").contents().find("#compere_box").length<=0) {
			return false;
		}
        var onlyme = true;
        if($("input[name=chatroomcheck]").attr("checked") == true) {
            onlyme = false;
        }
        if($(this).attr("checked") == true) {
            $("#chatroom").contents().find("#compere").show();
            if(onlyme) {
                $("#chatroom").contents().find("#compere_box").css("height", 335);
            } else {
                $("#chatroom").contents().find("#compere_box").css("height", 120);
                $("#chatroom").contents().find("#chat_room_box").css("height", 215);
            }
        } else {
            $("#chatroom").contents().find("#compere").hide();
            $("#chatroom").contents().find("#compere_box").css("height", 0);
            if(!onlyme) {
                $("#chatroom").contents().find("#chat_room_box").css("height", 335);
            }
        }
    });
    $("input[name=chatroomcheck]").click(function () {
        var onlyme = true;
        if($("input[name=comperecheck]").attr("checked") == true) {
            onlyme = false;
        }
		if($("#chatroom").contents().find("#compere_box").length<=0) {
			onlyme = true;
		}
        if($(this).attr("checked") == true) {
            $("#chatroom").contents().find("#chat_room").show();
            if(onlyme) {
                $("#chatroom").contents().find("#chat_room_box").css("height", 335);
            } else {
                $("#chatroom").contents().find("#compere_box").css("height", 120);
                $("#chatroom").contents().find("#chat_room_box").css("height", 215);
            }
        } else {
            $("#chatroom").contents().find("#chat_room").hide();
            $("#chatroom").contents().find("#chat_room_box").css("height", 0);
            if(!onlyme) {
                $("#chatroom").contents().find("#compere_box").css("height", 335);
            }
        }
    });
	$("#CinemaModel").click(function () {
		optionModel();
	});
	getNews();
    viewip();
});
var newstitle = '';
function getNews() {
	$.post(API+"/index.php?m=news", {title: newstitle}, function (data) {
		if(data) {
			var arr = data.split("<tt>");
			if(arr[1]) {
				newstitle = arr[0];
				if($("#live_news > li:first-child > a").html() != arr[0]) {
					$("#news_pop").html('<iframe src="'+API+'/index.php?m=news&a=pop&title='+arr[0]+'&link='+arr[2]+'" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" height="119px" width="152px"></iframe>');
					$("#live_news > li:last-child").remove();
					$("#live_news").prepend("<li>"+arr[1]+"</li>");
					$("#news_pop").fadeIn(function() {  
						var a = setTimeout(function() {  
							$("#news_pop").fadeOut(3000);
						}, 7000);
						$("#news_pop").hover(function () {
							clearTimeout(a);
							$(this).stop().fadeIn(500);
						}, function () {
							$(this).stop().fadeOut(3000);
						});
				   });
				}
			}
		}
		setTimeout("getNews()", 30000);
	});
}

var sec = 10;
var num = 0;
function adsec()
{
    if(num>=sec) {
        closead();
    }else{
        num++;
        $('#tvsec').html(sec-num);
        setTimeout("adsec()", 1000);
    }
}

function viewip()
{
    $.get(API+'/index.php?m=play&a=ip', {}, function (data) {
                $('#strcontent').html(data); 
            })
}
function closead() {
    $('#tvad').css('display','none');
    $('#tvad').css('z-index','0');
    $('#play').css('z-index','9999');
}

function getcode(channel){
	var text='<iframe id="play_content" name="play_content" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" height="398px" width="450px" src="'+API+'/index.php?m=play&a=channel_code&channel='+channel+'"></iframe>';
	document.getElementById('play_code').innerHTML = text;
	hidden_div(10,'channel_box');
	document.frames['play_content'].location.reload();
}

function loadChat()
{
    var pageUrl = document.URL;
    var arr = '';
    var type = '';
    var chatType = '';
    var infoid = '';
    var chaturl = '';
    if (pageUrl.indexOf('#') != '-1')
    {
        arr = pageUrl.split('#');
        arr = arr[1];
        type = arr.substr(0,1);
        infoid = arr.substr(1);
        if (type == 'n') chatType = 'nba';
        if (type == 'c') chatType = 'cba';
        if (type == 'o') chatType = 'live';
        if (!chatType || !infoid) return false;
        chaturl = API+'/index.php?m=chat&a=liveChat&cid='+infoid+'&type='+chatType;
        document.getElementById('chatroom').src=chaturl;
    }
	document.frames['chatroom'].location.reload();
}

function openCinemaModel()
{
	var bH = $("body").height();
	var bW = $("body").width();
	if(bH < document.body.clientHeight) {
		bH = document.body.clientHeight;
	}
	if(bW < document.body.clientWidth) {
		bW = document.body.clientWidth;
	}
	 
	//var ve = $("embed").attr("wmode");  
	//$("EMBED").attr("wmode","window"); 
	$("#cinemaModelLay").css({width:bW,height:bH,display:"block"});
	$("#cinemaToolbar").css({display:"block"});
}

function exitCinemaModel()
{
	$("#cinemaModelLay").hide();
	$("#cinemaToolbar").hide();
}
function optionModel()
{
	if(document.getElementById("cinemaModelLay").style.display == 'none') {
		openCinemaModel();
	} else {
		exitCinemaModel();
	}
}

function hidden_div(num,obj)
{
		document.getElementById(obj).style.display = 'block';
		document.getElementById(obj).style.filter = "alpha(opacity="+num+")";
		document.getElementById(obj).style.opacity = num/100;
		num--;
		if (num > 0)
		{
			setTimeout("hidden_div("+num+",'"+obj+"')",150);
		}
		else
		{
			document.getElementById(obj).style.display = 'none';
			document.getElementById(obj).style.filter = "alpha(opacity=100)";
			document.getElementById(obj).style.opacity = 1;
		}
}
