﻿
/// <reference path="intellisense/jquery-1.2.6-vsdoc.js" />
/// <reference path="intellisense/jquery.ajaxdotnet.intellisense.js" />


// TV jquery script 
// Local Variable
var options;
var BBC = 126, ch1 = 198, Mardom = 113, sazegara = 134, appa = 8, pars = 4, time = 144, mihan = 129;


$(function() {

    // Cache tv List
    options = 'Change TV Stations : <select id="tvlist" title="Change TV Stations">';
    for (var i = 0; i < TV_List.length; i++) {
        options += "<option value='" + parseInt(TV_List[i][0]) + "' >" + TV_List[i][1] + "</option>";
    }
    options += '</select>';

    //Add tip

    $('input[tip]').each(function() {
        $(this).data('tip', $(this).attr('tip'))
        .SCCtip({ tip_nb: $(this).data('tip') });
    });

    // Pars tV
    $('#4').click(function() {
        ParstTV();
    });

    // Add click event
    //$('.button1').click(function() {
    $('.button1[id!=4]').click(function() {
        //Remove Moshiri
        try {
            // Remove tip if exist
            if (this.tooltipdiv) {
                $(this.tooltipdiv).hide();
            }
            $('#JT').remove();
        }
        catch (err) { err.name + ': ' + err.message }
        finally {
            // Disable all button
            $('.button1').each(function() { this.disabled = true; });
            MakeTV(this.id, $(this).val());
        }

    }); // button1 click


});                                                                         //Ready

ParstTV = function() {
    if (this.tooltipdiv) {
        $(this.tooltipdiv).hide();
    }
    $('#JT').remove();

    window.open('http://www.voinews.net/Live/Default.aspx');
    try {
        //$.post('WebServices/TV.asmx/Add_TV_Count', { 'TvID': 4 });
        $.ajaxDotNet('WebServices/TV.asmx/Add_TV_Count',
            {
                data: { 'TvID': 4 }
            });
    }
    catch (err) { } // alert(err); }
    return false;

}


stopTV = function() {
    try {
        if ($.browser.msie) {

            var player = document.getElementById('Mplayer') || document.getElementsByTagName('object');
            if (player) {
                player.controls.stop();
            }

        }
        $('#frame').empty().remove();
    }
    catch (err) {  } //alert(err.message);

}       // stopTV

MakeTV = function(tvid, tvname) {
    stopTV();
    $.ajaxDotNet('WebServices/TV.asmx/Get_Tv_Info',
            {
                data: { 'tvID': tvid }
                , success: function(ret) {
                    if (ret.Title) {
                        $.nyroModalManual({
                            bgColor: '#3333cc'
                            , content: MakeHtm(ret, tvname)
                            , minWidth: 220
                            , minHeight: 200
                            , modal: true
                            , endShowContent: function(elts, settings) {
                                var ddl = elts.content.find('select');  // drop down
                                var opts = elts.content.find('option'); // option array
                                // Select tvid in ddl, and get focussed
                                opts.filter('[value="' + tvid + '"]').attr('selected', 'selected').parent('select').focus();
                                ddl.change(function() {
                                    var tvidVal = $(this).val();
                                    switch (tvidVal) {
                                        case '0':
                                            return false;
                                            break;
                                        case '4':
                                            ParstTV();
                                            $.nyroModalRemove();
                                            break;
                                        default:
                                            //$('#frame').empty().remove();
                                            $('#tblMedia').empty();
                                            MakeTV($(this).val(), $(this).children('[selected]').text());
                                            break;
                                    }
                                });
                            }
                            , beforeHideContent: function(elts, settings, goback) {
                                // Just stop TV if is IE
                                stopTV();
                                $('#frame').empty().remove();
                                $('#tblMedia').remove();
                                goback();
                            }

                            , endRemove: function() {
                                //Enable buttons
                                $('.button1').each(function() { this.disabled = false; });
                            }
                            , 'blocker': '#main_content'
                            //, debug: true

                        }); // nyroModal
                    }
                    else {

                        alert('Network Problems: There is a problem with connection to database. We\'re working on it. Please try later.');
                    }

                } // success
                , error: function(xhr, st, e) {
                    alert('Network Problems: There is a problem with connection to database. \nWe\'re working on it. Please try later. \nError : ' + e.Message);
                    $('.button1').each(function() { this.disabled = false; });
                } //Other
            }); // ajaxDotNet
}                                                       // MakeTV
makeIranTV = function(tv) {
    var src = 'http://www.iran.tv/new/ChannelDetail.php?q=' + tv + '&VID=' + tv + '&TN=online_channel#WMP';

    return '<tr><td align="center"><iframe id="frame" name="frame" width="326" height="312" frameborder="0"  src="' + src + '"></iframe></iframe></td></tr>';
}

