//<![CDATA[
$(document).ready(function() {
    my_kwicks();
    simple_tooltip("a", "tooltip");
});

function my_kwicks(){
    $('.kwicks').kwicks({
		duration: 300,   
        max: 300,  
        spacing:  0  
    });
}

function simple_tooltip(target_items, name) {
    $(target_items).each(function(i) {
        $("body").append("<div class='" + name + "' id='" + name + i + "'><p>" + $(this).attr('title') + "</p></div>");
        var my_tooltip = $("#" + name + i);

        if ($(this).attr("title") != "" && $(this).attr("title") != "undefined") {

            $(this).removeAttr("title").mouseover(function() {
                my_tooltip.css({ opacity: 0.8, display: "none" }).fadeIn(400);
            }).mousemove(function(kmouse) {
                var border_top = $(window).scrollTop();
                var border_right = $(window).width();
                var left_pos;
                var top_pos;
                var offset = 15;
                if (border_right - (offset * 2) >= my_tooltip.width() + kmouse.pageX) {
                    left_pos = kmouse.pageX + offset;
                } else {
                    left_pos = border_right - my_tooltip.width() - offset;
                }

                if (border_top + (offset * 2) >= kmouse.pageY - my_tooltip.height()) {
                    top_pos = border_top + offset;
                } else {
                    top_pos = kmouse.pageY - my_tooltip.height() - offset;
                }

                my_tooltip.css({ left: left_pos, top: top_pos });
            }).mouseout(function() {
                my_tooltip.css({ left: "-9999px" });
            });

        }

    });
}




var sbSlides = "";
var current_state = 0;
var kwick_choice = "";
//This is needed as workaround for IE when we had to show 
//SubCategory thru URL request. We need to initialize the first 
//category and then second, so when we are initializing the first one
//then we need to skip initialization of image viewer because IE will display
//download bar if we initiliaze the first and then the second at the same time.
var skip_slide_initialization = false;

function onKwickclick(o) {
    
    if (o == "kwick1") {
        resetKwick();
        current_state = 1;
        kwick_choice = "favorite_music";   
        onFeatureClick(CategoryLookUp(current_state));  
        $('#accordion_1').accordion('activate', 0); 
    }
    else if (o == "kwick2") {
        resetKwick();
        current_state = 2;
        kwick_choice = "rip_music";
        onFeatureClick(CategoryLookUp(current_state)); 
        $('#accordion_2').accordion('activate', 0); 
    }
    else if (o == "kwick3") {
        resetKwick();
        current_state = 3;
        kwick_choice = "manage_ipod";
        onFeatureClick(CategoryLookUp(current_state)); 
        $('#accordion_3').accordion('activate', 0); 
    }
    else if (o == "kwick4") {
        resetKwick();
        current_state = 4;
        kwick_choice = "quick_burn";
        onFeatureClick(CategoryLookUp(current_state)); 
        $('#accordion_4').accordion('activate', 0); 
    }
    else if (o == "kwick5") {
        resetKwick();
        current_state = 5;
        kwick_choice = "customize_with";
        onFeatureClick(CategoryLookUp(current_state)); 
        $('#accordion_5').accordion('activate', 0); 
    }
    else if (o == "kwick6") {
        resetKwick();
        current_state = 6;
        kwick_choice = "save_usb";
        onFeatureClick(CategoryLookUp(current_state)); 
        $('#accordion_6').accordion('activate', 0); 
    }
 }

function resetKwick() {
    current_state = 0;
    document.getElementById('my_slides').innerHTML = "";
    document.getElementById('previous_slide').className = "visible_no";
    document.getElementById('next_slide').className = "visible_no";

    document.getElementById('kwick1').className = 'kwick1';    
    
    document.getElementById('favorite_music').className = "visible_no";
    document.getElementById('kwick2').className = "kwick2";
    document.getElementById('rip_music').className = "visible_no";

    document.getElementById('kwick3').className = "kwick3";
    document.getElementById('manage_ipod').className = "visible_no";

    document.getElementById('kwick4').className = "kwick4";
    document.getElementById('quick_burn').className = "visible_no";

    document.getElementById('kwick5').className = "kwick5";
    document.getElementById('customize_with').className = "visible_no";

    document.getElementById('kwick6').className = "kwick6";
    document.getElementById('save_usb').className = "visible_no";

}

function CategoryLookUp(kwick_selection){
    var category = 0;

    if (kwick_selection == 1) {
        category = 1;
        document.getElementById('kwick1').className = "kwick1activated";
    }
    else if (kwick_selection == 2) {
        category = 4;
        document.getElementById('kwick2').className = "kwick2activated";
    } 
    else if (kwick_selection == 3) {
    category = 8;
    document.getElementById('kwick3').className = "kwick3activated";
    }
    else if (kwick_selection == 4) {
    category = 11;
    document.getElementById('kwick4').className = "kwick4activated";
    }
    else if (kwick_selection == 5) {
    category = 13;
    document.getElementById('kwick5').className = "kwick5activated";
    }
    else if (kwick_selection == 6) {
    category = 16;
    document.getElementById('kwick6').className = "kwick6activated";
    }
    else {
        document.getElementById('kwick1').className = "kwick1activated";
    }

    return category;
}

