jQuery.fn.exists = function() { return ($(this).length > 0); }

// OnLoad
$(function () {
    //logo
    $('#logo').attr('src', userparams.logo);

    //menu html fixes
    var menuHTML = $('ul.main').html();
    $('.menu .cover').html('<ul class="main">' + menuHTML + '</ul><div class="opacity"></div>');
    $(".menu li a:last").addClass("last-child");
    $(".main > li").addClass("first");
    $(".menu li:first-child ul > li a").prepend("#");
    //opacity
    $('.opacity').css('background-color', userparams.opBGColor);

    // :first-child
    $(".artists-list tr:first").addClass("first-child");

    $('a.close[rel=content]').click(function () {
        $('.content, .side').hide();
        return false;
    });

   
    // Input Focus out/in
    var input_fields = ".search .field"
    $(input_fields).each(function () {
        var input_title = $(this).attr("title");
        $(this).attr("value", input_title);
    });
    $(input_fields).focusin(function () {
        var input_title = $(this).attr("title");
        if ($(this).attr("value") == input_title)
            $(this).attr("value", "");
    });
    $(input_fields).focusout(function () {
        var input_title = $(this).attr("title");
        if ($(this).attr("value") == "") {
            $(this).attr("value", input_title);
        }
    });

    // DropDownMenu
    $(".menu .main > li.first").click(function () {
        $(".menu .main > li.first ul").slideUp();
        $(this).children().next().slideToggle("slow");
    });

    // a[rel=gallery] > FancyBox
    if ($(".gal a").exists()) {

        $(".gal a").fancybox({
            'padding': 0,
            'overlayShow': true,
            'overlayOpacity': 0.3,
            'overlayColor': '#fff',
            'showCloseButton': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'autoScale': false,
            'titlePosition': 'over'
        });
    }

    if ($("a[rel=gallery]").exists()) {

        $("a[rel=gallery]").fancybox({
            'padding': 0,
            'overlayShow': true,
            'overlayOpacity': 0.3,
            'overlayColor': '#fff',
            'showCloseButton': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'autoScale': false,
            'titlePosition': 'over'
        });
    }

    // a.poster > FancyBox
    if ($("a.poster").exists()) {

        $("a.poster").fancybox({
            'padding': 0,
            'overlayShow': true,
            'overlayOpacity': 0.3,
            'overlayColor': '#fff',
            'showCloseButton': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'autoScale': false,
            'titlePosition': 'over'
        });
    }

    $(".artists-list td a").click(function () {
        $(".side").css("display", "none");
        var anchor = $(this).attr("href");
        $(".side[name=" + anchor + "]").fadeIn("slow");
        return false;
    });

    $('embed').attr('wmode', 'transparent');

    if ($('.navigations').exists()) {
        $('.navigations a:first-child').addClass('prev');
        $('.navigations a:last-child').addClass('next');
    }

    $('.side .header h1').after('<a class="close" href="#" rel="side" title="close">x</a>');
    
    $('a.close[rel=side]').click(function () {
        $('.side').hide();
        return false;
    });
    swfobject.embedSWF('../images/bkg_movie.swf?film=../images/' + userparams.movieName + '&screen=../images/bg' + userparams.bgImg + '&loadercolor=ece570&showloader=false&buttoncolor=000000&bkgcolor=ffffff&done="done"', 'background-flash', "1000", "800", '9.0.0', false, flashvars, params, attributes);
});


