﻿// Gasta result page
// -----------------------
// last updated 20/11/2007

//////////////////////////
// the Vars
//////////////////////////


var search_div_id = 0; //visible scrolled div id

var strSearchUrl = "index.aspx?keywords=";
var strVideoUrl = "/video/index.aspx?keywords=";
var strImagesUrl = "/images/index.aspx?keywords=";
var strNewsUrl = "/news/index.aspx?keywords=";

var strKeywords = getQueryVariable("keywords", getQueryString());

var img_offset = 0;


//ajax video defaults <- ajaxCallVideoSearch(strQuery, strNumResults, strPage)
var video_page_id = 1;
var strNumResults = 12;

//ajax news defualts
var strchannel;
var news_start;
var strResults, strStart, strLanguage, strHeadlineOnly;


var loading_html_message = "<div style=\"text-align:center; font-weight:bold; font-size:16px;\"><img src=\"../../assets/ajax-loader.gif\"/>"+ global_str_loading +"...</div>";




////////////////////////
// QueryString functions
////////////////////////

function getQueryVariable(variable, strQueryParams)
{
    var query = strQueryParams;
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++)
    {
    var pair = vars[i].split("=");
    if (pair[0].toLowerCase() == variable)
    {
    return pair[1];
    }
    }
}

function replaceQueryVariable(variable, newVal, strQueryParams)
{
    var query = strQueryParams;
    var vars = query.split("&");
    var newquery = "";
    for (var i=0;i<vars.length;i++)
    {
        var pair = vars[i].split("=");
        if (pair[0] == variable)
        {
            pair[1]= newVal;
        }
        if (newquery == "")
        {
            newquery = pair[0]+"="+pair[1]
        }
        else
        {
            newquery = newquery + "&" + pair[0]+"="+pair[1]
        }
    }
    
    return newquery;
}


function getQueryString()
{
    var queryUrl = window.location.search.substring(1);
    return queryUrl;

}

////////////////////////
// Javascript search
////////////////////////

function do_search(strpage, strhf)
{
    var elemName = $get(strhf);
    var elem = $get(elemName.value);
    var thisKeyword = html_encode(elem.value); //encodeMyHtml(elem.value);  
    
    /*var thisQueryString = replaceQueryVariable("keywords", thisKeyword, getQueryString());
    
    thisQueryString = replaceQueryVariable("Keywords", thisKeyword, getQueryString());
    alert(thisKeyword);*/
    
    
    window.location.href = strpage + "?keywords=" + thisKeyword;
   
    
    return false;

}


////////////////////////
//AJAX sliding search
////////////////////////

function ajaxCallSearch(strArgs) {
    var elem = "more_results";
    
    var lastResult = $get('search_results'+search_div_id);
    search_div_id = search_div_id + 1;
    
    var new_div = document.createElement('div'); 
    
    new_div.setAttribute('id','search_results'+search_div_id);

    new_div.innerHTML = loading_html_message;
    
    lastResult.appendChild(new_div);
    
    
    var strXArgs = getQueryVariable("xargs", strArgs);
    reVal = get_search.get_search_html(strKeywords, strXArgs, "0", "0", "0", OnCompleteSearch, OnTimeOutSearch, OnErrorSearch)
    return false;
    
}

function ajaxCallSearch_ASK(strArgs) {
    var elem = "more_results";
    
    var lastResult = $get('search_results'+search_div_id);
    search_div_id = search_div_id + 1;
    
    var new_div = document.createElement('div'); 
    
    new_div.setAttribute('id','search_results'+search_div_id);

    new_div.innerHTML = loading_html_message;
    
    lastResult.appendChild(new_div);
    
    
    var strXArgs = getQueryVariable("xargs", strArgs);
    var strXPage = getQueryVariable("page", strArgs);
    var strXqid = getQueryVariable("qid", strArgs);
    var strXPos = getQueryVariable("pos", strArgs);
    
    reVal = get_search.get_search_html(strKeywords, strXArgs, strXqid, strXPage, strXPos, OnCompleteSearch, OnTimeOutSearch, OnErrorSearch)
    return false;
    
}

