/* define a new shortcut for jQuery to prevent conflict with Prototype */
$j = jQuery.noConflict();

/* define the CLIENT NAME object to avoid conflicts with any third party code */
var LAU = {};

/* define all configurable variables used for the CLIENT NAME site */
LAU.vars = {
	/* camelCase naming convention */
	shareItObj:null
};


function setWatermark(element) {
    element.className = 'textalt';
};

/* define all reusable functions for the CLIENT NAME site */
LAU.functions = {
	/* camelCase naming convention */

	/*
	* Enables tab with id _tabId
	*/
	activateTab: function(_tabId) {

		// activate the tab button
		$j('div.tabs div.header ul li').removeClass('active');
		$j('div.tabs div.header ul li').each(function(){
			if($j('a', this).attr('href') == _tabId) {
				$j(this).addClass('active');
				// TODO: how do we break out?			
			}
		});

		// enable tab content
		$j('div.tabs div.body > div').removeClass('active');
		$j('div.tabs div.body > div#' + _tabId).addClass('active');
	},
	
	/*
	* Adds corners to elements
	*/	
	addCorners: function() {
		$j('div.rounded').append('<div class="tl"><\/div><div class="tr"><\/div><div class="bl"><\/div><div class="br"><\/div>');
	}
};

/* jQuery DOMdocument.ready */
$j(document).ready(function() {

    /* HTML; add HTML to the page that is not content. this HTML either purely decorative, or purely functional (requiring JS to work). */

    /*
    * Let CSS know JS is enabled
    */
    $j('#container').removeClass('noJS');

    /*
    * Add .first, .last to LIs
    */
    $j('ul li:first-child').addClass('first');
    $j('ul li:last-child').addClass('last');

    /*
    * This is for the first element in the Search Results
    * Note: this will be removed in the future to use the above
    */
    $j('#searchResultCes > div:first-child > span:first-child > div:first-child').addClass('first');

    /*
    * Network logo slideshow
    */
    var con = $j('.networkLogos');
    var ctr = $j('.networkLogos .controls');
    //ctr.css("left", ((con.width() / 2) - (ctr.width() / 2)));
    
    ctr.css("left", 320);

    /*
    * Rounded Corners 
    */
    LAU.functions.addCorners();
    $j('.wrapper.withContentNavBg, .wrapper.withContentRelatedBg').append('<div class="te"></div><div class="be"></div>');

    /*
    * Wrap HR with DIV tags to stylize it
    */
    $j('hr').wrap('<div class="hr"></div').remove();


    /*
    * Add icons to links
    */

    $j('a.jump, ul.jump a').append('<span class="icon"></span>')

    /* Interactions; define the intereactive components of the page. */


    /*
    * Search field hint
    */

    var search = '#navSearch input.text';

    // hide when focus is on	
    $j(search).focus(function() {
        $j('label', $j(this).parent()).css('display', 'none');
    });

    // show when blur
    $j(search).blur(function() {
        $j('label', $j(this).parent()).css('display', ($j(this).val() == '') ? 'block' : 'none');
    });

    // hide if there is any text in field
    if ($j(search).val() != '') {
        $j('label', $j(search).parent()).css('display', 'none');
    }

    /*
    * Tabs
    */

    // add click functionality to tabs
    $j('div.tabs div.header ul li a').click(function() {
        LAU.functions.activateTab($j(this).attr('href'));
        $j(this).blur();
        return false;
    });

    // activate the first tab
    LAU.functions.activateTab("#t1");


    /*
    * Tree menu
    */

    $j('.tree').treeview({
        animated: 'fast',
        collapsed: true,
        persist: 'location'
        //unique: true			
    });

    // hightlight selected area
    $j('.tree a.selected').parents('li:first').addClass('active');

    /*
    * Feature slideshow
    */

    $j('.slideshow .content').cycle({
        fx: 'fade',
        speed: 'slow',
        timeout: 8000,
        pause: true,
        pager: '.slideshow .controls ul',
        pagerAnchorBuilder: function(id) {
            return '<li><a href="#"><span></span></a></li>';
        }
    });

    $j('.slideshow .controls a').click(function() {
        $j(this).blur();
    });

    $j('.slideshow .controls > a').click(function() {
        if ($j(this).hasClass('pause')) {
            $j('.slideshow .content').cycle('resume');
            $j(this).removeClass('pause');
            $j(this).addClass('play');
        }
        else {
            $j('.slideshow .content').cycle('pause');
            $j(this).removeClass('play');
            $j(this).addClass('pause');
        }
        return false;
    });

    /*
    * Logos slideshow
    */

    $j('.networkLogos .content').cycle({
        fx: 'scrollHorz',
        speed: 1000,
        timeout: 8000,
        pause: true,
        next: '.networkLogos .controls .next',
        prev: '.networkLogos .controls .previous',
        pager: '.networkLogos .controls ul',
        pagerAnchorBuilder: function(id) {
            return '<li><a href="#"><span></span></a></li>';
        }
    });

    $j('.networkLogos .controls a').click(function() {
        $j(this).blur();
    });

    /*
    * Enable print button
    */
    $j('div.pageTools div.print a').click(function() {
        window.print();
        return false;
    });

    /*
    * Enable Go back button
    */
    $j('div.pageTools div.back a').click(function() {
        history.back();
    });

    /*
    * Enable customized SharedThis button
    */

    if ($j('#shareIt').length > 0) {
        LAU.vars.shareItObj = SHARETHIS.addEntry({}, { button: false });
        LAU.vars.shareItObj.attachButton(document.getElementById('shareIt'));
    }


    /* Visual Clean-Up; help non standards-based browsers render the page properly. */


    // ie 6 drop-down support & ie 6/7/8 dropshadows
    if ($j.browser.msie) {
        $j('div#navMain > ul > li:not(.a6, .active)').hover(function() {
            $j(this).addClass('hover');
            //$j('span', this).textShadowRemove()						
        }, function() {
            $j(this).removeClass('hover');
            //LAU.functions.addTextShadow($j('span', this));										
        });

        // Make the tree menu visible
        $j('div.tree').removeClass('hidden');
        $j('div.tree').addClass('show');
    }


    // initialise
    var element = $j('input.text');
    
    if (element[0] != null) {
        //setWatermark(element[0]);
        element[0].onfocus = function() { setWatermark(element[0]); };
        element[0].onblur = function() { if (element[0].value == '') element[0].className = 'text'; };

        if (element.captureEvents) element.captureEvents(Event.CLICK);
    }

});

function SearchButton_onClientClick(ctrl) {
    document.getElementById(ctrl).value = document.getElementById(ctrl).value.replace(/^\s*|\s*$/g, "");
    if (document.getElementById(ctrl).value == "")
        return false;
    else
        return true;
};

document.onkeyup = KeyCheck;
function KeyCheck() {
    var KeyID = event.keyCode;
    switch (KeyID) {
        case 13:
            if (SearchButton_onClientClick('ctl01_ctl00_SearchBox')) {
                document.getElementById('ctl01_ctl00_SearchButton').click();
            }
            break;
    }
}




