(function($){


// ===== Date Elements ===============================================================================
	var aMonth = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'];
	var aDay = ['SUNDAY','MONDAY','TUESDAY','WEDNESDAY','THURSDAY','FRIDAY','SATURDAY'];
	
	Date.prototype.getDateOffset = function(offset) {
		var newDate = new Date(this);
		var day = 24 * 60 * 60 * 1000; // total milliseconds per day;
		newDate.setTime(newDate.getTime()+offset*day);
		return newDate;
	};

// ===== TRAY - Tabs: Schedules / Shows / Login / Investors ==================================================
	$.fn.globalTray = function(options){
		// extend our default options with those provided
		var $options = $.extend({}, $.fn.globalTray.defaults, options);
		$options.tray.data('open',false);
		
		$options.tray.append('<a href="#" class="close-btn"><img src="http://outdoorchannel.com/images/btn_close_globaltray.png" title="Close"></a>');
		$options.tray.find('a.close-btn').click(function(e){
			e.preventDefault();
			$options.tray.stop().animate({'marginTop':$options.tray.outerHeight()*-1},{duration:750, easing:'easeInOutQuad'});
			$('#trayTabs li').removeClass('selected');
			$options.tray.data('open',false);
			$options.header.empty();
			$options.content.empty();
		});
		
		return this.each(function(i, item) {
			var $this = $(this);
			// ~~~~~ cache elements ~~~~~ 
			var $parent = $this.parent('li');
			var bkgdPosLeft = $(this).css('backgroundPosition').split(" ")[0];
			
			$this.click(function(e){
				e.preventDefault();
				$options.container.removeClass().addClass('trayContainer '+$this.attr('class'));
				if($parent.hasClass('selected')){
					$options.tray.stop().animate({'marginTop':$options.tray.outerHeight()*-1},{duration:750, easing:'easeInOutQuad'});
					$parent.removeClass('selected');
					$options.tray.data('open',false);
					$options.header.empty();
					$options.content.empty();
				} else {
					if(!$options.tray.data('open')){
						$options.tray.stop().animate({'marginTop':0},{duration:750, easing:'easeOutQuad', complete:function(){ $(this).data('open',true); switchTray(); }});
						//switch background
						
						$parent.siblings('.selected').removeClass('selected');
						/*$parent.delay(250, function(){$(this).addClass('selected')});*/
						$parent.addClass('selected');
					} else {
						$parent.siblings('.selected').removeClass('selected')
						$parent.addClass('selected');
						switchTray();
					};
				};
			});
			
			var pathname = window.location.pathname.toLowerCase();
			var parentContent = $parent[0].innerHTML.toLowerCase();
			
		});
		
		function switchTray(){
			// ~~~~~ reset ~~~~~ 
			$options.header.empty();
			$options.content.empty();
			//this is where facebook/twitter icons are to be added.
			$options.header.html('<img class="label" src="http://outdoorchannel.com/images/blank.gif" height="35" alt="" /><span class="socialnetworks"></span>');
			//*****************************
			// ~~~~~ switch ~~~~~ 
			if($options.container.hasClass('schedule')){
				$options.tray.traySchedule();
			} else if($options.container.hasClass('shows')){
				$options.tray.trayShows();
			} else if($options.container.hasClass('register')){
				$options.tray.trayRegister();
			} else if($options.container.hasClass('investors')){
				$options.tray.trayInvestors();
			}else if($options.container.hasClass('newsletter')){
				$options.tray.trayNewsletter();
			};
		};
	};
	
	// default option
	$.fn.globalTray.defaults = {
		container: $('.trayContainer', $('#globalTray')),
		tray: $('#trayContent'),
		header:$('.header', $('#trayContent')),
		content:$('.content', $('#trayContent'))
	};
	
// ===== TRAY: Schedules ==================================================
	$.fn.traySchedule = function(options){
		// extend our default options with those provided
		var $options = $.extend({}, $.fn.traySchedule.defaults, options);
		
		
		return this.each(function() {							
			var $this = $(this);
			// ~~~~~ cache elements ~~~~~ 
			var $header = $this.find('.header');
			var $content = $this.find('.content');
			// ~~~~~ header ~~~~~ 
			$header.find('img.label').attr('src','http://outdoorchannel.com/images/tray_label_schedule.png').hide().fadeIn('slow');
			var days = [];
			var today = new Date();
			for(var x=0;x<7;x++){
				var date = today.getDateOffset(x);
				var day = aDay[date.getDay()];
				var img = '<li><a href="#" class="'+day.substr(0,3).toLowerCase()+'"><span>'+day+'</span></a></li>';
				days[days.length] = img;
			};
			$header.append('<ul class="days">'+days.join('')+'</ul><div class="arrow"></div>');
			
			var cat = '<div class="category right">Choose a Category <select><option selected>Show All</option>';
			cat = cat + '<option>Hunting</option><option>Fishing</option><option>Shooting</option><option>Off-Road</option><option>Adventure</option>';
			cat = cat + '</select><br/>';
			$header.append(cat);
			var dayTabs = $('ul.days li a', $header);
			dayTabs.each(function(){
				$(this).css('backgroundPosition',(($(this).width()/2)-6.5) + "px -15px");
			}).click(function(e){
				selectDay(this);
				e.preventDefault();
			});
			var html = '\
				<div id="scrollContainer">\
					<div id="scrollArea"><div class="scrollContent Scroller-Container">\
					<table cellspacing="0">\
						<colgroup width="60"></colgroup>\
						<colgroup width="249"></colgroup>\
						<colgroup width="88"></colgroup>\
						<colgroup width="127"></colgroup>\
						<tbody></tbody>\
					</table>\
					</div></div><!-- end: #scrollArea -->\
					<div id="Scrollbar-Container" class="scrollbar">\
						<img id="up" class="Scrollbar-Up" src="http://outdoorchannel.com/images/scroll_up.gif" width="22" height="16" alt="" />\
						<img id="down" class="Scrollbar-Down" src="http://outdoorchannel.com/images/scroll_down.gif" width="22" height="16" alt="" />\
						<div id="track" class="Scrollbar-Track">\
							<img id="drag" class="Scrollbar-Handle" src="http://outdoorchannel.com/images/scroll_drag.gif" width="22" height="16" alt="" />\
						</div>\
					</div>\
				</div><!-- end: #scrollContainer -->\
				<div class="tray_tout" id="schedule_tray_tout"></div>\
				<div class="scheduleLink"><a href="http://outdoorchannel.com/Schedule.aspx">Full Schedule</a> | <a href="http://outdoorchannel.com/ProgramGuide/">Program Guide</a> | <a href="http://outdoorchannel.com/ProgramBlocks.aspx">Program Blocks</a></div>\
				<div class="scheduleLink" style="margin-left:380px;"><a href="http://www.outdoorchannel.com/International.aspx">Non-U.S. Schedule</a></div>\
			';
			$content.html(html).addClass('preload');
			//$("#schedule_tray_tout").load("http://outdoorchannel.com/GetHtmlContent.ashx?name=/DefaultAds/Schedule/ScheduleTrayTout&type=collection");
			$("#schedule_tray_tout").html('<iframe src="http://outdoorchannel.com/GetHtmlContent.ashx?name=/DefaultAds/Schedule/ScheduleTrayTout&type=collection&render=iframe" width="279" height="176" frameborder="0" allowTransparency="true" scrolling="no"></iframe>').hide().fadeIn('slow');
			$options.table = $('#scrollArea').find('table');					
					
			// ~~~~~ schedule ~~~~~
			
            $options.data = scheduleFeedJSON;
            $header.find('select').change(function(){
				var selected = $(this).find(':selected').val().toLowerCase();
				if (selected == "Off-Road"){
				    selected = "OffRoad";
				}
				$options.table.find('tr').removeClass('even').each(function(){
					var genre = $('td:eq(2)',$(this)).text().toLowerCase();
					(selected == "show all" || selected == genre)? $(this).show() : $(this).hide();
				});
				$('#scrollArea table tr.empty').remove();
				var visibleRows = $options.table.find('tr:visible');
				if(visibleRows.length < 8){
					var rows = (8 - visibleRows.length);
					for(var x = 0; x < rows; x++){
						$('#scrollArea table tbody').append('<tr class="empty"><td><a>&nbsp;</a></td><td></td><td></td><td></td></tr>');
					};
				};
				$options.table.find('tr:visible:odd').addClass("even");
			});
			// ~~~~~ init ~~~~~
			$content.removeClass('preload');
			selectDay(dayTabs.eq(0));
	
	        $.getCachedScript('http://outdoorchannel.com/js/Scrolling.Scroller_min.js',function(){
		        $.getCachedScript('http://outdoorchannel.com/js/Scrolling.Scrollbar_min.js',function(){
			        $options.scroller  = new Scrolling.Scroller(document.getElementById("scrollArea"), 598, 176);
			        $options.scrollbar = new Scrolling.Scrollbar(document.getElementById("Scrollbar-Container"), $options.scroller, new Scrolling.ScrollTween());
		        })											  
	        });		
			
			function selectDay(day){
				var $parent = $(day).parent('li');
				var $parentActive = $parent.siblings('.selected');
				var $left = $(day).css('backgroundPosition').split(" ")[0];
				// ~~~~~ reset ~~~~~
				if($parentActive.length){
					var $leftActive = $('a', $parentActive).css('backgroundPosition').split(" ")[0];
					$('a', $parentActive).stop().animate({backgroundPosition:"("+$leftActive+" -15px)"}, {duration:600, easing: 'easeOutBounce'});
					$parentActive.removeClass('selected');
				};
				// ~~~~~ select ~~~~~
				$parent.addClass('selected');
				$(day).stop().animate({backgroundPosition:"("+$left+" 6px)"}, {duration:600, easing: 'easeOutBounce'})
				buildSchedule($(day).text());
				if($options.scrollbar) $options.scrollbar.reset();
			};
			
			function buildSchedule(day){
				$('#scrollArea table tbody').empty();
				// ~~~~~ shows ~~~~~
				var genres = $options.data.Genres;
				var days = eval('$options.data.Days.'+day.toLowerCase()+'');
				var shows = days.Shows;
				var aSchedule = [];
				for(var x = 0, xl = shows.length; x < xl; x++){
					var genre = $(shows[x])[0].genreId;
					if ($(shows[x])[0].title == 'Paid Programming'){
					    var aShow = [
						    '<td class="time">'+$(shows[x])[0].t+'</a></td>',
						    '<td><a href="#">'+$(shows[x])[0].title+'</td>',
						    '<td>&nbsp;</td>',
						    '<td>&nbsp;</td>'
					    ];
					} else {
					    var aShow = [
						    '<td class="time">'+$(shows[x])[0].t+'</td>',
						    '<td><a href="'+$(shows[x])[0].href+'" title="'+$(shows[x])[0].eT+' - '+$(shows[x])[0].eD+'">'+$(shows[x])[0].title+'</a></td>',
						    '<td><a href="'+$(shows[x])[0].genreURL+'" title="'+$(shows[x])[0].genreName+'">'+$(shows[x])[0].gN+'</a></td>',
						    //'<td>&nbsp;</td>'
						    ($(shows[x])[0].pUrl != "")?'<td><a href="'+$(shows[x])[0].pUrl+'">Buy DVD</a></td>' : (($(shows[x])[0].new =="true") ? '<td><a href="/NewShows.aspx">New This Quarter</a></td>' : '<td>&nbsp;</td>'),
						    //'</tr><tr><td colspan="4" style="padding-left:35px;"><strong>'+$(shows[x])[0].episodeTitle+'</strong><p style="margin:2px 0px 0px 0px;">'+$(shows[x])[0].episodeDescription+'</p></td>'
					    ];  
					}
					aSchedule[aSchedule.length] = '<tr>'+aShow.join('')+'</tr>';
				};
				$('#scrollArea table tbody').append(aSchedule.join(''));
				$("#scrollArea table tr:odd").addClass("even");
				$header.find('select').trigger('change');
				if($options.scrollbar) $options.scrollbar.reset();
			};
		});					
	};
	
	// default option
	$.fn.traySchedule.defaults = {
		data: null,
		table: null,
		scroller: null,
		scrollbar: null,
		parser: '/getScheduleJSon.aspx'
	};
				


// ===== TRAY: Shows ==================================================
	$.fn.trayShows = function(options){
		// extend our default options with those provided
		var $options = $.extend({}, $.fn.trayShows.defaults, options);
		
		return this.each(function() {
			var $this = $(this);
			// ~~~~~ cache elements ~~~~~ 
			var $header = $this.find('.header');
			var $content = $this.find('.content');
			var aShowsList = []; // shows container;
			var aShowsSearchList = [];//search results matches - 
			var nColumns = 0; // starting column;
			var maxPerColumn = 10; // items per column;
			var maxColumnHeight = 190;
			// ~~~~~ pagination ~~~~~
			var nPrevIndex = 0;
			var nNextIndex = 0;
			var numNEXT = -1;
			var numPREV = -1;
			// ~~~~~ header ~~~~~ 
			$header.find('img.label').attr('src','http://outdoorchannel.com/images/tray_label_shows.png').hide().fadeIn('slow');
			var selectHtml = '<div class="category">Choose a Category <select><option selected>Show All</option></select></div>',
				searchHtml = '<div class="search"><input type="text" name="episodes" value="Find a show" class="findShow" /><a href="#" class="submit"><img src="http://outdoorchannel.com/images/btn_submit_search.png" width="31" height="21" alt="" /></a></div>';
			$header.append(selectHtml+searchHtml);
            $header.find('.search').append('<ul id="keywordList"></ul>');
			$header.find('input:text').focus(function(){
				if(this.value == this.defaultValue) this.value = "";
			}).blur(function(){
				if(this.value == "") this.value = this.defaultValue;
			}).keydown(function(e){
				if (e.keyCode == 13) {
					//eval($('#find_team a:first').attr('href'));
					e.preventDefault();
				};
			});
			// ~~~~~ content ~~~~~
			var html = '\
				<div class="showsContainer">\
					<div class="search_PREV" title="previous"></div>\
					<div class="shows-listings"><ul><li></li></ul></div>\
					<div class="search_NEXT" title="next"></div>\
				</div>\
				<div class="tray_tout" id="shows_tray_tout"></div>\
				<div class="showsLink"><a href="http://www.outdoorchannel.com/Shows.aspx">All Shows</a> | <a href="http://www.outdoorchannel.com/ProgramGuide/">Program Guide</a></div>\
				<div class="scheduleLink" style="margin-left:380px;"><a href="http://www.outdoorchannel.com/International.aspx">Non-U.S. Schedule</a></div>\
			';
			$content.html(html);
			//$("#shows_tray_tout").load("http://outdoorchannel.com/GetHtmlContent.ashx?name=/DefaultAds/Shows/ShowsTrayTout&type=collection");
			$("#shows_tray_tout").html('<iframe src="http://outdoorchannel.com/GetHtmlContent.ashx?name=/DefaultAds/Shows/ShowsTrayTout&type=collection&render=iframe" width="279" height="176" frameborder="0" allowTransparency="true" scrolling="no"></iframe>').hide().fadeIn('slow');
			$options.table = $('#trayContent').find('li');
			$options.visibleWidth = $options.table.parent('ul').outerWidth();
			// ~~~~~ pagination ~~~~~
			var btnPREV = $this.find('div.search_PREV');
			var btnNEXT = $this.find('div.search_NEXT');
			btnPREV.bind('click',{'dir':'prev'},pagination).css({'opacity':0.25,'cursor':'default'});
			btnNEXT.bind('click',{'dir':'next'},pagination).css({'opacity':0.25,'cursor':'default'});
			// ~~~~~ shows ~~~~~
		//	$.getJSON('http://outdoorchannel.com/getShowJSon.aspx?callback=jsonCallback', function(xml) {
			
					aShowsList = showFeedJSON.Shows;
					//aShowsList.sort(sortXml);
					aShowsSearchList = aShowsList;
					$options.data = showFeedJSON ;
					$options.total = aShowsList.length;
					// ~~~~~ genre ~~~~~
					var genreXML = showFeedJSON.Genres;
					var aOptions = [];
					$.each(genreXML, function (i, genre) {
					    if (i == "OffRoad"){
						    i = "Off-Road";
						}
                        aOptions[aOptions.length] = '<option value="'+genre.gId+'">'+i+'</option>';
                    });

					// ~~~~~ <select> functionality ~~~~~
					$header.find('select').append(aOptions.join('')).change(function(){
						var selected = $(this).find(':selected').val().toLowerCase();
						if (selected == "Off-Road"){
						    selected = "OffRoad";
						}
						aShowsList = [];
						if(selected == 'show all'){
							aShowsList = showFeedJSON.Shows;
						} else {
							aShowsList = winnerjQuery.grep(showFeedJSON.Shows,
							     function(a){
							        if (a.genreId == selected){
							            return a;
							        }
							     });
						};					
						$('#globalTray .search input:text').val("Find a show");
						//aShowsList.sort(sortXml);
						aShowsSearchList = aShowsList;
						// ~~~~~ reset ~~~~~
						nColumns = 0;
						$options.table.empty();
						$options.current = 0;
						$options.total = aShowsList.length;
						// ~~~~~ init ~~~~~
						createColumn(0);
						resetNav();
					});
					// ~~~~~ init ~~~~~
					createColumn(0);
					resetNav();
					$.fn.trayShows.data = aShowsList;
					// ~~~~~~ filter ~~~~~
					var timeout;
					$('#globalTray .search input:text').keyup(function() {
					    var searchText =  $('#globalTray .search input:text').val();
					    if ((searchText != "Find a show")&&(searchText != "")){
                            window.clearTimeout(timeout);
			                timeout = window.setTimeout(function () {
				                 /*if (searchText.length > 3){*/keywordSearch(aShowsList, searchText);/*}*/
			                }, 200);
			            }
                    });
				
		//	});
			$.fn.trayShows.filterList = function(aData){
				aShowsSearchList =aData;
				// ~~~~~ reset ~~~~~
				nColumns = 0;
				$options.table.empty();
				$options.current = 0;
				$options.total = aShowsList.length;
				// ~~~~~ init ~~~~~
				createFilteredColumn(0);
				resetNav();
			};
			
			function arrayUniq(a) 
			{
                var rval = [];
                var kTitle = [];
                                
                for( var i = 0; i < a.length; i++ ) 
                {
                    var aTitle = a[i].getAttribute("sorttitle");
                    if( jQuery.inArray(aTitle, kTitle) == -1 ) 
                    {
                        rval.push(a[i]);
                        kTitle.push(aTitle);
                    };
                };
                return rval;                
            };
			
			//function sortXml(a,b)
//			{
//			    var aa = a;
//			    var bb = b;
//			    // a.attributes[2] = sorttitle
//                return ((a.attributes[2].value < b.attributes[2].value) ? -1 : ((a.attributes[2].value > b.attributes[2].value) ? 1 : 0));
//			};
			function keywordSearch(data, keyword){
			    keyword = keyword.toLowerCase(); 
			    var matchArray = [];
			    //loop through each item in the data ans check the "sorttitle" attribute agains the keywords entered
			    for (var i = 0; i < data.length; i ++) {
			        var title = $(data[i]).attr("sorttitle").toLowerCase(); 
				    if (title.indexOf(keyword) != -1) {
					    matchArray[matchArray.length] = data[i];
				    }
			    }
			    //this will redraw the tray shows with only matched ones there
			    $.fn.trayShows.filterList(matchArray);
			};
			function createFilteredColumn(index){
			    var aList = [];
				var total = (index+maxPerColumn < aShowsSearchList.length)? index+maxPerColumn : aShowsSearchList.length;
				if(index >= total) return;
				// ~~~~~ 1) fill list with maximum items ~~~~~~
				for(var x = index, xl = total; x < xl; x++){
				    if ( $(aShowsSearchList[x]).attr('sorttitle') != 'Paid Programming') {
					aList[aList.length] = '<li><a href="http://outdoorchannel.com'+$(aShowsSearchList[x]).attr('href')+'" rel="'+$(aShowsSearchList[x]).attr('genreId')+'">'+$(aShowsSearchList[x]).attr('sorttitle')+'</a></li>';
				    }
				};
				// ~~~~~ 2) verify height to max height ~~~~~~
				$options.table.append('<ul class="resize">'+aList.join('')+'</ul>');
				var column = $options.table.find('ul:eq('+nColumns+')');
				if(nColumns%3 == 0){
					$options.table.find('ul:eq('+nColumns+')').css('backgroundImage','none');
				};
				// ~~~~~ 3) if height greater, remove until less than max height ~~~~~~
				while(column.height() > maxColumnHeight){
					column.find('li:last').remove();
					--x;
				};
				
				nColumns++;
				column.removeClass('resize');
				// ~~~~~ resize container to fit columns ~~~~~
				$options.table.css('width',nColumns*178);
				$options.totalColumns = Math.ceil(nColumns / 3)-1;
				// ~~~~~ repeat until all shows are displayed ~~~~~
				if(index < total-1) createFilteredColumn(x);
			}
			function createColumns(index){
			
			}
			function createColumn(index){
				var aList = [];
				var total = (index+maxPerColumn < $options.total)? index+maxPerColumn : $options.total;
				if(index >= total) return;
				// ~~~~~ 1) fill list with maximum items ~~~~~~
				for(var x = index, xl = total; x < xl; x++){
				    if ( $(aShowsList[x]).attr('sorttitle') != 'Paid Programming') {
					aList[aList.length] = '<li><a href="http://outdoorchannel.com'+$(aShowsList[x]).attr('href')+'" rel="'+$(aShowsList[x]).attr('genreId')+'">'+$(aShowsList[x]).attr('sorttitle')+'</a></li>';
				    }
				};
				// ~~~~~ 2) verify height to max height ~~~~~~
				$options.table.append('<ul class="resize">'+aList.join('')+'</ul>');
				var column = $options.table.find('ul:eq('+nColumns+')');
				if(nColumns%3 == 0){
					$options.table.find('ul:eq('+nColumns+')').css('backgroundImage','none');
				};
				// ~~~~~ 3) if height greater, remove until less than max height ~~~~~~
				while(column.height() > maxColumnHeight){
					column.find('li:last').remove();
					--x;
				};
				
				nColumns++;
				column.removeClass('resize');
				// ~~~~~ resize container to fit columns ~~~~~
				$options.table.css('width',nColumns*178);
				$options.totalColumns = Math.ceil(nColumns / 3)-1;
				// ~~~~~ repeat until all shows are displayed ~~~~~
				if(index < total-1) createColumn(x);
			};
			
			
			
			function resetNav(){
				$($options.table).css('left',0);
				// ~~~~~ next ~~~~~
				if($options.current == $options.totalColumns){
					btnNEXT.css({'opacity':0.25,'cursor':'default'});
				} else {
					btnNEXT.css({'opacity':1,'cursor':'pointer'});
				};
				// ~~~~~ prev ~~~~~
				if($options.current == 0){
					btnPREV.css({'opacity':0.25,'cursor':'default'});
				} else {
					btnPREV.css({'opacity':1,'cursor':'pointer'});
				};
			};
			
			function pagination(evt){
				var p = 0;
				if(evt.data.dir == 'next'){
					if($options.current == $options.totalColumns) return;
					$options.current = ($options.current >= $options.totalColumns) ? $options.totalColumns : $options.current+1;
				} else {
					if($options.current == 0) return;
					$options.current = ($options.current <= 0) ? 0 : $options.current-1;
				};	
				p = ($options.current*$options.visibleWidth*-1);
				$($options.table).animate({ left:p }, {duration:350});
				resetNav();
			};
			
		});
	};
	
	// default option
	$.fn.trayShows.defaults = {
		data: null,
		table: null,
		parser: 'http://outdoorchannel.com/GetShowsXml.aspx',
		total: 0,
		current: 0,
		visibleWidth: 0,
		totalColumns: 0
	};
	
	
	
// ===== TRAY: Register ==================================================
	$.fn.trayRegister = function(options){
		// extend our default options with those provided
		var $options = $.extend({}, $.fn.trayRegister.defaults, options);
		
		return this.each(function() {
			var $this = $(this);
			// ~~~~~ cache elements ~~~~~ 
			var $header = $this.find('.header');
			var $content = $this.find('.content');
			// ~~~~~ header ~~~~~ 
			$header.find('img.label').attr('src','http://outdoorchannel.com/images/tray_label_register.png').hide().fadeIn('slow');
			//*********************************** #426
			
			//***********************************		
			//$content.load('globalTray_login_content.html','',function(){ $content.hide().fadeIn('slow') });
			$content.html('<iframe src="http://outdoorchannel.com/globalTray_login_content.html"  width="900" height="185"  frameborder="0" allowTransparency="true" scrolling="no"></iframe>').hide().fadeIn('slow');	
			// the following line of code can be uncommented when facebook/twitter icons are to be added.  Will need 
			// to uncomment in the css the line for #trayContent .header a.community.  The image size that it
			// is styled for are 32x32-ish.
			//$header.find('.socialnetworks').load("http://outdoorchannel.com/GetHtmlContent.ashx?name=/Generic/TrayCommunityHeader");	
			$header.find('.socialnetworks').html('<iframe src="http://outdoorchannel.com/GetHtmlContent.ashx?name=/Generic/TrayCommunityHeader&render=iframe" width="450" height="50" frameborder="0" allowTransparency="true" scrolling="no"></iframe>').hide().fadeIn('slow');	
							
		});				
	};	
	
	// default option
	$.fn.trayRegister.defaults = {
		//
	};
	
// ===== TRAY: Investors ==================================================
	$.fn.trayInvestors = function(options){
		// extend our default options with those provided
		var $options = $.extend({}, $.fn.trayInvestors.defaults, options);
		
		return this.each(function() {
			var $this = $(this);
			// ~~~~~ cache elements ~~~~~ 
			var $header = $this.find('.header');
			var $content = $this.find('.content');
			// ~~~~~ header ~~~~~ 
			$header.find('img.label').attr('src','http://outdoorchannel.com/images/tray_label_investors.png').hide().fadeIn('slow');
			$content.html('<iframe src="http://phx.corporate-ir.net/preview/phoenix.zhtml?c=107263&p=topframe_content" width="745" height="185" frameborder="0" allowTransparency="true" scrolling="no"></iframe><div class="divMore"><a href="http://outdoorchannel.com/Investors.aspx" class="more"><img src="http://outdoorchannel.com/images/investor_btn_more_info.gif" border="0" alt="More Info" /></a></div>').hide().fadeIn('slow');
			//$content.load('globalTray_investor_content.html','',function(){ $content.hide().fadeIn('slow') });
		});
	};
	
	// default option
	$.fn.trayInvestors.defaults = {
		//
	};
	
	// ===== TRAY: Newsletter ==================================================
	$.fn.trayNewsletter = function(options){
		// extend our default options with those provided
		var $options = $.extend({}, $.fn.trayNewsletter.defaults, options);
		
		return this.each(function() {
			var $this = $(this);
			// ~~~~~ cache elements ~~~~~ 
			var $header = $this.find('.header');
			var $content = $this.find('.content');
			// ~~~~~ header ~~~~~ 
			$header.find('img.label').attr('src','http://outdoorchannel.com/images/tray_label_newsletter.png').hide().fadeIn('slow');
			$content.html('<iframe src="http://outdoorchannel.com/newslettersignuptab.aspx" width="895" height="198" frameborder="0" allowTransparency="true" scrolling="auto"></iframe>').hide().fadeIn('slow');
			//$content.load('globalTray_investor_content.html','',function(){ $content.hide().fadeIn('slow') });
		});
	};
	
	// default option
	$.fn.trayNewsletter.defaults = {
		//
	};
	
	// ===== GLOBAL: Cached Version of $.getScript() =====
	$.getCachedScript = function(url, callback, cache){
		$.ajax({ type: "GET", url: url, success: callback, dataType: "script", cache: cache || true });
	}; 
	
})(winnerjQuery);

winnerjQuery(document).ready(function(winnerjQuery){
	winnerjQuery('#trayTabs li a').not('li a.submit').globalTray();
	
	winnerjQuery('.searchtext').keydown(function(e){
        if (e.keyCode == 13) {
            e.preventDefault();
            searchterm = encodeURIComponent(winnerjQuery('.searchtext').attr("value"));
            window.location='http://outdoorchannel.com/search.aspx?jq=1&term='+searchterm;
             return false;

        }
    });
     //onclick
    winnerjQuery('.btnSiteSearch').click(function(e){
        searchterm = encodeURIComponent(winnerjQuery('.searchtext').attr("value"));
        window.location='/search.aspx?jq=2&term='+searchterm;          
        return false;
    });
});