function ajaxCallSearch_MSN(strArgs, offset) {
    var elem = "more_results";
    
    var lastResult = $get('search_results'+search_div_id);
    search_div_id = search_div_id + 1;
    
    var new_div = document.createElement('div'); 
    
    new_div.setAttribute('id','search_results'+search_div_id);

    new_div.innerHTML = loading_html_message;
    
    lastResult.appendChild(new_div);
    
    
    var strXArgs = getQueryVariable("xargs", strArgs);
    reVal = get_search.get_search_html(strKeywords, "0", "0", "0", offset, OnCompleteSearch, OnTimeOutSearch, OnErrorSearch)
    return false;
    
}

function ajaxCallLoadSearch(strKeywords) {
    var elem = "more_results";
    var lastResult = $get('search_results'+search_div_id);
    lastResult.innerHTML = loading_html_message;
    
    //var strXArgs = getQueryVariable("xargs", strArgs);
    reVal = get_search.get_search_html(strKeywords, null, null, null, null, OnCompleteLoadSearch, OnTimeOutSearch, OnErrorSearch)
    return false;
    
}

function ajaxCallLoadSearch_ASK(strKeywords) {
    var elem = "more_results";
    var lastResult = $get('search_results'+search_div_id);
    lastResult.innerHTML = loading_html_message;
    
    //var strXArgs = getQueryVariable("xargs", strArgs);
    reVal = get_search.get_search_html(strKeywords, "0", "0", "0", "0", OnCompleteLoadSearch, OnTimeOutSearch, OnErrorSearch)
    return false;
    
}

function ajaxCallLoadSearch_MSN(strKeywords) {
    var elem = "more_results";
    var lastResult = $get('search_results'+search_div_id);
    lastResult.innerHTML = loading_html_message;
    
    //var strXArgs = getQueryVariable("xargs", strArgs);
    reVal = get_search.get_search_html(strKeywords, null, null, null, "0", OnCompleteLoadSearch, OnTimeOutSearch, OnErrorSearch)
    return false;
    
}

function OnCompleteLoadSearch(value)
{
    var lastResult = $get('search_results'+search_div_id);
    //search_div_id = search_div_id + 1;
    
    //var new_div = document.createElement('div');
    
    
    //new_div.setAttribute('id','search_results'+search_div_id);
    //new_div.setAttribute('style','opacity:0');
    lastResult.innerHTML = value;
    
    //lastResult.appendChild(new_div);
    

}


                   
function OnCompleteSearch(value)
{  
    var lastResult = $get('search_results'+search_div_id);
    
   
    
    lastResult.innerHTML = value;
    
    ScrollDown(500,1);
    
}

function OnTimeOutSearch(value)
{
    window.location = "/index.aspx?keywords="+strKeywords+"&js=no";    
}

function OnErrorSearch(value)
{
    window.location = "/index.aspx?keywords="+strKeywords+"&js=no";
}



function ScrollUp(upBy, iv){
    var y = 0;
    var oiv = iv;
    if(window.pageYOffset) y = window.pageYOffset;
    else if(document.body && document.body.scrollTop) y = document.body.scrollTop;
    var d = ((y - upBy) >= 0)? (y - upBy) : 0;

    while(y > (d + 7)){
        setTimeout('window.scrollBy(0, -7)', iv);
        iv += oiv;
        y = (y - 7);
    }

    setTimeout('window.scrollBy(0, '+(-1)*(y - d)+')', iv);
}

function ScrollDown(downBy, iv){
    var oiv = iv;

    while(downBy > 0){
        setTimeout('window.scrollBy(0, 40)', iv);
        iv += oiv;
        downBy = (downBy - 40);
    }

    setTimeout('window.scrollBy(0, '+downBy+')', iv);
}

////////////////////////////////////////
//AJAX More Search -- Images/Video/News
////////////////////////////////////////

function ajaxCallImages(strTerm) {
    var elem = $get("os_image_content");
    elem.style.display="";
    reVal = get_images.get_image_html(strTerm, "9", "0", OnCompleteImages, OnTimeOutImages, OnErrorImages);
    
    
    return(false)
    
}                   
function OnCompleteImages(value)
{   
    $get("os_img_html").innerHTML = value;
}


function OnTimeOutImages(value)
{
    window.location = strImagesUrl + "&js=no"
    
}

function OnErrorImages(value)
{
    window.location = strImagesUrl + strKeywords + "&js=no";
}

