// 0 - for slider view
// 1 - for floater view
var highlighted_view = 0; // default to slider view when page is refresh

// the clone for ul.picks
var ul_clone;

$(document).ready( function() {

    // begin - close "x" button notifica
        $("a#closeNotifiche").click( function() {
            $("li.notifica,li.notifica_next").fadeOut(400);
            return false;
        });

/*      commented because it's handled by generic.js  
		$("ul.scroll a.close").click( function() {
            $(this).parent().parent().fadeOut(400);
            return false;
        });
*/        // end - close "x" button notifica

        // begin - close "x" button
        $("div.custumButt > a.close").click( function() {
            $(this).parent().parent().fadeOut(400);
            return false;
        });
        // end - close "x" button

        // begin - tag cloud toggler
        $("#tagscloud_full h3").click( function() {
            if ($(this).parent().attr("class").indexOf("close") >= 0) {
                $(this).parent().children("div.tagscloud").slideDown(1000);
                $(this).parent().removeClass("close");
            } else {
                $(this).parent().children("div.tagscloud").slideUp(1000);
                $(this).parent().addClass("close");
            }
        });
        // end - tag cloud toggler

        // begin - side bar signup pane toggler
        $("div.contentBox_Signup > h4").children("a").click(
                function() {
                    if ($(this).parent().parent().attr("class")
                            .indexOf("close") >= 0) {

                        $(this).parent().parent().children(".contentBoxSH")
                                .slideDown(1000);
                        $(this).parent().parent().removeClass("close");

                    } else {
                        $(this).parent().parent().children(".contentBoxSH")
                                .slideUp(1000);
                        $(this).parent().parent().addClass("close");
                    }

                    return false;
                });
        // end - side bar signup pane toggler

        // begin - side bar pane toggler
        $("div.contentBox_video > h4, div.custom > h4").children("a").click(
                function() {
                    if ($(this).parent().parent().attr("class")
                            .indexOf("close") >= 0) {

                        $(this).parent().parent().children(".contentBoxSH")
                                .slideDown(1000);
                        $(this).parent().parent().children(".contentBoxSH")
                                .find("ul.contentBox_video_list").slideDown(
                                        1000);
                        $(this).parent().parent().removeClass("close");

                    } else {
                        $(this).parent().parent().children(".contentBoxSH")
                                .find("ul.contentBox_video_list").slideUp(800);
                        $(this).parent().parent().children(".contentBoxSH")
                                .slideUp(1000);
                        $(this).parent().parent().addClass("close");
                    }

                    return false;
                });
        // end - side bar pane toggler

        // begin - sliding for the left pane
        $("div.contentBox_hp > h3").children("a").click(
                function() {

                    if ($(this).parent().parent().attr("class")
                            .indexOf("close") >= 0) {

                        $(this).parent().parent().children(".contentBoxSH")
                                .slideDown(1000);
                        $(this).parent().parent().removeClass("close");

                    } else {
                        $(this).parent().parent().children(".contentBoxSH")
                                .slideUp(1000);
                        $(this).parent().parent().addClass("close");
                    }

                    return false;
                });
        // end - sliding for the left pane

        // begin - loads the floater view
        $("#float_view").click( function() {

            if (highlighted_view == 1)
                return false;

            highlighted_view = 1;
            $(this).addClass("animazioneOn").removeClass("animazioneOff");
            $("#list_view").addClass("elencoOff").removeClass("elencoOn");

            $("#slider").fadeOut(500);

            // start cloning
                ul_clone = $("ul.picks").clone();

                init_floater($("ul.picks"));

                return false;

            });
        // end - loads the floater view

        // begin - load the slider view
        $("#list_view").click(
                function() {

                    if (highlighted_view == 0)
                        return false;

                    highlighted_view = 0;
                    $(this).addClass("elencoOn").removeClass("elencoOff");
                    $("#float_view").addClass("animazioneOff").removeClass(
                            "animazioneOn");

                    // ul_clone.remove();
                    $("ul.picks").remove();
                    $("#content_scroll").append(ul_clone);
                    ul_clone.children().fadeIn(5000);

                    $("#slider").fadeIn(500).slider("option", "value", 50);
                    $("#content_scroll").attr( {
                        scrollLeft : 735
                    });

                    return false;

                });
        // end - load the slider view

        // begin - the vertical bar for right side bar
        $("ul.contentBox_video_list").jScrollPane( {
            showArrows : false,
            scrollbarWidth : 21,
            scrollbarMargin : 0,
            dragMaxHeight : 21
        });
        // end - the vertical bar for right side bar

        // begin - customize panel
        $("#customizeButt").click(
                function() {

                    if ($("#customizeBox").hasClass("close")) {
                        $("#customizeBox").slideDown(1000).removeClass("close")
                                .addClass("open");
                        $(this).removeClass("sdButtSGrey").addClass(
                                "sdButtSRed");
                    } else {
                        $("#customizeBox").slideUp(1000).addClass("close")
                                .removeClass("open");
                        $(this).removeClass("sdButtSRed").addClass(
                                "sdButtSGrey");
                    }

                    return false;
                });

        $("#customizeForm input:checkbox").bind(
                "click",
                function() {
                    $("#customizeForm input").parent().removeClass("checked")
                            .addClass("unchecked");
                    $("#customizeForm input:checked").parent().removeClass(
                            "unchecked").addClass("checked");
                });

        // end - customize panel

        // begin - the vertical bar for right side bar
        $("ul.scroll").jScrollPane( {
            showArrows : false,
            scrollbarWidth : 21,
            scrollbarMargin : 0,
            dragMaxHeight : 21
        });
        // end - the vertical bar for right side bar

        init_slider();
        
    });

function log(msg) {
    $("p.testo").text(msg);
}