var hideTimer, fadeTimer;
var _appRoot = "";

if (typeof $ != "undefined") {
    $(document).ready(function() {
        $("a[rel=InlineFlvPlayer]").each(function() { replaceLinkWithFlashPlayer(this); });
    });
}

function chkSearchValue(input) {
    if (input.value == input.defaultValue) { input.value = ''; }
    else if (input.value == '') { input.value = input.defaultValue; }
}

function searchHilite(btn, hilite) {
    btn.src = _appRoot + '/images/static/' + (hilite ? 'cmdGoOver.gif' : 'cmdGo.gif');
}

function onSearchSubmit(searchForm, evt) {    
    var f = searchForm.elements["q"];
    if (f.value == f.defaultValue) { cancelEvent(evt); return false; }    
}
function cancelEvent(e) {
    if (e.returnValue) { e.returnValue = false; e.cancelBubble = true; }
    if (e.preventDefault) { e.preventDefault(); e.stopPropagation(); }
}


// PREVENT ERROR MESSAGES
try { window.onerror = function() { return false; } } catch (e) { }


function youtube_popup(id, w, h) {
    if (w == null) { w = 560; }
    if (h == null) { h = 340; }    
    var url = 'http://www.youtube.com/v/' + id + '&hl=en&fs=1&rel=0&color1=0x111111&color2=0x444444';
    var html = '<embed src="' + url + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + w + '" height="' + h + '"></embed>';

    doHtmlPopup(html,null, null, '#000');
}

function flv_popup(url, w, h, dummy) {
    if (w == null) { w = 560; }
    if (h == null) { h = 340; }

    var playerHtml= '<embed src="' + _appRoot + '/script/flv_player/player_flv_maxi.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + w + '" height="' + h + '"'
             + ' FlashVars="flv=' + escape(url) + '&amp;autoplay=1&amp;margin=0&amp;videobgcolor=000000&amp;volume=75&amp;showstop=1&amp;showvolume=1&amp;showtime=1&amp;showfullscreen=1"></embed>';

    doHtmlPopup(playerHtml, null, null, '#000');    
}

function replaceLinkWithFlashPlayer(anchor) {
    $img = $("img", anchor);

    var w = $img.width();
    var h = $img.height();

    if (w == null) { w = 400; }
    if (h == null) { h = 300; }

    var imgPath = escape($img.attr('src'));

    var url = escape(anchor.href);

    var html = '<embed src="http://www.laerdal.com/script/flv_player/player_flv_maxi.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + w + '" height="' + h + '"'
             + ' FlashVars="flv=' + url + '&amp;startimage=' + imgPath + '&amp;showplayer=autohide&amp;showiconplay=1&amp;autoplay=0&amp;margin=4&amp;playercolor=000000&amp;bgcolor1=d0d0d0&amp;bgcolor2=808080&amp;videobgcolor=ffffff&amp;volume=100&amp;showstop=1&amp;showvolume=1&amp;showtime=1&amp;showfullscreen=1&amp;"></embed>';

    $(anchor).replaceWith(html);
}


function doHtmlPopup(popupHtml, w, h, bgColor) {

    var args = {};

    if (h || w) { 
        popupHtml = '<div style="' + (w ? 'width:' + w + ';' : '') + (h ? 'height:' + h + ';' : '') + '">' + popupHtml + '</div>';
    }

    args["content"] = popupHtml;

    if (bgColor) {
        args['onStart'] = function() { $("#fancybox-outer").css('backgroundColor', bgColor); }
        args['onCleanup'] = function() { $("#fancybox-outer").css('backgroundColor', ''); }
    }

    $.fancybox(args);    
}

function openPopup(url, w, h, cssClass) {
    var args = { href: url, type: 'iframe' };
    
    if (w) { args["width"] = w; }
    if (h) { args["height"] = h; }

    $.fancybox(args);    
}

function slideshow3() {
    $("a[rel=SlideShow]:first").click();
}   
function setLanguage(lang) {
    window.location.href="?setLang=" + lang;
}

function closePopup() {
    $.fancybox.close();
}




