﻿//// functions

var hash = location.hash;



// call overlay
function CallOverlay(url){
    var api = $j("#overlay").overlay({api: true}); 
    api.onBeforeLoad(function(){
        this.getContent().find(".contentWrap").html("");
        $j('#overlay').removeClass(); 
        $j('#overlay').addClass("overlay"); 
        var wrap = this.getContent().find(".contentWrap"); 
        wrap.load(url); 
    });
    api.load();
    api.unbind("onBeforeLoad");
};

// call spot overlay
function CallSpotOverlay(url){
    var api = $j("#overlay").overlay({api: true}); 
    api.onBeforeLoad(function(){
        this.getContent().find(".contentWrap").html("");
        $j('#overlay').removeClass(); 
        $j('#overlay').addClass("overlay OverlaySpotOverlay"); 
        var wrap = this.getContent().find(".contentWrap"); 
        wrap.load(url); 
    });
    api.load();
    api.unbind("onBeforeLoad");
};



// Print Page
function PrintPage(){
    // remove vml
    $j("ignore").remove();
    window.print();
}

//// dom ready elements
$j(function(){
   
    // setup ul.tabs to work as tabs for each div directly under div.panes
    $j("#tvpage-subnav").tabs("div.pane");
    
    // overlay
    
    $j(".overlay").overlay({ 
        expose: '#000000', 
        target: '#overlay', 
        onBeforeLoad: function() { 
            // clean up
            var wrap = this.getContent().find(".contentWrap");
            wrap.html("");
            // pause evt videos playing
            $j("#ContainerFlowplayerMultiLoop").flowplayer().each(function(){this.pause();});
            $j('#overlay').removeClass(); 
            $j('#overlay').addClass("overlay");    
            // grab wrapper element inside content 
            var wrap = this.getContent().find(".contentWrap"); 
            // load the page specified in the trigger 
            wrap.load(this.getTrigger().attr("href")); 
        },
        onClose: function() {
            this.getContent().find("a.flowplayer").flowplayer().each(function (i) {this.stop()})
        }
    });
    
    // split overlay
    $j(".SplitOverlay").overlay({ 
        expose: '#000000', 
        target: '#overlay', 
        onBeforeLoad: function() { 
            this.getContent().find(".contentWrap").html("");
            $j('#overlay').removeClass(); 
            $j('#overlay').addClass("overlay SplitOverlay");    
            // grab wrapper element inside content 
            var wrap = this.getContent().find(".contentWrap"); 
            // load the page specified in the trigger 
            wrap.load(this.getTrigger().attr("href")); 
        },
        onClose: function() {
            this.getContent().find("a.flowplayer").flowplayer().each(function(i){this.stop();});
            $j('#overlay').removeClass("SplitOverlay");  
        }
    });
    
    // accordion
    $j('#content .accordion h2').click(
        function(){
            $j(this).parent().find('.pane:visible').slideUp('normal', function(){$j(this).prev('h2').removeClass("current");}).end().end().next('.pane:hidden').slideDown('normal');
            if ($j(this).parent().find('.pane:visible').length > 0) {
                $j(this).addClass("current"); 
            } else {
                $j(this).removeClass("current"); 
            }
        }
    ); 
    
    if(hash != ""){
        // accordion
        $j("#content .accordion h2[anchor='" + hash +"']").click();
    }
    
    // initialize scrollable 
	$j("div.scrollable").scrollable({ vertical:true, size: 3}).mousewheel();
    
    // site search
    $j(".sitesearch input").focus(function(){
        $(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){this.value = '';}
	});
	
	// initiate ArticleVideoOverlay & ArticleFlashOverlay
    $j("a.ArticleVideoOverlay, a.ArticleFlashOverlay").overlay({
        expose: '#000000', 
        target: '#overlay',
        onBeforeLoad: function() {
            this.getContent().find(".contentWrap").html("");
            $j('#overlay').removeClass(); 
            $j('#overlay').addClass("VideoOverlay");
            // grab wrapper element inside content
            var wrap = this.getContent().find(".contentWrap"); 
            // load the page specified in the trigger - added callback to start video
            wrap.load(this.getTrigger().attr("href"),function(){var video = $j("#overlay .flowplayer").attr("id");$f(video).play();}); 
        },
        onClose: function() {
            this.getContent().find("a.flowplayer").flowplayer().each(function(i){this.stop();});
        }
    });
	
	// initiate spotoverlay
    $j("a.SpotOverlay").overlay({
        expose: "#000000", 
        target: "#overlay", 
        onBeforeLoad: function() {
            this.getContent().find(".contentWrap").html("");
            $j('#overlay').addClass("OverlaySpotOverlay");  
            //this.getContent().append("<div class=\"SpotContent\"></div>");
            var wrap = this.getContent().find(".contentWrap"); 
            wrap.load(this.getTrigger().attr("href"));
        },
        onClose: function() {
            $j('#overlay').removeClass("SpotOverlay");  
        }
    }); 
    
    // initiate PacketOverlay
    $j("a.PackageOverlay").overlay({ 
        expose: '#000000', 
        target: '#overlay', 
        onBeforeLoad: function() { 
          var wrap = this.getContent().find(".contentWrap"); 
            wrap.html("");
            $j('#overlay').removeClass(); 
            $j('#overlay').addClass("overlay");    
            var wrap = this.getContent().find(".contentWrap"); 
            wrap.load(this.getTrigger().attr("href")); 
        }
    }); 
    

});
