/**
 * Bind the site search panel's button to submit the search
 * (The button is outside the form)
 * 
 */
function bindSearch()
{
	// $j('globalsearchbutton').click(function() {
	// 	Alert("Site Search In Progress...");
	// 	submitSearch();
	// });
}

function submitSearch()
{
	// $j('searchsiteform').submit();
}

function cleanUpFontTags()
{
	var font = $j('font');
	$j.each(font, function(){
		
		var content = $j(this).html();
		$j(this).replaceWith(content);
		
	});
}

function renderSkinnableSelects()
{
    $j('.my-skinnable-select').each(
      function(i) {
        selectContainer = $j(this);
        // Remove the class for non JS browsers
        selectContainer.removeClass('my-skinnable-select');
        // Add the class for JS Browers
        selectContainer.addClass('skinned-select');
        // Find the select box
        selectContainer.children().before('<div class="select-text">&nbsp;</div>').each(
          function() {
            $j(this).prev().text(this.options[0].innerHTML);
          }
        );
        // Store the parent object
        var parentTextObj = selectContainer.children().prev();
        // As we click on the options
        selectContainer.children().click(function() {
          // Set the value of the html
          parentTextObj.text(this.options[this.selectedIndex].innerHTML);
        });        
      }
    );
}

/**
 * Create the superfish menu
 */
function configureMenu()
{
	var column = $j('html body div.main div.main_resize div.slider_main div#minimap');
	var block = $j('html body div.main div.main_resize div.slider_main div#minimap div');
		
	if(column != null && block != null){
		column.css('width','160px');
		block.css('line-height','2em');
	}	
	
	$j("ul.sf-menu").bgiframe().superfish({
		animation: {height:'show'},   // slide-down effect without fade-in
		delay:     1400,              // 1.4 second delay on mouseout
		autoArrows: true,
		dropShadows: false
	});
}

/**
 * Many thanks go to:
 * 
 * http://www.vancelucas.com/blog/fixing-ie7-z-index-issues-with-jquery/
 * 
 * For fixing the issues with ie 6 and 7 without this our menu would end up
 * underneath the slide show
 * 
 * Both of these versions of the dirge render elements in
 * LIFO mode: Last in - First out
 * Meaning that elements further down the page will always appear above
 * elements at the top of the page. A far lesser use case scenario which
 * has wasted millions of pounds of man hours and kept developers awake till
 * the witching hour for many years.
 * 
 */
function thwartInternetExplorer6and7()
{
	var zIndexNumber = 20000;
	$j('div').each(function() {
		$j(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
}

/**
 * Get the slideshow up and running
 */
function configureSlideShow()
{
	$j('#slideshow').cycle({
		fx:     'fade',
		speed:  'slow',
		timeout: 4500,
		pager:  '#slider_nav',
		pagerAnchorBuilder: function(idx, slide) {
			// return sel string for existing anchor
			return '#slider_nav li:eq(' + (idx) + ') a';
		}
	});
}


/**
 * Slideshow Version 2 (Not is use yet)
 */
function configureSlideShow2(){

	var is_image_loaded = function(img) {
	    // IE
	    if(!img.complete) {
	        return false;
	    }
	    // Others
	    if(typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
	        return false;
	    }
	    return true;
	};

	var first_slide = $j('#slideshow img:first');
	if(is_image_loaded(first_slide.get(0))) {
	    $j('#slideshow').cycle();
	} else {
	    first_slide.load(function(e) {
	        $j('#loading').hide();
	        $j('#slideshow').show().cycle();
	    });
	    $j('#slideshow').hide();
	    // I'll handwave the display of a loading indicator, since
	    // it's covered in the tutorial linked in the question.
	    $j('#loading').show();
	}
}

