
/// <reference path="../scripts/jquery-1.3.2-vsdoc2.js" />

// Desktop radar
function openWindow(newURL, width, height)
{
	newWindow = window.open(newURL, 'newWin', 'toolbar=no,location=no,scrollbars=no,width=' + width + ',height=' + height)
};

function openWindowScroll(newURL, width, height)
{
	newWindow = window.open(newURL, 'newWin', 'toolbar=no,location=no,scrollbars=yes,width=' + width + ',height=' + height)
};	

// Forms with dates/times
function popCal(fieldref)
{
    window.open('/scripts/popup_calendar.asp?jsfieldname=' + fieldref, 'calWin', 'menubar=no,toolbar=no,scrolling=no,height=250,width=300,');
};

function popTime(fieldref)
{
    window.open('/scripts/popup_time.asp?jsfieldname=' + fieldref, 'calWin', 'menubar=no,toolbar=no,scrolling=no,height=250,width=300,');
};

// Form validation
function validate_tags(source, args)
{
	var theValue;
	theValue = args.Value.toLowerCase();
	
	if ((theValue.match(/<a /)) || (theValue.match(/<img /)) || (theValue.match(/<script /)) || (theValue.match(/<object /)))  {
	     args.IsValid = false;
         return;
     }
     else {
     	args.IsValid = true;
     }
};

// SEARCH IMAGE BG
function searchClickOn() {
    $("#searchTerm").css({ background: "white" });   
};

function searchClickOff() {
    if ($("#searchTerm").val() == ''){
        $("#searchTerm").css({ background: "#FFFFFF url(/images/navigation/navtop-google.gif) left no-repeat" });
    }    
};

function searchSubmit() {
    var re = /[\~\\,\/\*\-\+<>=;'@%\(\)\{\}\[\]\|&\?\$"]/g; 
    $("#searchTerm").val($("#searchTerm").val().replace(re, " "));
};

// MAKE THIS SITE HOME PAGE
function makeStationYourHomePage(stationName,url) {
    if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(window.location.href);
    }
};

// Pencil pop-overs
function ClickDivOn ()
{
    var pencilIn
    pencilIn = document.getElementById("pencilAd").style.height = "300px";
};

function ClickDivOff ()
{
    var pencilIn   
    pencilIn = document.getElementById("pencilAd").style.height = "31px";     
};

// Pop-overs/Push-Downs
function bICookie(searchCookieValue) {  // cookie and ads, preRoll
    var name = 'bIdayCookie';
    
    var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
		{   		    
		    var bIcookieValues = c.substring(nameEQ.length,c.length);
		    var cookieArray = new Array();
		        
		       cookieArray = bIcookieValues.split('&'); // split to each name=value
		       
		    var strArray;
		    var cookieValuesArray = new Array();
		    
		    for ( strArray in cookieArray )
		    {
		        cookieValuesArray = cookieArray[strArray].split('=')
		        
		        if ( cookieValuesArray[0] == searchCookieValue )
		        {
		            return cookieValuesArray[1];
		        }
		    }
		    
		    return 1;
        } 
	}
	return "noCookie";
};

// WebVision
function ClosePlayer()
{
    document.getElementById("preRollOuter").style.height = 30 + "px";
}

function rePlay()
{       
    var movieName = "RMembed";
    document.getElementById("preRollOuter").style.height = 250 + "px";
    document.getElementById(movieName).Play();       
};        
 
function PreRollPlayer(flv,duration,client_url)
{   
    var movieName = "RMembed";
    var player = "/includes/players/player.swf";
    var play = "false";
    var durationCookie = bICookie("duration_preRoll");
    var wmode = navigator.appName.indexOf("Microsoft Internet") == -1 ? "opaque" : "" ;
    
    if ( durationCookie > 0 ) { document.getElementById("preRollOuter").style.height = 250 + "px"; play = "true"; }
    
    swfobject.embedSWF(player + "?file=" + flv + "&duration=" + duration + "&clientUrl=" + client_url, "preRollInner", 296, 238, "9.0.0", false, null, {menu:"false",quality:"high",play:play,wmode:wmode,bgcolor:"#FFFFFF"}, {id:movieName,name:movieName});
};

