/*! This file has *//* NOT *//*! been minimized. */


/*In minimized files, *//*! credits of reused code can be found by removing '-min' from the url. */


if (typeof SOUPGIANT == "undefined" || !SOUPGIANT) {
	//create SOUPGIANT namespace if it hasn't been done already
	SOUPGIANT = {};
}

SOUPGIANT.client = function() {
	var $ = jQuery,
		SG = SOUPGIANT,
		SGb = SG.base;
			
	function SideBarSearch(settings){
		var searchField = $(settings.searchField);
		searchField.val(settings.initValue);
		
		searchField.focus(function(){
			$(this).val('');
			$(this).css('color', '#000');
		});
		
		searchField.blur(function(){
			$(this).val(settings.initValue);
			$(this).css('color', '#9A9A9A');
		});
		
		searchField.keypress(function(event){
			if(event.keyCode === 13)
			{
				$(settings.spinnerDiv).css('display', 'inline');
			}
		});
	}
		
	$(function(){
		//document ready (html,css,js - no img)
		
		var headerSearch = new SideBarSearch({
			searchField : "#query",
			initValue : "Find products and Suppliers",
			spinnerDiv : "#header-search .loading"
		});
		
		var blogSearch = new SideBarSearch({
			searchField : "#blog_query",
			initValue : "Search Resources",
			spinnerDiv : ".search-bar .loading"
		});
		
		SGb.nav('#nav');
		switchRatings();
		
		var splitLocation = window.location.href.split("/");
		$('#site_selector').val(splitLocation[3].toUpperCase());
		$('#site_selector').change(function(){
			window.location.href = 'http://resources.selector.com/' + $(this).val().toLowerCase();
		});
	});
	
	$(window).ready(function(){
		//window ready (html,css,js - no img)
	});
	
	
	var switchRatings = function () {
		var $ratingsWidgets = $('#contentB .widget_ratings:lt(2)'); // get 1st two ratings
		
		
		//are they next to each other?
		if ($ratingsWidgets.eq(0).next('div').hasClass('widget_ratings') == true) {
			
			var tallestWidget = 0;
			$ratingsWidgets.each(function(){
				var thisHeight = $(this).height();
				
				if (tallestWidget < thisHeight) {
					tallestWidget = thisHeight;
				}
				//console.log(thisHeight);

			}).height(tallestWidget);
			
			$ratingsWidgets.wrapAll('<div class="widget_ratings_wrapper" style="height: ' + tallestWidget + 'px;" />');
			$ratingsWidgets.addClass('widget_ratings_tabbed');

			//wrap headings with <a>
			$('.widget-title', $ratingsWidgets).wrapInner( '<a href="#" />' )
			
			//move second title right
			$('.widget-title', $ratingsWidgets.eq(1)).css({
				left: $('.widget-title', $ratingsWidgets.eq(0)).width() + 15
			});


			//3. hide ul of second ratings widget
			var showWidget = function($theWidget) {
				$('ul', $theWidget).css({
					'left': 'auto',
					'z-index': '2'
				});
				$('.widget-title', $theWidget).css({
					'z-index': '2'
				});				
				$('.widget-title a', $theWidget).css({
					color: '#464646'
				});
			}

			var hideWidget = function($theWidget) {
				$('ul', $theWidget).css({
					'left': '-90000em',
					'z-index': '1'
				});
				$('.widget-title', $theWidget).css({
					'z-index': '1'
				});				
				$('.widget-title a', $theWidget).css({
					color: '#367FA1'
				});
			}

			hideWidget($ratingsWidgets.eq(1));
			showWidget($ratingsWidgets.eq(0));
			
			
			//4. add click events to each of the links
			$('.widget-title a', $ratingsWidgets.eq(0)).click(function(e){
				hideWidget($ratingsWidgets.eq(1));
				showWidget($ratingsWidgets.eq(0));
				e.preventDefault();
			});
			
			$('.widget-title a', $ratingsWidgets.eq(1)).click(function(e){
				hideWidget($ratingsWidgets.eq(0));
				showWidget($ratingsWidgets.eq(1));
				e.preventDefault();
			});
			

			
			
			
		}
		
		return;
	}
	
	
}();
