$(document).ready(function(){
	$(document).ajaxError(function(){
	    if (window.console && window.console.error) {
	        console.error(arguments);
					//$(document).trigger('close.facebox');
					//$.facebox('System Busy... Please try again');
					$(".close").show();
	    }
	});
	
    $.cookie('testcookiesenabled', null);
    $.cookie('testcookiesenabled', 'enabled');
    if ($.cookie('testcookiesenabled')) {
		$.cookie('testcookiesenabled', null);
    } else {
    	var url = window.location; 
    	if (url.toString().indexOf('logout')<0) {
    		alert("Please enable COOKIE");
    		location.href = '/en/logout.jhtml';
    	}	
    }

	$(".showOnload").each(function() {
			$(this).show();
		});

			$('.f').click(function(){
				$(this).next().toggle();
				if ($(this).hasClass('expanded')) {
						$(this).removeClass('expanded');
						$(this).addClass('collapsed');
					}
				else if ($(this).hasClass('collapsed')) {
						$(this).removeClass('collapsed');
						$(this).addClass('expanded');
					}
			});

			$('.x').click(function(){
				$(this).parent().toggle();
			});

                         $('.parenthide').click(function(){
				$(this).parent().addClass("hide");
			});

			$('.p').mouseover(function(e){
				var userid = $(this).attr('id').replace("user-","");
                                var pop_ = $('#miniprofile-'+userid);
                               $(pop_).fadeIn();
			});

			$('.q').mouseout(function(){
				$('.popupprofile').css("display","none");
			});
                         $('.username').click( function () {
                                goToProfile($(this));
                         });

	$('.username').each(function() {
             if ($(this).attr('id')!= undefined ) {
                            var userid = $(this).attr('id').replace("user-","");
                            if (!isNaN(userid))
                                $(this).css("cursor","pointer");
              }

            });



	$('.buttonsconfirm').mouseover(function () { $(this).addClass('buttonsconfirmover');});
	$('.buttonsconfirm').mouseout (function () { $(this).removeClass('buttonsconfirmover');});

	$('.buttonscancel').mouseover(function () { $(this).addClass('buttonscancelover');});
	$('.buttonscancel').mouseout (function () { $(this).removeClass('buttonscancelover');});

			$('.buttonscancel').click(function(){$(this).parent().toggle();});


		$('.roller').mouseover(function () { $(this).addClass("over");});
 		$('.roller').mouseout(function () { $(this).removeClass("over");});

                 updateProfileStatusCSS();

			$("input[id^='checkall-']").click( function() {
				var checkTarget = this.id.replace("checkall-","");
				var checkStatus = this.checked;
				$("input[id^='"+checkTarget+"']").each(function() {
					this.checked = checkStatus;
				});
			});

			$('a[rel*=facebox]').facebox();

			//$(document).bind("beforeReveal.facebox", function(){$ ("select").hide();})
			//$(document).bind("close.facebox", function(){$("select").show();})
		});


function updateProfileStatusCSS(){

if ($("#profilestatustxt").length > 0 && $("#profilestatustxt").parent().length > 0 &&
    $("#profilestatustxt").width() > $("#profilestatustxt").parent().width() )
    {
        $("#profilestatustxt").css("width",$("#profilestatustxt").parent().width());
           $("#profilestatustxt").css("max-width",$("#profilestatustxt").parent().width() );
        $("#profilestatustxt").css("overflow","scroll");
    }

}

function goToProfile (element)  {
            if ($(element).attr('id')!= undefined ) {
                            var userid = $(element).attr('id').replace("user-","");
                            if (!isNaN(userid)){
                                    var url_ = "/member/browse.jhtml?action=profile&profileId="+userid;
                                    document.location = url_;
                                        }
                           }
}


