Cufon.replace('.replace_font');
/*
//elements that require hover states
Cufon.replace('.flash_wrapper a span, .promotions li a', {hover: true});
//elements that require a text shadow
Cufon.replace('.page_banner div',{ textShadow: '#333 1px 1px' });*/
   
$(document).ready(function() {			
	$('.category_list li').mouseover(function() {		
		$(this).find('.category_image_overlay').addClass('border_colour');
		$(this).find('h2').addClass('highlight_colour').removeClass('secondary_colour');
	}).mouseout(function() {		
		$(this).find('.category_image_overlay').removeClass('border_colour');
		$(this).find('h2').removeClass('highlight_colour').addClass('secondary_colour');
	});
	
	
	
	    //use js for dropdown nav as not all versions of IE support :hover pseudo class
    if(jQuery.browser.msie) {
        $('ul.site_navigation li').each(function() {
            $(this).mouseover(function() {
                $(this).find('ul').toggleClass('pseudo_hover');
            }).mouseout(function() {

            	$(this).find('ul').toggleClass('pseudo_hover');
            });
        });
    }
	
	
	(function($) {
		$.widget("ui.combobox", {
			_create: function() {
				var self = this;
				var select = this.element.hide();
				var input = $("<input>")
					.insertAfter(select)
					.autocomplete({
						source: function(request, response) {
							var matcher = new RegExp(request.term, "i");
							response(select.children("option").map(function() {
								var text = $(this).text();
								if (this.value && (!request.term || matcher.test(text)))
									return {
										id: this.value,
										label: text.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(request.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"),
										value: text
									};
							}));
						},
						delay: 0,
						change: function(event, ui) {
							if (!ui.item) {
								// remove invalid value, as it didn't match anything
								$(this).val("");
								return false;
							}
							select.val(ui.item.id);
							self._trigger("selected", event, {
								item: select.find("[value='" + ui.item.id + "']")
							});
						},
						minLength: 0,
						select: function(event, ui) {
							window.location = ui.item.id;
						}
					})
					.addClass("ui-widget ui-widget-content ui-corner-left")
					.val($('.header_bg img').attr('alt'));
				$("<button>&nbsp;</button>")
				.attr("tabIndex", -1)
				.attr("title", "Show All Items")
				.insertAfter(input)
				.button({
					icons: {
						primary: "ui-icon-triangle-1-s"
					},
					text: false
				}).removeClass("ui-corner-all")
				.addClass("ui-corner-right ui-button-icon")
				.click(function() {
					// close if already visible
					if (input.autocomplete("widget").is(":visible")) {
						input.autocomplete("close");
						return;
					}
					// pass empty string as value to search for, displaying all results					
					input.autocomplete("search", "");
					input.focus();
					
					if($('.ui-autocomplete').offset().top > 100) {						
						var top = $('.ui-autocomplete').offset().top - ($('.ui-autocomplete').height() + 26);
						$('.ui-autocomplete').css({'top': top})
					}
				});
			}
		});

	})(jQuery);
	
	//load site list
	$.ajax({
		type: 'POST',
		url: '/site_list/load_list/',
		timeout: 30000,
		error: function() {
			//console.log('error');
		},
		success: function(data){	
			$('#combobox').html(data);
		}
	});
		
	$("#combobox").combobox();
	
});

