﻿function openPlayer(spotId, spotTitle)
{
    $("#player").load("/Video/View/" + spotId, function ()
    {
        $("#player").dialog({ width: 575, height: 408, title: spotTitle, modal: true,
            close: function (event, ui) { $("#player").empty(); }
        });
    });

    return false;
}

function openSearch()
{
    $("#search").load("/Search/Index", function ()
    {
        $("#search").dialog({ width: 700, height: 410, title: 'IQ Search Engine', modal: true,
            close: function (event, ui) { $("#search").empty(); }
        });
    });

    return false;
}

function openResults(filterValues, letterValues)
{    
    $.ajaxSettings.traditional = true;
    var data = { filters: filterValues, letters: letterValues };
    $("#results").load("/Search/Main", data, function ()
    {    
        $("#results").dialog({ width: 700, height: 470, title: 'IQ Search Engine Results', modal: true,
            close: function (event, ui) { $("#results").empty(); }
        });
    });

    return false;
}

function getParameterByName(name)
{
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}


$(document).ready(function ()
{
    $(".default #searchImg").click(function ()
    {
        openSearch();
    });

    $("#loading").ajaxStart(function ()
    {
        $(this).show();
    }).ajaxStop(function ()
    {
        $(this).hide();
    });

    if (getParameterByName("spot") != '')
    {
        openPlayer(getParameterByName("spot"), "IQTV");
    }
});
