﻿var gcCarousel = {
    version: parseFloat(navigator.appVersion.split("MSIE")[1]),
    correctPNG:function() {
        if ((gcCarousel.version < 7) && (document.body.filters)) 
        {
          var theCarousel = document.getElementById("mycarousel");
          var thePngs = theCarousel.getElementsByTagName("img");
          for(var i=0; i<thePngs.length; i++)
          {
             var img = thePngs[i]
             var imgName = img.src.toUpperCase()
             if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
             {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText 
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
                + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
                img.outerHTML = strNewHTML
                i = i-1
             }
          }
        }    
    },
    mycarousel_itemVisibleInCallback:function(carousel, item, i, state, evt)
    {
        // The index() method calculates the index from a
        // given index who is out of the actual item range.
        var idx = carousel.index(i, mycarousel_itemList.length);
        carousel.add(i, gcCarousel.mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
        gcCarousel.correctPNG();
    },
    mycarousel_itemVisibleOutCallback:function(carousel, item, i, state, evt)
    {
        //setTimeout(function() { carousel.remove(i); }, 20);
        carousel.remove(i)
    },
    mycarousel_getItemHTML:function(item)
    {
        return '<a href="' + item.link + '"><img height="' + item.height + '" width="' + item.width + '" src="' + item.url + '" alt="' + item.title + '"></a>';
    },
    mycarousel_initCallback:function(carousel) {

        jQuery('#mycarousel-next').bind('click', function() {
            carousel.next();
            return false;
        });

        jQuery('#mycarousel-prev').bind('click', function() {
            carousel.prev();
            return false;
        });
    },
    openPopup:function() {
        gc_popup=window.open('http://www.barnesandnoble.com/popup_cds2.asp?PID=25439','popup','width=434,height=195,resizable=yes');
        gc_popup.moveTo(360, 380);
        gc_popup.focus();
        return(false);
    },
    hideAll:function() {
    
        $(".gc-style").hide();
        return false;
    },
    showAll:function() {
    
        this.hideAll();
        
        $(".gc-style").show()
        return false;
    },
    showMe:function(id) {
    
        this.hideAll();        
        var idocc = $("#" + id)
        idocc.show()
        
        return false;
    }
}

$(document).ready(function() {
   $("#styles_nav > li > a").click(function() {
     $("#styles_nav > li > a").removeClass("currentStyle")    
     
     gcCarousel.showMe($(this).attr("class"));
     
     if ($(this).attr("id") == "see-all-styles-link")
        gcCarousel.showAll();
        
     $(this).addClass("currentStyle");
     return false;
   });
 });

