// JavaScript Document
$(document).ready(function()
{
        setIEFixes();
        setUpSlider();
        setUpDropShadows();
        setUpTabs();
        setUpOverlays();
        //setUpslideContent();
});

function setIEFixes(){

   if ($.browser.msie && $.browser.version < 7) {
        $('body').css('behavior', 'url("/skins/wordsworth/js/csshover.htc")');  /* IE6 FIX */
        $('img, div').css('behavior', 'url("/skins/wordsworth/js/iepngfix.htc")');  /* IE6 FIX */
        $('.rightCol .bookGridContainer .content').css('border','none');
   }

}

function setUpScrollable(){
	// initialize scrollable
	$('.scrollable').scrollable();
}

function setUpEditionsHover(){
	$(".scrollable img").hover(
            function () {
                    //get the position of the placeholder element
                    var pos = $(this).offset();
                    var width = $(this).width();
                    //show the menu directly over the placeholder
                    $("#editionDetail").css( { "left": pos.left + "px", "top":pos.top + "px" } );
                    $("#editionDetail").show();
            }
	);
	
	$("#editionDetail").mouseleave(function(){
            $("#editionDetail").hide();
	});
}

function setUpSlider(){
    //If Element exists
    if($('#s3slider').length != 0){
        /*$('.anythingSlider').anythingSlider({
            easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
            autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
            delay: 8000,                    // How long between slide transitions in AutoPlay mode
            startStopped: false,            // If autoPlay is on, this can force it to start stopped
            animationTime: 600,             // How long the slide transition takes
            hashTags: true,                 // Should links change the hashtag in the URL?
            buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
                    pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
                    startText: "Play",                // Start text
                    stopText: "Pause",          // Stop text
                    navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)

        });*/

        $('#s3slider').s3Slider({timeOut: 5000});
    }
}

 function formatText(index, panel) {
          return index + "";
  }

  function setUpOverlays(){
      //If exists
      if($('.overlay').length != 0){
        /* jQuery Tools - Overlay */
        $("#footnotes a[rel]").each(function(i) {
            if($(this).equals('.l1_li.email a')){
                $(this).attr('title','Email a friend Coming Soon');
                $(this).attr('alt','Email a friend Coming Soon');
            }else{
                $(this).overlay({effect: 'apple'});
            }
        });
      }
  }

  function setUpDropShadows(){
     
     if(Modernizr.boxshadow){
        //alert('support drop shadow css');
     }else{
        /*$(".leftCol .content, .rightCol .bookCoverBox, .rightCol .bookBox, .homeSlides, .productImage,  .categoryImage, .editionsNav, .bookGridContainer #filter").dropShadow({
                                    left  :  1,
                                    top     :  1,
                                    blur    :  2,
                                    opacity :  0.5,
                                    color   :  "#666",
                                    swap    :  false
                                  });*/
     }
  }

  //function setUpslideContent(){
        //If exists
    //    if($('.productDetail p.product_author').length != 0){
      //      $('.productDetail p.product_author').toggle(function(){
        //            $('#author_bio').slideDown("slow");
          //          $(this).addClass('open');
            //    }, function(){
              //      $('#author_bio').slideUp("slow");
                //    $(this).removeClass('open');
                //}
             //);
         //}
  //}
  
  function gotourl(url) {
        window.location = url;
  }

  function setUpTabs(){
      //If element exists
      if($("ul.editionTabs").length != 0){
          // setup ul.tabs to work as tabs for each div directly under div.panes
          $("ul.editionTabs").tabs("div.panes > div");
      }
  }

  // plugin function - checks if same element
    (function($){

        jQuery.fn.equals = function(selector) {
            return $(this).get(0)==$(selector).get(0);
        };

    })(jQuery);
