/**
 * **********************************************************************
 * **********************************************************************
 * 
 *
 * @author stefan kloiber, <hello@09.fresh-flava.net>
 * @date 2009-02
 *
 * @version 0.0.10
 *
 * @dependencies: jquery, jquery-ui.core, jquery-ui.draggable, 
 *                jquery-ui.droppable
 *
 * @tested Firefox 3, Opera 9, Safari 3(PC)
 * **********************************************************************
 * **********************************************************************
 */


/* define namespace */
var ff; // declares a global symbol
if (!ff) ff = {};
    else if (typeof ff != 'object')
        throw new Error('ff existiert bereits, ist aber kein objekt!');


/**
 * drag and drop elements
 *
 */
ff.dragging = function()
{
    // drag
    jQuery('[rel="draggable"]').draggable(
    {
        helper: 'clone',
        cursor: 'move',
        start: function(event,info) {},
        drag: function(event, info) {},
        stop: function(event,info) {}
    });
};


ff.setTitle = function()
{
    jQuery('div.category.pixel').attr('title', 'PixelArt, Design');
    jQuery('div.category.website').attr('title', 'Website');
    jQuery('div.category.webdev').attr('title', 'Webdevelopment');
}


/**
 * open link in a new browser tab
 *
 */
ff.newTab = function()
{
    jQuery('a.extern').click(function(event) {
        event.preventDefault();
        window.open(this.href);
    });
};


/**
 * open cert in a new window
 *
 */
ff.popUp = function()
{
    jQuery('a.popup').click(function(event) {
        event.preventDefault();

        var width = 1000,
            height = 635,
            winName = "cert",
            xPos = (screen.availWidth - width) / 2,
            yPos = (screen.availHeight - height) / 2,
            puFeat = 'width=' +width+ ',height=' +height+ ',toolbar=no,status=yes,scrollbars=yes,resizable=yes,left=' +xPos+ ',top=' +yPos,
            puWin = window.open( this.href, winName, puFeat, false );

        if (puWin.opener == null) puWin.opener = window;
        puWin.opener.name = "popup";
    });
};



/**
 * SET SECURE ID TO HREFS
 *
 */
    function setSecureId() {

        var secureId, val;
        secureId = document.getElementById('secureLoginId');
        if (secureId) {
            val = secureId.value;
            if (val != "") {
                opener.setSecureIdInOpener( val );
            }
        }
    }


    function setSecureIdInOpener( val ) {

        var aSet = document.getElementsByTagName('a');
        for (var ai = 0; ai < aSet.length; ai++) {
            if (new RegExp( /cert/ ).test( aSet[ai].className )) {
                aSet[ai].href = aSet[ai].href+ "&ffID=" +val;
            }
        }
    }




/**
 * things to do when the dom is available
 */
jQuery(document).ready(function()
{
    // avoid the outline that appears around links upon clicking 
    // them and make them active. used for ie.
    jQuery('a').click(function() { this.blur(); });

    ff.dragging();
    ff.setTitle();
    ff.newTab();
    ff.popUp();
    setSecureId();
});
