﻿this.tooltip = function() {

    xOffset = 0;
    yOffset = 20;

    jQuery(".information[title]").addClass("tooltip");

    jQuery(".tooltip").hover(function(e) {
        this.t = this.title;
        this.title = ""
        jQuery("body").append("<p id='tooltip'>" + this.t + "</p>");
        jQuery("#tooltip")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px")
			.fadeIn("fast")
			.fadeTo("fast", "0.7");
    },
	function() {
	    this.title = this.t;
	    jQuery("#tooltip").remove();
	});

};

$(document).ready(function() { //Start code ******************************************

    //activate the tooltip/
    tooltip();

    //***************
    //Start Fake select box - you couldn't make this stuff up
    //***************

    /**
    * PB, 30/10/08: additional shut functions;
    */

    jQuery.each(['body', /* "#signInClickOff" */], function(i, v) {
        jQuery(v).bind('click', function() {
            shutIt(this);
            // return false;
        });
    });

    function shutIt(elem) {
        if (elem.id !== "nestedOptions") {
            jQuery("#nestedOptions").attr("class", "hide");
        };
    };
    /* end */

    //show the options for the fake "select box" by "clicking" the "fake button"

    jQuery("#fakeSelect #fakeButton").click(function() {
        jQuery("#signInClickOff").remove();
        //hide any instance of the sign in form
        jQuery("#signInForm").slideUp();
        //hide any instance of the search filter
        jQuery("#searchFilterContainer").slideUp();
        //just remove the default class of "hide" from the fake select box options
        jQuery("#nestedOptions").attr("class", "");
        return false;
    });

    //add the selected option to the text box for submission
    jQuery("#nestedOptions li a").click(function() {

        //declare a variable "the choice" and set to null
        var theChoice = "";

        //assign "the choice" to be the value of the link text selected from the list
        var theChoice = jQuery(this).text();

        //add "the choice" value to the "hidden" input element for submission
        jQuery("input.choiceOfGenre").attr("value", theChoice);

        //update this value also to the "initial value" of the "select box"
        jQuery("li span#initialValue").text(theChoice);

        //hide the list by putting back the "hide" class
        jQuery("#nestedOptions").attr("class", "hide");

        //stop those links working!
        return false;

        //make a cup of tea
    });

    //***************
    //end Fake select box
    //***************



    //***************
    //Start "sign up" toggle
    //***************

    //hide the sign up form
    jQuery("#signInForm").hide();

    ///toggle the sign up form up and down - just like a yo-yo but without string
    jQuery("#CommonBarSignInSignUp #revealSignInSignUp").click(
        function() {
            //find body, add the signInClickOff
            if (jQuery("#signInClickOff").length == 0)
                jQuery("#commonBar").prepend("<div id='signInClickOff'><!--ui effect--></div>");
            else
                jQuery("#signInClickOff").remove();

            //set the width and heights inlne in PX for ie6
            //var width=jQuery("body").innerWidth();
            var height = jQuery("body").innerHeight();
            jQuery("#signInClickOff").css("width", "930px").css("height", height);


            jQuery("#signInClickOff").click(function() {
                jQuery("#signInForm").slideUp();
                jQuery("#searchFilterContainer").attr("class", "hide");
                jQuery(this).remove();
            });
            //hide fake genre dropdown
            jQuery("#nestedOptions").attr("class", "hide");
            jQuery("#hideForm").removeClass("hide");
            //hide any instance of the search filter
            jQuery("#searchFilterContainer").attr("class", "hide");
            jQuery("#signInForm").removeClass("hide");
            jQuery("#signInForm").slideToggle();
            return false;
        }
    );

    jQuery("#signInForm").fadeTo("slow", .5);
    jQuery("#signInForm").hover(
    //on "over" do dis
    function() {
        jQuery(this).fadeTo("slow", 1);
    },
    //then on "out" do dat
    function() {
        jQuery(this).fadeTo("slow", .5);
    }
    );

    //when the login inputs get focus - clear the holding text
    //jQuery("#CommonBarSignInSignUp #signInForm input.genericInput").focus(function() {
    //jQuery(this).attr("value", "");
    //});

    //book a flight to a small pacific island and relax

    //***************
    //end "sign up" toggle
    //***************




    //***************
    //start search filter
    //***************

    //show the options for the fake "select box" by "clicking" the "fake button"
    jQuery("#CommonBarSearch #searchInputContainer input").focus(function() {
        // console.log("here!");
        //hide fake genre dropdown
        jQuery("#nestedOptions").attr("class", "hide");
        jQuery("#signInClickOff").remove();
        //hide any sign in
        jQuery("#signInForm").slideUp();
        jQuery("#searchFilterContainer").hide()
    .animate({ opacity: .5 }, 'normal')
    .slideDown()
    .attr("class", "")
    ;
        return false;
    });

    jQuery("#CommonBarSearch #searchInputContainer input").blur(function() {
        // console.log("blur!");
        jQuery("#searchFilterContainer").hide();
    });

    //hover fade to reduce importance of the CTA to filter a search
    jQuery("#searchFilterContainer").hover(
    //on "over" do dis
    function() {
        jQuery(this).fadeTo("slow", 1);
    },
    //then on "out" do dat
    function() {
        jQuery(this).fadeTo("slow", .5);
    }
    );

    jQuery("#searchFilter li.toDynamicLabel a").click(function() {

        //declare a variable "the choice" and set to null
        var theChoice = "";

        //assign "the choice" to be the value of the link text selected from the list
        var theChoice = jQuery(this).text();

        //add "the choice" value to the "hidden" input element for submission
        jQuery("#CommonBarSearch label.dynamicLabel").text(theChoice);
        jQuery("#CommonBarSearch input.uniqueSearchType").attr("value", theChoice);

        //hide the "search filter" again
        jQuery("#searchFilterContainer").attr("class", "hide");

        //only remove the label faded colour when a filter choice is made
        jQuery("#CommonBarSearch label.dynamicLabel").removeClass("hover");

        //stop those links working!
        return false;

        //have a quick read of the paper, put your feet up and relax

    });

    //make the label change on hover to suggest that something will happen
    jQuery("#searchFilter li.toDynamicLabel a").hover(
    //on "over" do dis
    function() {

        //declare a variable "the choice" and set to null
        var theChoice = "";

        //assign "the choice" to be the value of the link text selected from the list
        var theChoice = jQuery(this).text();

        //add "the choice" value to the "hidden" input element for submission
        jQuery("#CommonBarSearch label.dynamicLabel").addClass("hover").text(theChoice);
        jQuery("#CommonBarSearch input.uniqueSearchType").attr("value", theChoice); //Should do it for now :)

    },
    //then on "out" . . .
    function() {
        //nothing
    }
    );


    //***************
    //end search filter
    //***************



    //***************
    //Start profile scripts
    //***************

    //the rowClass will be set on the trigger but be used to move through the steps 1 & 2
    var rowClass;

    //Make sure all the track info divs are hidden
    jQuery("tr[id^=track-info-]").each(function() {
        jQuery(this).hide();
    });

    //trigger the track change process
    jQuery("table.tracks .trigger").click(
    function() {

        //get the class of the link and use it to target the ID on the div to clone
        rowClass = jQuery(this).parent().parent().attr("class");

        jQuery(document).find("tr[id^=track-info-]").hide();
        jQuery(document).find("tr#" + rowClass).show()

        //hide any instance of step 1 & 2
        jQuery(document).find("tr#" + rowClass + " .step1").hide();
        jQuery(document).find("tr#" + rowClass + " .step2").hide();

        //Show step 1
        jQuery(document).find("tr#" + rowClass + " .step1").slideDown();
        jQuery(document).find("tr#" + rowClass + " .step2").hide();

        //close button
        jQuery(".closeTrack").click(
    function() {
        //hide everything!
        jQuery("tr[id^=track-info-]").hide();
        jQuery(document).find("tr#" + rowClass + " .step1").hide();
        jQuery(document).find("tr#" + rowClass + " .step2").hide();
    }
    )
    }
    );

    //This function is triggered from a button in step 1
    showStep2 = function() {
        //hide step 1
        jQuery(document).find("tr#" + rowClass + " .step1").hide();
        //show step 2
        jQuery(document).find("tr#" + rowClass + " .step2").show();
        return false;
    }

    showStep1 = function() {
        //hide step 2
        jQuery(document).find("tr#" + rowClass + " .step2").hide();
        //show step 1
        jQuery(document).find("tr#" + rowClass + " .step1").show();
        return false;
    }

    //take a break

    //***************
    //End profile scripts
    //***************

    //***************
    //Start Active tables
    //***************
    jQuery("table.tracks tr[class^=track-info-] td:contains('Active')").addClass("active");
    jQuery("table.tracks tr[class^=track-info-] td:contains('Inactive')").addClass("inactive");
    jQuery("table.tracks tr[class^=track-info-] td.rmstatus:contains('Pending')").addClass("pending");
    jQuery("table.tracks tr[class^=track-info-] td:contains('Exclusive')").addClass("exclusive");
    //***************
    //End Active tables
    //***************

    //***************
    //Start Generic Zebra
    //***************
    /*  This one is for track update table */
    jQuery("table.trackZebra tr:odd:even td").addClass("odd");

    /*  This one is general-every-other-line*/
    jQuery("table.genericZebra tr:odd td").addClass("odd");

    /*  For lists   */
    jQuery("ul.genericZebra li:odd").addClass("odd");
    //***************
    //End Generic Zebra
    //***************

    jQuery(".showStep1").click(showStep1);
    jQuery(".showStep2").click(showStep2);
    jQuery(".confirmTrackDelete").click(function() { return confirm("Are you sure you want to delete this track?  If you have less than " + activeTracksCount + " active tracks you will not be eligible for Scouting."); });

    //***************
    //Start Add Track Trigger
    //***************
    jQuery(".addTrackTrigger").removeClass("hide");
    jQuery("#addTrack").addClass("hide");

    jQuery(".addTrackTrigger").click(function() {
        jQuery(".addTrackTrigger").addClass("hide");
        jQuery("#addTrack").removeClass("hide");
        return false;
    });
    //***************
    //End Add Track Trigger
    //***************

    //***************
    //Start Close Add Track Trigger
    //***************
    jQuery(".closeAddTrackTrigger").click(function() {
        jQuery(".addTrackTrigger").removeClass("hide");
        jQuery("#addTrack").addClass("hide");
        return false;
    });
    //***************
    //End Close Add Track Trigger
    //***************

    //***************
    //Start Add/Remove Members to Artist Triggers
    //***************
    jQuery(".confirmAddInvite").click(function() { return confirm("Are you sure you want to invite this member?"); });
    jQuery(".confirmRemoveInvite").click(function() { return confirm("Are you sure you don't want to invite this member?"); });
    //***************
    //End Add/Remove Members to Artist Triggers
    //***************

    //***************
    //Start Forum trash killer
    //***************
    jQuery(".pageForum [style]").removeAttr("style");
    jQuery(".pageForum [cellpadding]").removeAttr("cellpadding");
    jQuery(".pageForum [cellspacing]").removeAttr("cellspacing");
    jQuery(".pageForum [width]").removeAttr("width");

    //find nested tables and identify them
    jQuery(".pageForum  table~table").addClass("hasNestedTable");

    //!*%@ html!
    jQuery(".pageForum  .hasNestedTable td:has([align=middle])").addClass("withImages");
    jQuery(".pageForum  .post_alt td:has(img)").addClass("withImages");

    jQuery(".pageForum  td.smallfont[align=center]").removeAttr("align");


    //***************
    //end Forum trash killer
    //***************

    if ($(".adjustInvestmentRdo").length > 0) {
        $(".adjustInvestmentRdo").click(getInvestmentRewards)
    }

    if ($(".investInArtistDdl").length > 0) {
        $(".investInArtistDdl").change(getInvestmentRewards)
    }

    /*  Scoutroom rating images - break after third item*/
    jQuery(".payment li:nth-child(3)").append("<div class='theBreaker'></div>");

    if ($("a.overlayLink").length > 0) {
        $(function() { $("a.overlayLink").swfBox(); }); //sprinkle the overlay sugar
    }

    if ($("span.inlineValidator").length > 0) {
        $("span.inlineValidator").removeAttr("style"); //remove .net inline styles on inline validators
        $("span.inlineValidator").hide();
    }

    //end code ******************************************

});

function preAjaxLoad(elemId) {
    var h = jQuery("#" + elemId).height();
    jQuery("#" + elemId).fadeTo("fast", 0, function() {
        jQuery("#" + elemId).height(h); //retain height
        jQuery("#" + elemId).fadeTo("fast", 1); //fadein again
        jQuery("#" + elemId).html("<h1>Loading...</h1>"); //Show message
    });  //fadeout
}

function postAjaxLoad(elemId, result) {
    jQuery("#" + elemId).fadeTo("fast", 0, function() {
        jQuery("#" + elemId).html(result); //show the new results
        jQuery("#" + elemId).removeAttr("style"); //remove the fixed height so it resizes to the new content
        jQuery("#" + elemId).fadeTo("fast", 1); //fade in
    });
}