/**
 * Created by JetBrains PhpStorm.
 * User: ekko3
 * Date: 9/15/11
 * Time: 4:29 PM
 * To change this template use File | Settings | File Templates.
 */





Cufon.replace('.cufon-universlt', {hover: true});

$(document).ready(function(){

    $(":text").labelify({ labelledClass: "labelHighlight" });
    
    $("#footer").constantfooter({"opacity": "1"});



    var config = {
        over: drop_menu, // function = onMouseOver callback (REQUIRED)
        timeout: 500, // number = milliseconds delay before onMouseOut
        out: hide_menu // function = onMouseOut callback (REQUIRED)
   };

   $(".hover_menu").hoverIntent( config );


    function drop_menu (){
        $(this).children('a').addClass('drop_hover');
        $(this).children('.hover_sub').slideDown("slow");
    }

    function hide_menu(){
        $(this).children('a').removeClass('drop_hover');
        $(this).children('.hover_sub').slideUp("fast");
    }

    $('.hover_menuss').hover(function(){
        var inprog = 0;
        $(this).children('a').addClass('drop_hover');
        if (inprog == 0){
            inprog = 1;
            $(this).children('.hover_sub').slideDown("slow");
        }
    }, function(){
        $(this).children('a').removeClass('drop_hover');
        $(this).children('.hover_sub').slideUp("fast", function() {inprog = 0;});
    });



    $.widget( "custom.catcomplete", $.ui.autocomplete, {
		_renderMenu: function( ul, items ) {
			var self = this,
				currentCategory = "";



			$.each( items, function( index, item ) {



				if ( item.category != currentCategory ) {
					ul.append( "<li class='ui-autocomplete-category'>" + item.category + "<span class='view_all search_action' type='search' rel='search.php?type=" + item.category + "'>View All Search Results</span></li>" );
					currentCategory = item.category;
				}

                self._renderItem( ul, item );

			})


		}
	});

    

    //$( "#search_box" ).autocomplete({
    $( "#search_box" ).catcomplete({
			minLength: 0,
			source: CI_ROOT+"lib/service/search.php",
			open: function(event, ui) {
                $('ul.ui-autocomplete').css('top', 45);
                oldLeft = jQuery(".ui-autocomplete").offset().left;
                newLeft = oldLeft - 137;
                jQuery(".ui-autocomplete").css("left", newLeft);
                },
			select: function( event, ui ) {
                window.location = CI_ROOT+ui.item.detailurl;
				return false;
			}
		})
		.data( "catcomplete" )._renderItem = function( ul, item ) {
			return $( "<li></li>" )
				.data( "item.autocomplete", item )
				.append( "<a><img src='"+ item.icon +"' />"+ "<div><span class='name'>" + item.label + "</span><span class='desc'>" + item.desc + "</span> <span class='links'>" + item.actions + "</span></div></a>" )
				.appendTo( ul );
		};


    $('.search_action').live('click', function(){
        var action = $(this).attr('rel');
        var term = $('#search_box').val();
        if ($(this).attr('type')=='search'){
            action = action + '&term=' + term;
        }

        window.location = CI_ROOT+action;
    });

    $('.search_action').live('mouseover', function(){
        $(this).addClass('search_hover');
    });
    
    $('.search_action').live('mouseout', function(){
        $(this).removeClass('search_hover');
    });


});