function ajaxCallVideo(strTerm) {
    var elem = $get("os_video_content");
    elem.style.display="";
    reVal = get_video.get_video_html(strTerm, "6", "0", false, OnCompleteVideo, OnTimeOutVideo, OnErrorVideo)
    
    return(false)
    
}
function OnCompleteVideo(value)
{   
    $get("os_video_html").innerHTML = value;
}


function OnTimeOutVideo(value)
{
    window.location = strVideoUrl + strKeywords;
    
}

function OnErrorVideo(value)
{
    window.location = strVideoUrl + strKeywords;
}

//ajaxCallNews
function ajaxCallNews(strTerm) {
    var elem = $get("os_news_content");
    elem.style.display="";
    reVal = get_news.get_news_html(strTerm, "10", "0", "en", true, OnCompleteNews, OnTimeOutNews, OnErrorNews);
    
    
    return(false)
    
}                   
function OnCompleteNews(value)
{   
    $get("os_news_html").innerHTML = value;
}


function OnTimeOutNews(value)
{
    window.location = strNewsUrl + strKeywords;
    
}

function OnErrorNews(value)
{
    window.location = strNewsUrl + strKeywords;
}

////////////////////////////////////////
//End More Search -- Images/Video/News
////////////////////////////////////////



function go_link(go_url, default_page, active_tab, call_ajax_tab, tab_type_id)
{
    var elemName = $get('hd_box_id');
    var elem = $get(elemName.value);
    var text = elem.value;
    
    var encodetrimmed = html_encode(text);

    if (encodetrimmed.length > 0)
    {
        encodetrimmed = go_url + "index.aspx?keywords="+ encodetrimmed;
        window.location = encodetrimmed;
    }
    else
    {
        encodetrimmed = go_url + default_page;
        window.location = encodetrimmed;
    }
    return(false);
}


function html_encode(string) {

        //strip whitespace
        while (string.indexOf("  ") > 0)
                {
                    string = string.replace("  ", " ");
                } 
                
        /*string = string.replace(/^\s*|\s(?=\s)|\s*$/g, "");
        string = string.replace(/\r\n/g,"");*/
        
        
        
         
        var utftext = ""; 
        
        
        
        //utftext = encodeURI(string);
        
        utftext = escape(string);  
  
        /* <-- old school js support
        for (var n=0, k=string.length; n < k; n++) {  
            var c = string.charCodeAt(n);  
  
            if (c < 128) {  
                utftext += String.fromCharCode(c);  
            }  
            else if((c > 127) && (c < 2048)) {  
                utftext += String.fromCharCode((c >> 6) | 192);  
                utftext += String.fromCharCode((c & 63) | 128);  
            }  
            else {  
                utftext += String.fromCharCode((c >> 12) | 224);  
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);  
                utftext += String.fromCharCode((c & 63) | 128);  
            }
            
        } 
        */  
        
        utftext = utftext.replace(/%20/g,"+");   
        
        
        return utftext;  
    }  
    
// Results.js <- imported //

///////////////////////////
// Image Results
///////////////////////////



function ajaxCallImageSearch(strQuery, strOffset) {
    var elem = $get("s_action");
    var img_loading = $get("img_loading");
    
    elem.style.display = 'none';
    img_loading.style.display = 'block';
    
    //var strXArgs = getQueryVariable("xargs", strArgs);
    img_offset = img_offset + parseInt(strOffset);
    reVal = get_images.get_image_html(strQuery, strOffset, img_offset, OnCompleteImageSearch, OnTimeOutImageSearch, OnErrorImageSearch);
    return false;
    
}
                   
function OnCompleteImageSearch(value)
{
 
    var img_loading = $get("img_loading");
    img_loading.style.display = 'none';
    
    var elem = $get("s_action");
    elem.style.display = 'block';
    
    
    var lastResult = $get('search_results'+search_div_id);
    search_div_id = search_div_id + 1;
    
    var new_div = document.createElement('div');

    
    new_div.setAttribute('id','search_results'+search_div_id);
    //new_div.setAttribute('style','opacity:0');
    new_div.innerHTML = value;
    
    lastResult.appendChild(new_div);
    
    ScrollDown(500,1);
    

    
}