//Navigation menu scripts
$(document).ready(function() {
    var navTopSection = $(".navTopSection");
    var navTopBox = $("#navTopBox")
    var navTopLowerBar = $("#navTopLowerBar");
    var navTopSubLinks = $("#navTopSubLinks");
    var navTopSubLinksHtml = navTopSubLinks.html();
    var navTopSubLinksClass = navTopSubLinks.attr("class");
    var navOnTimeDelay = 500; //controls the hover display speed
    var navOffTimeDelay = 300; //controls the unhover display speed
    var navOffTimeDelayAfterClick = 30000;
    var navTopTimerId; //stores the timer
    
    //click: section link
    $("#navTopSectionLinks A").click(function(event){
        clearTimeout(navTopTimerId);
        navOffTimeDelay = navOffTimeDelayAfterClick; 
        navOnTimeDelay = 0;
        showSelectedSection($(this));
    }); 
    
    //hover: over sections EXCEPT the currently selected section
    $("#navTopSectionLinks A:not(navTopSection)").hover(
        //Mouse Over event
        function(event){ 
            clearTimeout(navTopTimerId); 
            var element = $(this);
            navTopTimerId = setTimeout(function(){
                showSelectedSection(element);        
            }, navOnTimeDelay);
        },
        
        //Mouse leave event
        function(event){
        }
    );
        
    //hover: current section
    navTopSection.hover(
        //Mouse Over Default event
        function(event){ 
            clearTimeout(navTopTimerId); 
            navTopTimerId = setTimeout(showCurrentSection, navOnTimeDelay);
        }, 
        
        //Mouse leave event
        function(event){
        }
    );
        
    //click: subsection link
    $("#navTopSubLinks A").click(function(event){
        subsectionClick.apply(this);
    }); 

    //mouseleave: the menu container will show default links after a delay
    navTopBox.bind("mouseleave", function(event){
        clearTimeout(navTopTimerId); 
        navTopTimerId = setTimeout(showCurrentSection, navOffTimeDelay);
    });
        
    //mouseover: resets the timeout if the user accidently leaves the menu
    navTopLowerBar.bind("mouseover", function(event){
        clearTimeout(navTopTimerId);
    });

    var showCurrentSection = function() {
        $(".navTopSection").removeClass("navTopSection");
        navTopSection.addClass("navTopSection");
        navTopSubLinks.removeClass().addClass(navTopSubLinksClass).html(navTopSubLinksHtml);
        if ($(".navTopSubsection").length > 1) navTopSection.removeClass("navTopSubsection");
    };
    
    var showSelectedSection = function(element) {
        $(".navTopSubsection").removeClass("navTopSubsection");
        navTopSection.addClass("navTopSubsection");
        $(".navTopSection").removeClass("navTopSection");
        element.addClass("navTopSection");
     
        var section = bINav_sections[element.attr("id")];                
        var markup = [];
        for (var i = 0; i < section.subsections.length; i++) {
            markup[i] = "<a href=\""+section.subsections[i].href+"\" target=\""+(section.subsections[i].target?section.subsections[i].target:"_top")+"\""+(section.subsections[i].title?" title=\""+section.subsections[i].title+"\"":"")+">"+section.subsections[i].text+"</a>";
        }
        $("#navTopSubLinks A").unbind("click");
        navTopSubLinks.removeClass().addClass(section.cssClass).html(markup.join(section.linkSeparator));
        $("#navTopSubLinks A").click(function(event){
            clearTimeout(navTopTimerId);
            subsectionClick.apply(this);
        }); 
    };

    var subsectionClick = function() {
        navOffTimeDelay = navOffTimeDelayAfterClick;
        $(".navTopSubsection").removeClass("navTopSubsection");
        $(this).addClass("navTopSubsection");
    };

});

function bIShareUploadLoader(anchor, base) {

    // One time only, never return here again once thickbox is loaded;
    $(anchor).removeAttr('onclick');
    
    // Do setup for thickbox
    $(anchor).addClass("thickbox");

    // Load thickbox, and when loaded, fire the click handler it installed
    $('HEAD').queue(function() {
        var loader = new YAHOO.util.YUILoader({
            onSuccess: function() { $('HEAD').dequeue(); $(anchor).click(); }
        });
        loader.addModule({
            name: 'cssShareUpload',
            type: 'css',
            fullpath: base + '/css/thickbox.css'
        });
        loader.addModule({
            name: 'jsShareUpload',
            type: 'js',
            fullpath: base + '/Javascript/jquery.thickbox.js',
            requires: ['cssShareUpload']
        });
        loader.require('jsShareUpload');
        loader.insert();
    });

    // disable default action (i.e., don't link to the href here, let thickbox do it!)
    return false;
}