//jQuery OnLoad Function
$(document).ready(function () {
    
        
    
    //Update Sitefinity Search Button.
    if ($('.sf_searchSubmit').length) { $('.sf_searchSubmit').attr('value','GO');  }

    //Check to see if product Menu is on this Page.
    if ($('#firstpane').length) { loadInternalMenu(); }
    
    //Check to see if we want to show the DHTML Banner
	if ($('#slider').length) { loadDHTMLBanner(); }	
	
	if ($('#contentDocumentsWrapper').length) 
	{ 	    
	    if (gbl_LoadTags == true) //Set dyanmically in "ProductPage"
	    {	    
	        //Used to hide non-used tabs.
	        $("#contentDocumentsWrapper ul.tablist li a span").each(function (i) 
	        {
	            var childTabElement = $(this); 

	            if (this.innerHTML == "")
	            {
	                childTabElement.css('display', 'none');	         
	            }

	        })
    	        	    
	        $('#contentDocumentsWrapper').tabs(); 
	    }
	}
	
	if ( $('#youtubeDiv').length != 0 && channelID != "")
	{
        
        
        insertVideos({'block':'youtubeDiv','type':'playlist','q':channelID,'results':'20','order':'new_first','player':'link','imgstyle':'3px solid' });
        
         
        
    }
    else{
        $("a.iframe").fancybox({'width':800, 'height':650, 'overlayColor':'#000' });
    }


});


$(function(){

    var config = {    
         sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
         interval: 200,  // number = milliseconds for onMouseOver polling interval    
         over: doOpen,   // function = onMouseOver callback (REQUIRED)    
         timeout: 200,   // number = milliseconds delay before onMouseOut    
         out: doClose    // function = onMouseOut callback (REQUIRED)    
    };
    
    function doOpen() {
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    }
 
    function doClose() {
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    }

/*
    $("ul.dropdown li").hoverIntent(config);
    
    $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
*/

});







/* Used on pages with an Internal Menu */
function loadInternalMenu()
{

    $("#firstpane a.menu_head").click(function()
    {		
        $(this).css({}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
        $('a.menu_head').removeClass('selected');
        $(this).addClass('menu_head selected');
    })
    
    var staticURL = location.href;

	if (staticURL.lastIndexOf('//'))
	{
		var relativeURL = staticURL.substr(staticURL.lastIndexOf('//') + 2, staticURL.length);
		relativeURL = relativeURL.substr(relativeURL.indexOf('/'), relativeURL.length);
	}
	    	
	if (staticURL.lastIndexOf('#') > 0)
    {
        if (relativeURL.length > 0)
        {
            relativeURL = relativeURL.substr(0, relativeURL.lastIndexOf('#'));
        }
        else
        {
            var relativeURL = relativeURL.substr(0, relativeURL.lastIndexOf('#'));
        }
        
        staticURL = staticURL.substr(0, staticURL.lastIndexOf('#'));
    }
          
    $('div.menu_body a').each(function() 
	{	    
	    if ($(this).attr('href') == relativeURL || $(this).attr('href') == staticURL)
	    {
	        $(this).addClass("activePage");
	                    
            $(this).parent("div").prev('a.menu_head').css({}).next("div.menu_body").slideToggle(1).siblings("div.menu_body").slideUp("fast");
            $(this).parent("div").prev('a.menu_head').removeClass('selected');
            $(this).parent("div").prev('a.menu_head').addClass('menu_head selected');
	    }
	}
	)
    
}

function loadDHTMLBanner()
{
	// Banner Slider 
	////////////////////////////////////////////////////////////////////////////////////////////////////////////

    var $panels = $('#slider .scrollContainer > div');
    var $container = $('#slider .scrollContainer');

    // if false, we'll float all the panels left and fix the width 
    // of the container
    var horizontal = true;

    // float the panels left if we're going horizontal
    if (horizontal) {
        $panels.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });

        // calculate a new width for the container (so it holds all panels)
        $container.css('width', $panels[0].offsetWidth * $panels.length);
    }

    // collect the scroll object, at the same time apply the hidden overflow
    // to remove the default scrollbars that will appear
    var $scroll = $('#slider .scroll').css('overflow', 'hidden');

    // apply our left + right buttons
    $scroll
        .before('')
        .after('');

    // handle nav selection
    function selectNav() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('bannerSelected')
                .end()
            .end()
            .addClass('bannerSelected');
    }

    $('#slider .navigation').find('a').mouseover(selectNav);

    // go find the navigation link that has this target and select the nav
    function trigger(data) {
        var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
        selectNav.call(el);
    }

    if (window.location.hash) {
        trigger({ id : window.location.hash.substr(1) });
    } else {
        $('ul.navigation a:first').mouseover();
    }

    // offset is used to move to *exactly* the right place, since I'm using
    // padding on my example, I need to subtract the amount of padding to
    // the offset.  Try removing this to get a good idea of the effect
    var offset = parseInt((horizontal ? 
        $container.css('paddingTop') : 
        $container.css('paddingLeft')) 
        || 0) * -1;


    var scrollOptions = {
        target: $scroll, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: $panels,

        navigation: '.navigation a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'img.left', 
        next: 'img.right',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 350,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };

    // apply serialScroll to the slider - we chose this plugin because it 
    // supports// the indexed next and previous scroll along with hooking 
    // in to our navigation.
    $('#slider').serialScroll(scrollOptions);

	/*
    // now apply localScroll to hook any other arbitrary links to trigger 
    // the effect
    $.localScroll(scrollOptions);

    // finally, if the URL has a hash, move the slider in to position, 
    // setting the duration to 1 because I don't want it to scroll in the
    // very first page load.  We don't always need this, but it ensures
    // the positioning is absolutely spot on when the pages loads.
    scrollOptions.duration = 1;
    $.localScroll.hash(scrollOptions);
	*/
}