function OnTimeOutImageSearch(value)
{
    window.location = "/images/index.aspx?keywords="+strKeywords+"&offset="+img_offset+ "&js=no";   
}

function OnErrorImageSearch(value)
{
    window.location = "/images/index.aspx?keywords="+strKeywords+"&offset="+img_offset+ "&js=no";
}






////////////////////////////
// Video Results          //
////////////////////////////

function set_video_ajax(strSwf, strTitle)
{
    /* (non usercontrol version)
    var hiddenField = $get('hf_swf');
    var hiddenField2 = $get('hf_title');
    */
    
    var vid_ref_1 = $get('hd_hf_swf');
    var vid_ref_2 = $get('hd_hf_title');
    var ref_update_panel = $get('hd_update_video_panel');
    var update_panel = ref_update_panel.value;
    
    
    
    
    
    var hiddenField = $get(vid_ref_1.value);
    var hiddenField2 = $get(vid_ref_2.value);
    
    //alert("panel " + ref_update_panel.value + "<br/>ref1 " + hiddenField.value + "<br/>ref2 " +hiddenField2.value);
    
    if (hiddenField) {
        hiddenField.value = strSwf;
        if (hiddenField2)
        {
            hiddenField2.value = strTitle;
        }
        __doPostBack(update_panel,'');
        }
    return false;

}

function ajaxCallVideoSearch(strQuery, strNumResults, strPage) {
    var elem = "more_results";
         var lastResult = $get('search_results'+search_div_id); 
    
    var new_div = document.createElement('div');
    
    search_div_id = search_div_id +1; 
    
    new_div.setAttribute('id','search_results'+search_div_id);

    new_div.innerHTML = loading_html_message;
    
    lastResult.appendChild(new_div);
    //var strXArgs = getQueryVariable("xargs", strArgs);
    reVal = get_video.get_video_html(strQuery, strNumResults, strPage, true, OnCompleteVideoSearch, OnTimeOutVideoSearch, OnErrorVideoSearch);
    return false;
    
}

function ajaxCallVideoTopSearch()
{
    var elemName = $get('hd_box_id');
    var elem = $get(elemName.value);
    var text = elem.value;
    
    var encodetrimmed = html_encode(text);

    if (encodetrimmed.length > 0)
    {
        var elem = "more_results";
        var lastResult = $get('search_results'+search_div_id);
        lastResult.innerHTML = loading_html_message; //var strXArgs = getQueryVariable("xargs", strArgs);
        reVal = get_video.get_video_html(encodetrimmed, strNumResults, video_page_id, true, OnCompleteVideoSearch, OnTimeOutVideoSearch, OnErrorVideoSearch);
    }
    return(false);
   

}

function ajaxCallVideoChannel(strChannel) {
    var elem = "more_results"; 
     var lastResult = $get('search_results'+search_div_id);
     lastResult.innerHTML = loading_html_message;
    //var strXArgs = getQueryVariable("xargs", strArgs);
    reVal = get_video.get_video_channel(strChannel, OnCompleteVideoSearch, OnTimeOutVideoSearch, OnErrorVideoSearch);
    return false;
    
}
                   
function OnCompleteVideoSearch(value)
{  
    var lastResult = $get('search_results'+search_div_id);
        video_page_id = video_page_id + 1;
    /*search_div_id = search_div_id + 1;
    
    var new_div = document.createElement('div');*/
    
    
    //new_div.setAttribute('id','search_results'+search_div_id);
    //new_div.setAttribute('style','opacity:0');
    lastResult.innerHTML = value;
    
    //lastResult.appendChild(new_div);
    
}

function OnTimeOutVideoSearch(value)
{
    window.location = "/video/index.aspx?keywords="+strKeywords+"&page="+video_page_id+"&js=no";    
}

function OnErrorVideoSearch(value)
{
    window.location = "/video/index.aspx?keywords="+strKeywords+"&page="+video_page_id+"&js=no";
}

/////////////////
// News Search //
/////////////////



function ajaxCallNewsChannel(channel) {
    strchannel =channel;
    $get("news_container").innerHTML = loading_html_message

    reVal = get_news.get_news_by_channel(channel, OnCompleteNewsChannel, OnTimeOutNewsChannel, OnErrorNewsChannel);
    
    
    return false;
    
}                   
function OnCompleteNewsChannel(value)
{   
    $get("news_container").innerHTML = value;
    return false;
}