MakeHtm = function(tv, btnValue) {
    // Make the mediaplayer html with TV info
    var h = (tv.IMG) ? 70 : (tv.H) ? tv.H : 350;
    var w = (tv.W) ? tv.W : 350;
    var t = tv.Title.split(":");
    var ui = (tv.recorded) ? 'full' : 'mini';
    var tbl_h = h + 110;
    var tbl_w = w + 20;

    var htm = '<table id="tblMedia" align="center" >'; //width="' + tbl_w + 'px" height="' + tbl_h + 'px" 

    htm += '<tr><td align="center"><a class="button"><span class="nyroModalClose" title="Stop' + t[1] + '"><strong>' + tv.Title + '</strong></span></a></td></tr>';
    htm += '<tr><td align="center">' + options + '</td></tr>';
    switch (tv.tvid) {
        case BBC:
            htm += '<tr><td align="center">';
            htm += '<iframe id="frame" name="frame" width="537" height="363" frameborder="0" src="BBC.htm"></iframe>';
            htm += '</td></tr>';
            break;
        case appa:
            htm += '<tr><td align="center"><iframe id="frame" name="frame" width="350" height="350" frameborder="0"  src="http://appadanatv.net/default.aspx#ctl00_IWS_WH_CPH_Content_HtmlControl3"></iframe></td></tr>';
            break;
        case Mardom:
            htm += '<tr><td valign="bottom"><iframe  id="frame" name="frame" width="300" height="350" frameborder="0"  src="http://mardomtv.com/mardomtv_for_ir2007.html"></iframe></td></tr>';
            break;
        case time:
            htm += '<tr><td valign="bottom"><iframe  id="frame" name="frame" width="300" height="350" frameborder="0"  src="http://timebroadcasting.com/Watch-live.html"></iframe></td></tr>';
            break;
        case mihan:
            htm += '<tr><td valign="bottom"><iframe  id="frame" name="frame" width="300" height="355" frameborder="0"  src="http://www.mihantv.com/MBD.html"></iframe></td></tr>';
            break;
        case sazegara:
            htm += '<tr><td>';
            htm += '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/';
            htm += saz;
            htm += '&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="autoplay" value="1"><embed src="http://www.youtube.com/v/';
            htm += saz;
            htm += '&hl=en&fs=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';
            htm += '</td></tr>';
            break;
        case pars:

            htm += '<tr><td valign="bottom"><iframe  id="frame" name="frame" width="440" height="360" frameborder="0"  src="ParsTV1.htm"></iframe></td></tr>';
            break;

        default:
            // Other Normal TV
            if (tv.IMG) {
                // Just voice show the picture K
                htm += '<tr><td align="center">';
                htm += '<img id="imgRadio" src="' + tv.ImgSRC + '" name="imgRadio" title="' + btnValue + '" width="' + tv.W + '" height="' + tv.H + '" />';
                htm += '</td></tr>';
            }


            htm += '<tr><td align="center">';
            htm += '<object id="Mplayer" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="' + w + '" height="' + h + '" type="application/x-oleobject">';
            htm += '<param name="url" value="' + tv.URL + '"/>';
            htm += '<param name="enableContextMenu" value="false" />';
            htm += '<param name="uiMode" value="' + ui + '" />';


            htm += '<embed name="MPlayer" id="MPlayer" enablecontextmenu="0" ';
            htm += 'src="' + tv.URL + '" ';
            htm += 'width="' + w + '" height="' + h + '" autostart="true" ';
            htm += 'uiMode="' + ui + '" type="application/x-mplayer2" ';
            htm += 'enableContextMenu="0" '
            htm += 'pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"></embed>';
            htm += '</object>';
    }
    htm += '</td></tr>';
    var newTV = (tv.newTV) ? '+' : '-';
    htm += '<tr><td align="center"><a class="button"><span class="nyroModalClose" title="Close TV Player" ><strong>' + newTV + 'Close TV Player' + newTV + '</strong></span></a>';
    htm += '</td></tr>';
    htm += '</table>';
    return htm;
}






