/*!
	Site:		CreativeLynx Structure
	Author:		CreativeLynx http://creativelynx.co.uk/
------------------------------------------------------------*/

/*	Global Configuration
----------------------------------------------- */
var $j = jQuery;
var isIE = false;
var isIE6 = false;
var isSafari = false;

/*	Plugins
----------------------------------------------- */

/*	Global Literal Object: Site-wide functions
----------------------------------------------- */
var SGlobal = {

	/* Configuration, Flags and Messages */

	/* jQuery Object References  */
	jEOBody: null,
	jEOPrintPage: null,
	jEOPrintPageLoc: null,
	jEONavPrimary: null,

	/* Utility: Browser Tests / Specific Fixes/Hooks */
	utilBrowserTests : function() {

		if ($j.browser.msie) { isIE = true; }

		/* Detect if User Agent is IE6 using object detection, apply fix for background flicker bug */
		if (typeof document.body.style.maxHeight == 'undefined') { isIE6 = true; try { document.execCommand('BackgroundImageCache', false, true); } catch(e) { } }

		/* Detect if User Agent is Safari, add class '.safari' to div#Container */
		if ($j.browser.safari) { isSafari = true; $j('div#Wrapper').addClass('safari'); }

	},

	/* Utility: Print Page */
	utilPrintPage : function() {

		var cc = this;

		cc.jEOPrintPage = $j('<li><a href="#PrintPage" title="Print this page">Print Page</a></li>');
/*		cc.jEOPrintPageLoc = $j('#Footer ul li.first');*/

		/* Insert cc.jEOPrintPage to cc.jEOPrintPageLoc */
		cc.jEOPrintPageLoc.before(cc.jEOPrintPage);
		$j('a', cc.jEOPrintPage).click(function() {
			window.print();
			return false;
		});

	},

	/* NavPrimary Events: Workaround for li:hover IE */
	eventsNavPrimary : function() {

		var cc = this

		$j('li', cc.jEONavPrimary).hover(function() {
			$j(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});

	},
	
//	contentResize : function(){
//		/*
//		 * Loops through a given set of elements, detects which has the greatest height
//		 * and then then resizes all to suit.
//		 */
//		var cc = this;
//		var _interval;
//		var _elementsToCheck = [ '.l-c' ];
//		
//		/* Run the resizer on page load */
//		resizer();
//		
//		/* Clear any old interval data and start the resizer to repeat on interval */
//		if(window._interval) { window.clearInterval(_interval); }
//		_interval = window.setInterval(function(){
//			resizer();
//		});
//		
//		function resizer(){
//			var _greatestHeight = 0;
//			/* Loop through elements and find which has the greatest height */
//			$j(_elementsToCheck).each(function(k,v){
//				$j(v).each(function(kk,vv){
//					if( $j(vv).height() > _greatestHeight ){
//						_greatestHeight = $j(vv).height();
//					}
//				});
//			});
//			/* Set the height of all elements to match the height of the biggest element */
//			$j(_elementsToCheck).each(function(k,v){
//				$j(v).css({height: _greatestHeight + 'px' });
//			});
//		}
	//},

	init : function() {

		var cc = this;

		/* ADD class to body so we can apply CSS only for when jQuery is available, different to hasJS */
		cc.jEOBody = $j('body');
		cc.jEOBody.addClass('hasjQ');
		
		cc.utilBrowserTests();
		
		$j(window).load(function(){
			/*
			 * Wait for all images to load before resizing content areas
			 */
			//cc.contentResize();
		});
/*

		cc.jEONavPrimary = $j('#NavPrimary');
		if (cc.jEONavPrimary.length) {
			cc.eventsNavPrimary();
		}
*/

		/* If print support is available, initialise utilPrintPage */
		if (window.print & cc.jEOPrintPageLoc) { cc.utilPrintPage(); }

	}

};


//Clear search box on focus
function clearSearch() {
    $(".search").focus(function () {
        if (this.value == this.defaultValue) {
            this.value = "";
        }
    }).blur(function () {
        if (!this.value.length) {
            this.value = this.defaultValue;
        }
    });
};

$(document).ready(function () {
    $('.form1').bind('submit', function () {
        var encodedversion = htmlEncode($('#<%=m_SearchTextBox.ClientID%>').val());
        $('#<%=m_SearchTextBox.ClientID%>').val(encodedversion);
    });
});

function htmlEncode(value) {
    return $('<div/>').text(value).html();
}

function htmlDecode(value) {
    return $('<div/>').html(value).text();
}



/*	DOM Ready events
----------------------------------------------- */
$j(function () {

    SGlobal.init();
    clearSearch();
   
});