function OnTimeOutNewsChannel(value)
{
    window.location = "default.aspx?channel=" + strchannel;   
}

function OnErrorNewsChannel(value)
{
    window.location = "default.aspx?channel=" + strchannel;
}


function ajax_more_news(strQuery, results, start, language, headlineOnly) {
    $get("more_results").innerHTML = loading_html_message
    strKeywords = strQuery;
    strResults = results;
    strStart =start;
    strLanguage =language;
    strHeadlineOnly = headlineOnly;
    news_start = parseInt(start) + parseInt(results);
    reVal = get_news.get_news_html(strQuery, results, start, language, headlineOnly, OnCompleteNewsSearch, OnTimeOutNews, OnErrorNews);

    return(false)
    
} 

function OnCompleteNewsSearch(value)
{   
    if (strStart > 0)
    {
        var news_break = document.createElement('div');
        news_break.setAttribute('id','news_break'+search_div_id);
        news_break.innerHTML = "<div style='font-size:40px; text-align:center'>. . . .</div>";
    
    }
    
    var lastResult = $get('search_results'+search_div_id);
    search_div_id = search_div_id + 1;
    
    var new_div = document.createElement('div');
    
    
    new_div.setAttribute('id','search_results'+search_div_id);
    //new_div.setAttribute('style','opacity:0');
    new_div.innerHTML = value;
    
    if (strStart > 0)
    {
        lastResult.appendChild(news_break);
        
    }
    
    lastResult.appendChild(new_div);
    
    if (value.length > 400)
    {
     strHtml= "<a onclick=\"ajax_more_news('" + strKeywords+"', '" + strResults + "', '" + news_start + "', 'en', 'false'); return false\" href=\"index.aspx?keywords=" + strKeywords + "&start=" + news_start + "&js=no\">More News Stories</a>";
    }
    else
    {
        strHtml = "no more results";
    }
    
    $get("more_results").innerHTML = strHtml;
    
    if (strStart > 0)
    {
        ScrollDown(500,10);
    }
    return false;
}

/////////////////////////////
// Book Marking            //
/////////////////////////////

function g_bookmark_web(id)
{
    var g_title = $get("sh"+id);
    var g_description = $get("sd"+id);
    var g_host = $get("hl"+id);
    
    
    var g_urlstr = "?book_type=1&type=Web&url=" + encodeMyHtml(g_host.innerHTML) +"&title=" + encodeMyHtml(g_title.innerHTML) + "&desc=" + encodeMyHtml(g_description.innerHTML);
    
    //alert ("title = " + g_title.innerHTML + " <desc> = " + g_description.innerHTML + " <host> = " + g_host.innerHTML);
    var modal = $get("modal_box");
    modal.style.display = "block";
    
    var link = $get("hd_modal");
    
    //modal.innerHTML = "<iframe scrolling=\"no\" height=\"400px\" width=\"300px\" src=\"/iframe/add_bookmark.aspx"+g_urlstr+"\" />";
    
    modal.innerHTML = '' +
		'<div id="popupInner">' +
			'<div id="popupTitleBar">' +
				'<div id="popupTitle">Add Page Bookmark</div>' +
				'<div id="popupControls">' +
					'<img src="/assets/close.gif" onclick="close_modal_window();" id="popCloseBox" />' +
				'</div>' +
			'</div>' +
			"<iframe scrolling=\"no\" border=\"0\" frameborder=0 height=\"400px\" width=\"390px\" src=\"/iframe/add_bookmark.aspx"+g_urlstr+"\" />" +
		'</div>';
    
    $find(link.value).show();
    
}

