// site wide javascript functions

Cufon.replace('.blockHeader, .reviews h2, #fullColumn h1, h2.top5');

$(document).ready(function(){ 

	$('ul.sf-menu').superfish({
		delay:       1000,                            	// one second delay on mouseout 
		animation:   {opacity:'show',height:'show'},  	// fade-in and slide-down animation 
		speed:       'fast',                          	// faster animation speed 
		autoArrows:  true,                           	// disable generation of arrow mark-up 
		dropShadows: false                            	// disable drop shadows 
	});
	
	
	$('.corner').corner();
	$('.cornerTop').corner("top");
	$('.cornerBottom').corner("bottom");
	
	var searchBoxMessage = 'Enter Product Search or Code Here';
	if ($("#searchKW").val() == '') $("#searchKW").val(searchBoxMessage);
	
    $("#searchKW, #footerSearchKW").focus(function() {
        if ($(this).val() == searchBoxMessage) $(this).val('');
    })
    .blur(function() {
        if ($(this).val() == '') $(this).val(searchBoxMessage);
    });


		$("#searchKW").autocomplete({
			source: "/search/test-ajax",
			minLength: 2,
			select: function(event, ui) {
				//log(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value);
				location.href = ui.item.url;
			}
		});


/*
	new function($) {
	$.fn.setCursorPosition = function(pos) {
	if ($(this).get(0).setSelectionRange) {
	$(this).get(0).setSelectionRange(pos, pos);
	} else if ($(this).get(0).createTextRange) {
	var range = $(this).get(0).createTextRange();
	range.collapse(true);
	range.moveEnd('character', pos);
	range.moveStart('character', pos);
	range.select();
	}
	}
	}(jQuery);
*/

    
    
    // search functions
    
/*
    $("#searchKW").keyup(function(event){
		if ($("#searchKW:focus")){
		if (event.keyCode !=38 && event.keyCode != 40){
			// set value in hidden field to use when return to box
			$("#searchKWuser").val($(this).val());

			if($(this).val().length < 3) {
				$('#suggestions').fadeOut();
			} else {
				$('#searchKW').addClass('load');
				
				try{ 
				//alert($("#searchKW").css('background'))
				var searchKWbackground=$("#searchKW").css('background');
				if ((searchKWbackground === undefined || typeof searchKWbackground == 'undefined') && !searchKWbackground.match("ajax-loader.gif"))
					$("#searchKW").css('background', 'url(/images/ajax-loader.gif) no-repeat scroll left center transparent');
				} catch (err) {
					$("#searchKW").css('background', 'url(/images/ajax-loader.gif) no-repeat scroll left center transparent');
				}
				
				$.post("/search/test-ajax", {keywords: ""+$(this).val()+""}, function(data){
					if(data.length >0) {
						$('#suggestions').fadeIn();
						$('#suggestionsList').html(data);
						$('#searchKW').removeClass('load');
						
						$("#searchKW").css('background', 'url("/images/search-field.gif") no-repeat scroll left center transparent');
					}
				});
			}
		} else if (event.keyCode==13){
			var product_link = $(".ajaxSearchItem.selected a").attr("href");
			alert(product_link);
		}
		}
	});
	
	$("#searchKW").blur(function(){
	//	setTimeout("$('#suggestions').fadeOut();", 2000);
	});




	$("ajaxSearchItem").hover(
		// hover in
		function() { $("#suggestionsList ul li").removeClass('selected'); $(this).addClass('selected'); },
		// hover out
		function() { $("#suggestionsList ul li").removeClass('selected'); $(this).removeClass('selected'); }
	);
	
    $().keydown(function(e) {
		
        var $item = $(".selected").removeClass("selected");
        var index = $item.parent().children().index($item) + 1;
		var isFirst=false;
		//alert(index)
		if (index===undefined || index==0){
			isFirst=true;
			$item = $(".ajaxSearchItem:first");
		}
        if (e.keyCode === 38) { // up
            if ($item.prev().is("li")) {
                $item.prev().addClass("selected");
            } else {
            	$("#searchKW").focus().val($("#searchKWuser").val());
            	
		       	$("#searchKW").val($("#searchKW").val());
            	
            	//alert($("#searchKWuser").val())
                //$item.parent().children(":last").addClass("selected");
            }
            
            $("#searchKW").val($(".ajaxSearchItem.selected a").attr("title"));
            
        } else if (e.keyCode === 40) { // down
        	if(isFirst){
        		$item.addClass("selected");
        	} else {
	            if ($item.next().is("li")) {
	                $item.next().addClass("selected");
	            } else {
	                $item.parent().children(":first").addClass("selected");
	            }
            }
            $("#searchKW").val($(".ajaxSearchItem.selected a").attr("title"));
            
        }

    });
*/

    
});
