var OW ={
    fadeTimer: 400,

    init: function () {
        $("#id_facet1, #id_facet2, #id_facet3").focus(OW.showHelp);
        $("#id_facet1, #id_facet2, #id_facet3").blur(OW.hideHelp);
        $("#id_facet1").autocomplete("/tagg/autocomplete_tags_ajax", {
            multiple: true,
            multipleSeparator: ",",
            extraParams:{facet:1},
            delay:50,
            cacheLength:50
        });
        $("#id_facet2").autocomplete("/tagg/autocomplete_tags_ajax", {
            multiple: true,
            multipleSeparator: ",",
            extraParams:{facet:2},
            delay:50,
            cacheLength:50
        });
        $("#id_facet3").autocomplete("/tagg/autocomplete_tags_ajax", {
            multiple: true,
            multipleSeparator: ",",
            extraParams:{facet:3},
            delay:50,
            cacheLength:50
        });
		OW.pulse();
    },

    showHelp: function() {
        if(this.id==="id_facet1")
            OW.customFadeIn($("#tag-help1"),OW.fadeTimer);
        if(this.id==="id_facet2")
            OW.customFadeIn($("#tag-help2"),OW.fadeTimer);
        if(this.id==="id_facet3")
            OW.customFadeIn($("#tag-help3"),OW.fadeTimer);
    },

    hideHelp: function() {
        if(this.id==="id_facet1")
            OW.customFadeOut($("#tag-help1"),OW.fadeTimer);
        if(this.id==="id_facet2")
            OW.customFadeOut($("#tag-help2"),OW.fadeTimer);
        if(this.id==="id_facet3")
            OW.customFadeOut($("#tag-help3"),OW.fadeTimer);
    },

	customFadeIn:
    function(elm, speed) {
		if (jQuery.browser.msie)
            elm.show();
		else
			elm.fadeIn(speed, function() {
        });
    },

    customFadeOut:
	function(elm, speed) {
		if (jQuery.browser.msie)
	        elm.hide();
	    else
			elm.fadeOut(speed, function() {
	    });
	},


	pulse: function() {
		speed = 400;
		duration = 800;
		fromToColor = "#efefef";
		$('.message_success').pulse({
			speed: speed,
			duration: duration,
			backgroundColors: [fromToColor,'#bbffbb',fromToColor]
		});
		$('.message_error').pulse({
			speed: speed,
			duration: duration,
			backgroundColors: [fromToColor,'#ffbbbb',fromToColor]
		});
	}
}

$(document).ready(OW.init);

