
var szNormal = 410, szSmall = 390, szFull = 430;
var kwicks = null;
var theDescColorActive = "";
var theMenuItemOpened = false;

window.addEvent('domready', function(){

    kwicks = $$("#props .kwick");
    fx = new Fx.Elements(kwicks, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeOut});
    
    kwicks.each(function(kwick, i) {
        kwick.addEvent("mouseenter", function(event) {
            theMenuItemOpened = true;
            var o = {};
            o[i] = {width: [kwick.getStyle("width").toInt(), szFull]}
            kwicks.each(function(other, j) {
                if(i != j) {
                    other.setStyle('background-image', "url('/badge/imgres/gradbg_greenlight.png')");
                    var w = other.getStyle("width").toInt();
                    if(w != szSmall) o[j] = {width: [w, szSmall]};
                    $$("#" + other.id + " .editProp").setStyle('display', 'none');
                    $$("#" + other.id + " .propTitle").setStyle('display', 'block');
                }
            });
            fx.start(o);
            kwick.setStyle('background-image', "url('/badge/imgres/gradbg_green.png')");
            $$("#" + kwick.id + " .editProp").setStyle('display', 'block');
            $$("#" + kwick.id + " .propTitle").setStyle('display', 'none');
        });
    });
     
    $("props").addEvent("mouseleave", function(event) {
        var o = {};
        kwicks.each(function(kwick, i) {
            $$("#" + kwick.id + " .editProp").setStyle('display', 'none');
            $$("#" + kwick.id + " .propTitle").setStyle('display', 'block');
            kwick.setStyle('background-image', "url('/badge/imgres/gradbg_greenlight.png')");
            o[i] = {width: [kwick.getStyle("width").toInt(), szNormal]}
        });
        fx.start(o);
    });

});

function disableSelection(element) {
    element.onselectstart = function() {
        return false;
    };
    element.unselectable = "on";
    element.style.MozUserSelect = "none";
    //element.style.cursor = "default";
}

function openPicMenu()
{
    var tmpPic = $('mainPicViewMenu');
    if(tmpPic.fx != null)
            tmpPic.fx.stop();
    
    if(tmpPic.getStyle("display") == "none")
    {
        tmpPic.setStyle('display', 'block');
        tmpPic.fx = tmpPic.effect('height', {
                transition: Fx.Transitions.cubicOut,
                duration: 500
        }).start(150).chain( function(){
                if(!theMenuItemOpened)
                    $('badge_prop3').fireEvent('mouseenter');
        });
    }
    else
    {
        tmpPic.fx = tmpPic.effect('height', {
                transition: Fx.Transitions.cubicOut,
                duration: 500
        }).start(0).chain( function(){
                tmpPic.setStyle('display', 'none');
        });
    }
}

function onTitleOver(tmpElID)
{
    $(tmpElID).setStyle('color', '#666666');
};
function onDescOut(tmpElID, tmpNewColor)
{
    if(theDescColorActive == "")
        $(tmpElID).setStyle('color', tmpNewColor);
    else
        $(tmpElID).setStyle('color', theDescColorActive);
};

function onDescClick()
{
    var tmpEdit = $('thePicDescEdit');
    if($('thePicDesc').getText() == theNewDescText)
        tmpEdit.value = "";
    else
        tmpEdit.value = $('thePicDesc').getText();
    tmpEdit.setStyle("display", "block");
    $('thePicDesc').setStyle("display", "none");
    tmpEdit.select();
    tmpEdit.focus();
};
function onDescUpdated()
{
    var tmpEdit = $('thePicDescEdit');
    $('thePicDesc').setStyle("display", "block");
    tmpEdit.setStyle("display", "none");
    
    //sendAjaxRequest(theDescUpdateUri + '&pic_title_input=' + encodeURI(tmpEdit.value) , 'GET', updateDesc, ajaxFailureMain);
};
function updateDesc(textResponse)
{
    if(textResponse == "error")
        return;

    if(textResponse == "")
    {
        $('thePicDesc').setHTML(theNewDescText);
        theDescColorActive = "#000000";
        $('thePicDesc').setStyle("color", theDescColorActive);
    }
    else
    {
        $('thePicDesc').setHTML(textResponse);
        theDescColorActive = "#707070";
        $('thePicDesc').setStyle("color", theDescColorActive);
    }
    
}

//---------------------------------
//Ajax request function
function sendAjaxRequest(url, method, completeFx, failureFx)
{
    new Ajax(url,{ method:method, onComplete:completeFx, onFailure:failureFx}).request();
}
//Main failure processing
function ajaxFailureMain(transport)
{
    //alert("Error: " + transport.responseText);
}
