$(document).ready(function() {
		$(".vertical").vAlign();

    	$('ul.sf-menu').superfish({
    	 	animation:     {opacity:'show', height:'show'},
    	 	speed:         600,
    	 	delay:         400,
    	 	dropShadows:   false,
    	 	pathClass:     'current',
    	 	pathLevels:    1,
    	 	autoArrows:    false
    	});	
		
		$(".mainmenu .menu .submenu").hide();
		$(".mainmenu .menu.active .submenu").show();
			
		$(".mainmenu .menu:not('.active')").mouseover(function() {
			$(this).children('.submenu').show();		
		});

		$(".mainmenu .menu:not('.active')").mouseout(function() {
			$(this).children('.submenu').hide();	
		});

		$('input').live('focus', function() {
			$("input").css({"color":"#EC1B2E"});
		});

		$('input.gsc-input').live('focusout', setRestingSearchStyle );	

		// make the read more links pretty in the box-text boxes
		$('.block-text p').equalHeights();

		$("#searcher").autocomplete(
			"page/search",
			{
				delay:10,
				minChars:2,
				matchSubset:1,
				matchContains:1,
				maxItemsToShow: 6,
				cacheLength:10,
				onItemSelect:selectItem,
				onFindValue:findValue,
				formatItem:formatItem,
				autoFill:false
			}
		);
});


function findValue(li) {
	if( li == null ) return alert("No match!");

	// if coming from an AJAX call, let's use the CityId as the value
	if( !!li.extra ) var sValue = li.extra[0];

	// otherwise, let's just display the value in the text box
	else var sValue = li.selectValue;

//		window.location = "http://192.168.2.198/" + sValue;
		window.location = sValue;



}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
	return row[0];
}

function lookupAjax(){
	var oSuggest = $("#searcher")[0].autocompleter;

	oSuggest.findValue();

	return false;
}

function lookupLocal(){
	var oSuggest = $("#searcher")[0].autocompleter;

	oSuggest.findValue();

	return false;
}


function setRestingSearchStyle() {
	$("div.googlesearchbox").css({"border-color":"#BFBFBF"});
	$("input.gsc-input").css({"color":"#BFBFBF"});
	$("input.gsc-search-button").css({"color":"#BFBFBF"});			
}



function enableHomePageVideo(videoURL){
	// baseURL is defined in main template
    flowplayer("player", baseURL + 'swf/flowplayer.commercial-3.2.7.swf', {
        key: "#@7b3873ba0e9cd566b5b",
		clip: {
			autoPlay: true,
	        autoBuffering: true,
	        url: baseURL + videoURL,
            fadeInSpeed: 0,
            width: 700,
            height: 380,
            scaling: 'scale',
			onFinish: function() {
				this.unload();				
			}
        },
//        play: null,
        plugins: {
            controls: null
        },
        canvas: {
            backgroundColor: '#ffffff',
            backgroundGradient: 'none',
            borderRadius: 0
        }
    });
	
}


	
function enableVideo(videoURL) {
	// baseURL is defined in main template
    flowplayer("player", baseURL + 'swf/flowplayer.commercial-3.2.7.swf', {
        key: "#@7b3873ba0e9cd566b5b",
		clip: {
            url: baseURL + videoURL,
            fadeInSpeed: 0,
            width: 700,
            height: 380,
            scaling: 'scale',
			onFinish: function() {
				this.unload();				
			}
        },
        play: null,
        plugins: {
            controls: null
        },
        canvas: {
            backgroundColor: '#ffffff',
            backgroundGradient: 'none',
            borderRadius: 0
        }
    });
}

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  };
})(jQuery);
