var search_str="·j´M...";
//Menu{
var menu_close_timeout = 150;
var menu_close_timer = 0;
//Menu}

/*
window.onUnload=window.onBeforeUnload = function(){
   unloaded(); 
};*/

var is_unloaded=false;
var chk_unload_timeout;
function set_is_unloaded(){
   is_unloaded=true;
}

$(window).bind("beforeunload",function(){
   unloaded();
});


/*$(window).unload(function(){
   unloaded();
   chk_unload_timeout=window.setTimeout("chk_unloaded()",10);
   return false;
});*/

function getFlashMovie(movieName){
   return ($.browser.msie) ? window[movieName] : document[movieName];
}

function unloaded(){
    try{
      getFlashMovie('player').removedFromStage();
    }
    catch(ex){
    }
}

function close_menu(){
    $("#main_nav>li>div").css("visibility","hidden");
}

function set_close_menu_timer(){
    menu_close_timer = window.setTimeout(close_menu, menu_close_timeout);
}

function init_generals(){
   //window.onbeforeunload=function(){
   //   unloaded();
   //};
    //Menu{
    if($.browser.msie){
        if($.browser.version<7){
            $("#main_nav div").addClass("ie_less_than_7");
        }
    }
    $("#main_nav>li>a").mouseover(function(){
        var menu_item=$(this).parent().find("div");
        close_menu();
        menu_item.mouseover();
        menu_item.css("visibility","visible");
    });
    $("#main_nav>li>a").mouseout(function(){
	menu_close_timer = window.setTimeout(set_close_menu_timer, menu_close_timeout);
    });
    $("#main_nav>li>div").mouseover(function(){
//        $("#search_tf").val($("#search_tf").val()+"1");
	if(menu_close_timer){
	    window.clearTimeout(menu_close_timer);
            menu_close_timer = null;
	}
    });
    $("#main_nav>li>div").mouseout(function(){
        set_close_menu_timer();
    });
    //Menu}
    $.fn.getIndex=function(find_str){
        var $p=(find_str)?$(find_str):$(this).parent().children();
        return $p.index(this);
    };
    $("#search_form").submit(function (){
        var q=encodeURI(this.search_val.value)+" site:"+"radioicare.org";
        //var q=$(this).find('[name="search_val"]').val()+" site:"+"radioicare.org";
        window.open($(this).attr("action")+"?q="+q+"&ie=utf-8&oe=utf-8","_google");
        return false;
    });
    var search_tf = $("#search_tf");
    if(search_tf.val()==""){
        search_tf.val(search_str);
    }
    search_tf.mouseover(function(){
        if($(this).val()==search_str){
            $(this).val("");
        }
        $(this).focus();
    });
    search_tf.mouseout(function(){
        if($(this).val()==""){
            $(this).val(search_str);
        }
        //$(this).blur();
    });

    $("#search_btn").click(function(){
        $("#search_form").submit();
    });

    set_program_player();//player.js
}

function play_program(pid){
    try{
        getFlashMovie('player').addtoFront(pid);
    }
    catch(ex){
        alert("EX:"+ ex);
    }
}

function get_url_part(){
  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 results[1];
}
//Player Function{
function gen_swf(swf_setting,player_container_id){
    var so = new SWFObject(swf_setting['src'], swf_setting['id'], swf_setting["width"], swf_setting["height"], "10");
    so.addParam("quality", "high");
    //so.addParam("wmode", "opaque");
    so.addParam("wmode", "transparent");
    so.write(player_content_id);
    /*var str='';
    str+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2"';
    str+='  width="'+swf_setting['width']+'" height="'+swf_setting['height']+'" id="'+swf_setting['id']+'" align="">';
    str+='  <param name="movie" value="'+swf_setting['src']+'">';
    str+='  <param name="wmode" value="transparent">';
    str+='  <embed src="'+swf_setting['src']+'" quality="high"';
    str+='  width="'+swf_setting['width']+'" height="'+swf_setting['height']+'" name="'+swf_setting['id']+'" align="" wmode="transparent"';
    str+='  type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
    str+='  </object>';
    return str;*/
}