//Needed to highlight/unhighlight next/rev buttons when user clicks them
var LeftArrowHighlighted = 0;
var RightArrowHighlighted = 0;

function onLeftMouseDown() {

    if (current_slide == 1) {
        document.getElementById('previous_slide').src = "images/navigation/LeftArrowDisabled.png";
    }
    else {
        document.getElementById('previous_slide').src = "images/navigation/LeftArrow.png";
    }
}

function onRightMouseDown() {

    if (current_slide == total_slides) {
        document.getElementById('next_slide').src = "images/navigation/RightArrowDisabled.png";
    }
    else {
        document.getElementById('next_slide').src = "images/navigation/RightArrow.png";
    }
}

function onLeftMouseUp() {

    if (current_slide == 1) {
        document.getElementById('previous_slide').src = "images/navigation/LeftArrowDisabled.png";
    }
    else {
        document.getElementById('previous_slide').src = "images/navigation/LeftArrowHighlighted.png";
    }
}

function onRightMouseUp() {

    if (current_slide == total_slides) {
        document.getElementById('next_slide').src = "images/navigation/RightArrowDisabled.png";
    }
    else {
        document.getElementById('next_slide').src = "images/navigation/RightArrowHighlighted.png";
    }
}

function onLeftOver(o) {

    LeftArrowHighlighted = 0;
    
    if (current_slide == 1 ) {
        return;
    }
    
    if (o == 1 ){
        document.getElementById('previous_slide').src = "images/navigation/LeftArrowHighlighted.png";
        LeftArrowHighlighted = 1;
    }
    if (o == 2) {
        document.getElementById('previous_slide').src = "images/navigation/LeftArrow.png";
    }
    
}
function onRightOver(o) {

    RightArrowHighlighted = 0;
    
    if (current_slide == total_slides) {
        return;
    }
    
    if (o == 1) {
        document.getElementById('next_slide').src = "images/navigation/RightArrowHighlighted.png";
        RightArrowHighlighted = 1;
    }
    if (o == 2) {
        document.getElementById('next_slide').src = "images/navigation/RightArrow.png";
    } 
}

//Trigger on click event (which will be processed in displayPreviousSlideHandler
function displayPreviousSlide() {
    if (isIE()) {
        document.getElementById('previous_slide').click();
    }
    else {
        $('#previous_slide').click();
    }
}

function displayNextSlide() {
    if (isIE()) {
        document.getElementById('next_slide').click();
    }
    else {
        $('#next_slide').click();
    }
}

function displayPreviousSlideHandler() {
    if ( current_slide > 1) {
        current_slide -= 1;
        updateSlidesNavigationState();
    }
}

function displayNextSlideHandler() {
    if (current_slide < total_slides) {
        current_slide += 1;
        updateSlidesNavigationState();
    }
}

function updateSlidesNavigationState() {
    if (current_slide == 1) {
        LeftArrowHighlighted = 0;
        document.getElementById('previous_slide').src = "images/navigation/LeftArrowDisabled.png";
        document.getElementById('previous_slide_bottom').className = 'visible_hide';
        document.getElementById('onPrev').className = 'DisabledLink';
    }
    else {
        document.getElementById('onPrev').className = '';
        if (LeftArrowHighlighted == 1) {
            document.getElementById('previous_slide').src = "images/navigation/LeftArrowHighlighted.png";
        }
        else {
            document.getElementById('previous_slide').src = "images/navigation/LeftArrow.png";
        }

        document.getElementById('previous_slide_bottom').className = 'visible_unhide';
    }

    if (current_slide == total_slides) {
        RightArrowHighlighted = 0;
        document.getElementById('next_slide').src = "images/navigation/RightArrowDisabled.png";
        document.getElementById('next_slide_bottom').className = 'visible_hide';
        document.getElementById('onNext').className = 'DisabledLink';
    }
    else {
        document.getElementById('onNext').className = '';
        if (RightArrowHighlighted == 1) {
            document.getElementById('next_slide').src = "images/navigation/RightArrowHighlighted.png";
        }
        else {
            document.getElementById('next_slide').src = "images/navigation/RightArrow.png";
        }

        document.getElementById('next_slide_bottom').className = 'visible_unhide';
    }
}

function isIE() {
    return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function preloadImages(arguments) {
    for (var i = 0; i < arguments.length; i++) {
        $('<img />').attr('src', arguments[i]);
    }
};
//]]>