function g_bookmark_image(id, url, title, thumb)
{
    var g_url = url;
    var g_title = title;
    var g_thumb = thumb;
    
    var g_urlstr = "?book_type=2&type=Image&url=" + encodeMyHtml(g_url) +"&thumb="+ encodeMyHtml(g_thumb) +"&title="+encodeMyHtml(title);
    
    var modal = $get("modal_box");
    modal.style.display = "block";
    
    var link = $get("hd_modal");
    
    //modal.innerHTML = "<iframe scrolling=\"no\" height=\"400px\" width=\"300px\" src=\"/iframe/add_bookmark.aspx"+g_urlstr+"\" />";
    
    modal.innerHTML = '' +
		'<div id="popupInner">' +
			'<div id="popupTitleBar">' +
				'<div id="popupTitle">Add Image Bookmark</div>' +
				'<div id="popupControls">' +
					'<img src="/assets/close.gif" onclick="close_modal_window();" id="popCloseBox" />' +
				'</div>' +
			'</div>' +
			"<iframe scrolling=\"no\" border=\"0\" frameborder=0 height=\"400px\" width=\"390px\" src=\"/iframe/add_bookmark.aspx"+g_urlstr+"\" />" +
		'</div>';
    
    $find(link.value).show();
}

function g_bookmark_news(id)
{
    var g_nh = $get("nh"+id);
    var g_url = g_nh.href
    var g_title = g_nh.innerHTML;
    var g_description = $get("ns"+id);
    
    var g_urlstr = "?book_type=1&type=Web&&url=" + encodeMyHtml(g_url) +"&title=" + encodeMyHtml(g_title) + "&desc=" + encodeMyHtml(g_description.innerHTML);
    
    var modal = $get("modal_box");
    modal.style.display = "block";
    
    var link = $get("hd_modal");
    
    
    modal.innerHTML = '' +
		'<div id="popupInner">' +
			'<div id="popupTitleBar">' +
				'<div id="popupTitle">Add Bookmark</div>' +
				'<div id="popupControls">' +
					'<img src="/assets/close.gif" onclick="close_modal_window();" id="popCloseBox" />' +
				'</div>' +
			'</div>' +
			"<iframe scrolling=\"no\" border=\"0\" frameborder=0 height=\"400px\" width=\"390px\" src=\"/iframe/add_bookmark.aspx"+g_urlstr+"\" />" +
		'</div>';
    
    $find(link.value).show();
    
}

function g_bookmark_video(url, thumb, title )
{
    var g_url = url;
    var g_title = title;
    var g_thumb = thumb;
    
    var g_urlstr = "?book_type=3&type=Video&url=" + encodeMyHtml(g_url) +"&thumb="+ encodeMyHtml(g_thumb) +"&title=" + encodeMyHtml(g_title);
    
    var modal = $get("modal_box");
    modal.style.display = "block";
    
    var link = $get("hd_modal");
    
    //modal.innerHTML = "<iframe scrolling=\"no\" height=\"400px\" width=\"300px\" src=\"/iframe/add_bookmark.aspx"+g_urlstr+"\" />";
    
    modal.innerHTML = '' +
		'<div id="popupInner">' +
			'<div id="popupTitleBar">' +
				'<div id="popupTitle">Add Video Bookmark</div>' +
				'<div id="popupControls">' +
					'<img src="/assets/close.gif" onclick="close_modal_window();" id="popCloseBox" />' +
				'</div>' +
			'</div>' +
			"<iframe scrolling=\"no\" border=\"0\" frameborder=0 height=\"400px\" width=\"390px\" src=\"/iframe/add_bookmark.aspx"+g_urlstr+"\" />" +
		'</div>';
    
    $find(link.value).show();
}

function close_modal_window()
{
    var modal = $get("modal_box");
    modal.innerHTML = "";
    
    var link = $get("hd_modal");
    $find(link.value).hide();
}

function g_play_video(url, title, img)
{
    var g_title = url;
    var g_host = title;
    
    var g_urlstr = "?book_type=3&type=Video&url=" + encodeMyHtml(g_title) +"&title=" + encodeMyHtml(g_host);
    
    var modal = $get("modal_box");
    modal.style.display = "block";
    
    var link = $get("hd_modal");
    
    //modal.innerHTML = "<iframe scrolling=\"no\" height=\"400px\" width=\"300px\" src=\"/iframe/add_bookmark.aspx"+g_urlstr+"\" />";
    
    modal.innerHTML = '' +
    '<div id="popupInner">' +
			'<div id="popupTitleBar">' +
				'<div id="popupTitle">'+global_str_video+'</div>' +
				'<div id="popupControls">' +
					'<img src="/assets/close.gif" onclick="close_modal_window();" id="popCloseBox" />' +
				'</div>' +
			'</div>' +  title +
			'<div id="flashcontent" style="text-align: center;">' +
'<embed id="movie_player" width="600" height="400" type="application/x-shockwave-flash" src="'+ url + '" name="movie_player" bgcolor="#FFFFFF" quality="high"/>' +
'</div>'+
		'</div>';

$find(link.value).show()
}

