function inputSuggest( sel ) {
	var $sel = jQuery(sel);
	$sel.data("search-suggest",$sel.val());
	$sel.focus(function(){
		if ( jQuery(this).val() == jQuery(this).data("search-suggest") ) {
			jQuery(this).val("");
		}
	}).blur(function(){
		if ( jQuery(this).val() == "" ) {
			jQuery(this).val( jQuery(this).data("search-suggest") )
		}
	})
}

jQuery(document).ready(function($){
	
	$(document).click(function(){
		if ( $('._dropdownDiv').is(":visible") )
			$('._dropdownDiv').hide();
		if ( $('#community-button-dropdown').is(":visible") ) {
			$('#community-button').removeClass("clicked");
			$('#community-button-dropdown').hide();
		}
	})
	
	$('#header-signin').click(function(){						   
		LoginStatus.signIn();
		return false;
	})
	
	
	$('#community-button').click(function(){
		$(this).toggleClass("clicked");
		if ( $(this).hasClass("clicked") ) {
			$('#community-button-dropdown').slideDown();
		} else {
			$('#community-button-dropdown').slideUp();
		}
	});
	
	inputSuggest('.header .search input[type=text]');
	
	$("#msg-input-box *[title]").unbind('tooltip').tooltip({
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		fade: 250
	});
	
});


/* Streamer */
var LoginStatus = {
    authenticate: function(){
        if (jsLoginStatus != undefined && jsLoginStatus == '200') 
            return true
        else 
            return false;
    },
    forceLogin: function(){
        if (LoginStatus.authenticate()) {
            return true;
        }
        else {
            LoginStatus.signIn();
            return false;
        }
    },
    twitterConnect: function(){
        if (jsUserTwitterStatus != undefined && jsUserTwitterStatus == '200') 
            return true
        else 
            return false;
    },
    signIn: function(){
		jQuery(".exposeDialog").hide();		
		setTimeout(function(){
			jQuery("#right-navigation-ul applet").hide();
			jQuery("#right-navigation-ul applet").hide();
		},60);
        if (jQuery('#sign-content').length) {
            DialogUtil.showPopup('#sign-in-dialog');
			Applet.hidden=1;
			Applet.showhide();
        }
        else {
            jQuery('#sign-in-dialog').load(Properties.SIGN_IN_TEMPLATE, function(){
                DialogUtil.showPopup('#sign-in-dialog');
            });
        }
		
		jQuery("#signin_cancel_btn").click(function(){
			jQuery("#right-navigation-ul applet").show();
		});
		jQuery("#sign-in-dialog").mouseover(function(){
			setTimeout(function(){
				jQuery("#right-navigation-ul applet").hide();
				jQuery("#right-navigation-ul applet").hide();
			},60);

		});
		jQuery("#sign-in-dialog").click(function(){
			setTimeout(function(){
				jQuery("#right-navigation-ul applet").hide();
				jQuery("#right-navigation-ul applet").hide();
			},5);
		});
		
    }
};

