// yes/no toggle
// WSS event
$(function() {
    $(".helpful a").each(function(i) {
        $(this).click(function() {
        var myTarget = $(this).get();  
        var targetChildren = $(this).parent().parent().children(); // get the related children of the clicked element
        
        var lid = "Urev_Review_Helpful";
        _hbLink(lid, lid);
        
        switch($(myTarget).attr("name")) {        
        case ("yes"):
            $(this).removeClass().toggleClass("selected");
            $($(targetChildren[2]).children()).removeClass().toggleClass("muted");
            
            var myHref = $(myTarget).attr("href");             
            ajaxRequest = new AjaxRequest(myHref, null, null).run();      
            
            break;
        case ("no"):
            $(this).removeClass().toggleClass("selected");            
            $($(targetChildren[1]).children()).removeClass().toggleClass("muted");
            
            var myHref = $(myTarget).attr("href");            
            ajaxRequest = new AjaxRequest(myHref, null, null).run();   
                        
            break;
        }                    
		RefreshAds();
        return false;
        });
    });
});

     
// flag toggle    
// WSS event
$(function() {
    $(".helpful a.flag").each(function(i) {
        $(this).click(function() {
            var myTarget = $(this).get();  
            
            var lid = "Urev_Review_Helpful";
            _hbLink(lid, lid);
            
            if ($(this).attr("class") == "flag") {
                $(this).toggleClass("reported");  
           
                var myHref = $(myTarget).attr("href");                             
                ajaxRequest = new AjaxRequest(myHref, null, null).run();  
                     
                return false;                         
            } else {
                return false;
            }
			RefreshAds();
        });
    });
});

    
// search filter toggle
//WSS event
$(function() {
    $(".refine-search .group h5").each(function(i) {    
        $(this).click(function() {
            var lid = "Urev_GO_Search_Rvws";
            _hbLink(lid, lid);    
            
            $(this).parent(".group").toggleClass("open");
            this.childNodes[0].blur();
            return false;
        });
    });
});

// user popup layer toggle
$(function() {
    $("a.trigger").each(function(i) {
        $(this).mouseover(function() {     
            showUserLayer(this);                
            renderFancyUserPopup(this);        
        });      
        
        $("a.trigger").mouseout(function() {                        
            hideUserLayer(this);
        });
        
        $("a.trigger").click(function() {
            var lid = "Urev_User_Profile";
            _hbLink(lid, lid);  
            
            //return false;
        });
        
        $("div.user_popup_layer").hover(function() {          
            if ($("div.user_popup").mouseover()) {
                showUserLayer(this);                
            }
        }, function() {        
            hideUserLayer(this);
        });
    });     
});

// hide the layer
function hideUserLayer(thisEl) {
    $(thisEl).parent().children("div.user_popup_layer").hide();
}

// show the layer
function showUserLayer(thisEl) {    
    $(thisEl).parent().children("div.user_popup_layer").show();
}

// add shadow to user popups
$(function() {
    $("div.user_popup").wrap("<div class='top'><div class='top_left'></div><div class='top_right'></div></div>");
    $("div.user_popup_layer").append("<div class='bottom'><div class='bottom_left'><div class='arrow'></div></div><div class='bottom_right'></div></div>");
});


// render the shadows based on the content div
function renderFancyUserPopup(thisEl) {
    // determine the box height based on the class
    var boxWidth = $(thisEl).parent().children().find("div.user_popup").outerWidth();
    var boxHeight = $(thisEl).parent().children().find("div.user_popup").outerHeight();
    
    // apply the shadow container elements; assumes 6px padding
    $(".user_popup_layer").css("width",boxWidth+6).css("height",boxHeight+6);
    $(".user_popup_layer .top_left").css("width",boxWidth);
    $(".user_popup_layer .top_right").css("height",boxHeight);
    $(".user_popup_layer .bottom_left").css("width",boxWidth);  
}
