/**
 * Safer console.log(). Just use log()!
 */
window.log = function(){
    log.history = log.history || [];
    log.history.push(arguments);
    arguments.callee = arguments.callee.caller;
    if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});

(function($) {

    window.addPrettyPhoto = function( obj ) {

        var aHref = $(obj).attr('href');

        var imgTitle = $(obj).attr('title');
        var imgDesc = $(obj).find('img').attr('title');

        longDesc= imgDesc.split("\n");
        if( longDesc.length > 1 )
        imgDesc = '<strong>' + longDesc[0] + '</strong><br/>' + longDesc[1];

        $.prettyPhoto.open( aHref , imgTitle , imgDesc );

        return;
    }

    window.cloneInput = function( type , originalInput ) {
        var inp = $('<input type="'+type+'" />');

        inp.addClass( $(originalInput).attr('class') );
        inp.attr( 'name', $(originalInput).attr('name') );
        inp.attr( 'value', $(originalInput).attr('value') );
        return inp;
    }

    /**
     * Change the default value of an Input Button or an Password field on focus
     */
    window.infieldLabel = function( targets ) {
        $(targets).live('focusin',function(){
            if($(this).data("oldvalue") == null || $(this).data("oldvalue") == $(this).val())
            {
                $(this).data("oldvalue",$(this).val());
                $(this).val("");
                if($(this).data("oldtype") == "password" )
                {
                    var newObj = cloneInput('password', this );
                    newObj.data("oldtype","password");
                    newObj.data("oldvalue", $(this).data('oldvalue') );
                    $(this).replaceWith( newObj );
                    window.setTimeout(function(){
                        newObj.focus();
                    },500);
                }
            }
        }).live('focusout',function(){
            if($(this).val() == "")
            {
                $(this).val($(this).data("oldvalue"));
                if($(this).data("oldtype") == "password" )
                {
                    var newObj = cloneInput('text', this );
                    newObj.data("oldtype","password");
                    newObj.data("oldvalue", $(this).data('oldvalue') );
                    $(this).replaceWith( newObj );
                }
            }
        }).each(function(){
            if( $(this).attr('type') == 'password' )
            {
                var newObj = cloneInput('text', this );
                newObj.data("oldtype","password");
                newObj.data("oldvalue", $(this).data('oldvalue') );
                $(this).replaceWith( newObj );
            }
        });
    }

    window.getFlash = function(filename, filename_bild, width, height, transparent, qualitaet)
    {
        var objectData = '<object type="application/x-shockwave-flash" data="'+filename+'" width="'+width+'" height="'+height+'">';

            if (transparent = '1')
            {
                objectData += '<param name="wmode" value="transparent">';
            } else {
                objectData += '<param name="wmode" value="opaque">';
            }

            objectData += '<param name="movie" value="'+filename+'">';
            objectData += '<param name="quality" value="'+qualitaet+'">';
            objectData += '<img src="'+filename_bild+'" width="'+width+'" height="'+height+'" border="0" />';
        objectData += '</object>';
        document.write(objectData);
    }

    $(function(){
        infieldLabel("#search input[type=text],#search input[type=password]");

        $("a[rel^='lightbox[']").prettyPhoto({
            theme:'connectiv',
            overlay_gallery: false,
            show_title: false,
            social_tools: false
        });

        $("a[rel^='lightbox']").bind('click',function(){
            addPrettyPhoto( this );
            return false;
        });
    })

})(jQuery);