function gen_wmp(mplayer_setting){
    var str="";
    str+='<object id="'+mplayer_setting['id']+'"';
    str+='codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
    str+='type=application/x-oleobject width="'+mplayer_setting['width']+'" height="'+mplayer_setting['height']+'"  align=absmiddle';
    str+='classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95>';
    str+='<param name="FileName" value="'+mplayer_setting['src']+'">';
    str+='<param name="ShowControls" value="1">';
    str+='<param name="ShowStatusBar" value="1">';
    str+='<param name="ShowDisplay" value="0">';
    str+='<param name="DefaultFrame" value="Slide">';
    str+='<param name="PlayCount" value='+(mplayer_setting['loop']?0:1)+'>';
    str+='<param name="Loop" value='+(mplayer_setting['loop']?1:0)+'>';
    str+='<param name="Autostart" value="'+mplayer_setting['auto_start']+'">';
    str+='<embed';
    str+='    id="'+mplayer_setting['id']+'_embed"';
    str+='    src="'+mplayer_setting['src']+'" width="'+mplayer_setting['width']+'" height="'+mplayer_setting['height']+'"';
    str+='    autostart="'+mplayer_setting['auto_start']+'"';
    str+='    loop="'+(mplayer_setting['loop']?1:0)+'" PlayCount="'+(mplayer_setting['loop']?0:1)+'"';
    str+='    align="absmiddle" type="application/x-mplayer2"';
    str+='    pluginspage="http://www.microsoft.com/Windows/MediaPlayer/download/default.asp"';
    str+='    showcontrols="1" showdisplay="0" showstatusbar="1" > </embed>';
    str+='</object>';
    return str;
}

function gen_qt(mplayer_setting){
    var str='';
    if(!$.browser.msie){
        str+='        <object ';
        str+='          id="'+mplayer_setting['id']+'"';
        str+='          data="'+mplayer_setting['src']+'" width="'+mplayer_setting['width']+'" height="'+mplayer_setting['height']+'" type="video/quicktime">';
        str+='        <param name="pluginurl" value="http://www.apple.com/quicktime/download/" />';
        str+='        <param name="controller" value="true" />';
        str+='        <param name="autoplay" value="'+mplayer_setting['auto_start']+'" />';
        str+='        loop="'+(mplayer_setting['loop']?1:0)+'" PlayCount="'+(mplayer_setting['loop']?0:1)+'"';
        str+='        </object>';
    }
    else{
        str+='<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
        str+='    id="'+mplayer_setting['id']+'"';
        str+='    codebase="http://www.apple.com/qtactivex/qtplugin.cab"';
        str+='    width="'+mplayer_setting['width']+'" height="'+mplayer_setting['height']+'">';
        str+='    <param name="src" value="'+mplayer_setting['src']+'" />';
        str+='    <param name="autoplay" value="'+mplayer_setting['auto_start']+'" />';
        str+='    <param name="pluginspage" value="http://www.apple.com/quicktime/download/" />';
        str+='    <param name="controller" value="true" />';
        str+='</object>';
    }
    return str;
}
//Player Function}

//Plugin Detect{
// initialize global variables
var detectableWithVB = false;
var pluginFound = false;


function goURL(daURL) {
    // if the browser can do it, use replace to preserve back button
    /*if(javascriptVersion1_1) {
	window.location.replace(daURL);
    } else {
	window.location = daURL;
    }*/
    window.location = daURL;
    return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) ||
	(!pluginFound && !redirectIfFound)) ) {
	// go away
	goURL(redirectURL);
	return pluginFound;
    } else {
	// stay here and return result of plugin detection
	return pluginFound;
    }
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Director');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectQuickTimeActiveXControl();
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media Player');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin

// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}
//Plugin Detect}