function g_play_video_list(vid)
{
    var vid_elem = $get("play_vid"+vid);
    vid_elem.innerHTML='<div id="flashcontent" style="text-align: center; clear:both">' +
    '<div id="popupControls">' +
					'<img src="/assets/close.gif" onclick="close_list_video(\''+vid+'\');" id="popCloseBox" />' +
				'</div>' +
'<embed id="movie_player" '+ detect_screen_width() + ' type="application/x-shockwave-flash" src="http://youtube.com/v/' + vid + '".swf" name="movie_player" bgcolor="#FFFFFF" quality="high"/>' +
'</div>'
     ScrollDown(200,1);   

}

function g_play_video_standalone(vid)
{
    var vid_elem = $get("search_results0");
    vid_elem.innerHTML='<div id="flashcontent" style="text-align: center; clear:both">' +  
'<embed id="movie_player" ' + detect_screen_width() +' type="application/x-shockwave-flash" src="' + vid + '" name="movie_player" bgcolor="#FFFFFF" quality="high"/>' +
'</div>'
     

}

function detect_screen_width()
{
    var s_width = screen.width;
    var n_width = 300;
    var n_height = 300;
    var n_html = "";
    
    if (s_width>1024)
    {
        n_width = 600;
        n_height = 500;
    }
    if (s_width>940 && s_width<=1024)
    {
        n_width = 460;
        n_height = 320;
    }
    
    if (s_width<940)
    {
        n_width = 300;
        n_height = 200;
    }
    
    
    n_html = ' width="'+n_width+'" height="'+n_height+'" ';
    return n_html;
}

function g_play_image(img, img_id)
{
    var vid_elem = $get("search_results0");
    vid_elem.innerHTML='<div id="image_slide" style="text-align: center; clear:both">' +  
    '<span class="nav_links"><a onclick="g_play_image_prev('+ img_id + ')">&lt;&lt;Prev</a>' +
    '<a href="/images/view.aspx?imgurl=' + img + '">View Original</a>'+
    '<a onclick="g_play_image_next('+ img_id + ')">Next>&gt;&gt</a></span>' +
    '<br />' +
'<img width="500" src="' + img + '"/>' + 
'</div>'
}

function g_play_image_next(img_id)
{
    var new_img_id = img_id+1;
    var img_elem = 'slide_'+new_img_id;
    
    if (document.getElementById(img_elem))
    {
        
        //get image
        var img_elem2 = $get(img_elem);
        
        var img_href = img_elem2.rel;


        //alert("found" + img_href);
        g_play_image(img_href, new_img_id);
    }
    else
    {
        
        img_elem = 'slide_0';
        //get image
        var img_elem2 = $get(img_elem);
        
        var img_href = img_elem2.rel;
        g_play_image(img_href, new_img_id);
    }

}



function g_play_image_prev(img_id)
{
    if (img_id>0)
    {
        var new_img_id = img_id-1;
        var img_elem = 'slide_'+new_img_id;
        
        if (document.getElementById(img_elem))
        {
            
            //get image
            var img_elem2 = $get(img_elem);
            
            var img_href = img_elem2.rel;


            //alert("found" + img_href);
            g_play_image(img_href, new_img_id);
        }
        else
        {
            
            img_elem = 'slide_0';
            //get image
            var img_elem2 = $get(img_elem);
            
            var img_href = img_elem2.rel;
            g_play_image(img_href, new_img_id);
        }
    }

}



function close_list_video(vid)
{
    var vid_elem = $get("play_vid"+vid);
    vid_elem.innerHTML="";
}

function encodeMyHtml(html) 
{
     var encodedHtml = escape(html);
     while (encodedHtml.indexOf(" ") > 0)
                {
                    encodedHtml = encodedHtml.replace("  ", " ");
                } 
     encodedHtml = encodedHtml.replace(/\//g,"%2F");
     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40");
     return encodedHtml;
} 







