/* nav hover ie fix */
$(document).ready(function() {
    //call the jQuery Hover Over and Out
    $('#nav li').hover(over, out);
    //when hovered over
    function over(event) {
        $(this).addClass("on");
    }
    //going outside the object area
    function out(event) {
	    $(this).removeClass("on");
	}
});

/* showcase */
$(function() { 
 
    // initialize scrollable 
    $("div.scrollable").scrollable(
	{size: 6}
	); 
 
});
$(function() { 
    $(".items img").click(function() {

	// calclulate large image's URL based on title attribute
	var url = $(this).attr("alt");

	// get handle to element that wraps the image and make it semitransparent
	var wrap = $("#show").fadeTo("medium", 0.5);

	// the large image from flickr
	var img = new Image();

	// call this function after it's loaded
	img.onload = function() {

		// make wrapper fully visible
		wrap.fadeTo("slow", 1);

		// change the image
		wrap.find("img").attr("src", url);

	};

	// begin loading the image
	img.src = url;

// when page loads simulate a "click" on the first image
}).filter(":first").click();
});

/*
 * tools.tooltip "Slide Effect" 1.0.0
 * 
 * Copyright (c) 2009 Tero Piirainen
 * http://flowplayer.org/tools/tooltip.html#slide
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 *
 * Since  : September 2009
 * Date: ${date}
 * Revision: ${revision} 
 */
$(document).ready(function() { 
 
    // initialize tooltip 
    $("#nav li [title]").tooltip({ 
     
        // use single tooltip element for all tips 
        tip: '.tooltip',  
         
        // tweak the position 
        position: 'bottom center', 

		relative: 'true',
         
		// delay 1000 miliseconds
		delay: 1000
         
    // add dynamic plugin  
    }).dynamic( { 
     
        // customized configuration on bottom edge 
        bottom: { 
         
            // slide downwards 
            direction: 'down'
        } 
    }); 
     
});

/* More Info Tooltip */
$(document).ready(function() { 
    $(".manga .btn-green").tooltip({
		position: 'top center',
		offset: [15, 65],
		relative: 'true',
		delay: 1000
		});  
});
$(document).ready(function() { 
    $(".character .btn-green").tooltip({
		position: 'top center',
		offset: [15, 65],
		relative: 'true',
		delay: 1000
		});  
});
$(document).ready(function() { 
    $(".fullcolor .btn-green").tooltip({
		position: 'top center',
		offset: [15, 65],
		relative: 'true',
		delay: 1000
		});  
});

/* Show Order Form */


/*
 * jQuery.labelify - Display in-textbox hints
 * Stuart Langridge, http://www.kryogenix.org/
 * Released into the public domain
 * Date: 25th June 2008
 * @author Stuart Langridge
 * @version 1.3
 */
jQuery.fn.labelify = function(settings) {
  settings = jQuery.extend({
    text: "title",
    labelledClass: ""
  }, settings);
  var lookups = {
    title: function(input) {
      return $(input).attr("title");
    },
    label: function(input) {
      return $("label[for=" + input.id +"]").text();
    }
  };
  var lookup;
  var jQuery_labellified_elements = $(this);
  return $(this).each(function() {
    if (typeof settings.text === "string") {
      lookup = lookups[settings.text]; // what if not there?
    } else {
      lookup = settings.text; // what if not a fn?
    };
    // bail if lookup isn't a function or if it returns undefined
    if (typeof lookup !== "function") { return; }
    var lookupval = lookup(this);
    if (!lookupval) { return; }

    // need to strip newlines because the browser strips them
    // if you set textbox.value to a string containing them    
    $(this).data("label",lookup(this).replace(/\n/g,''));
    $(this).focus(function() {
      if (this.value === $(this).data("label")) {
        this.value = this.defaultValue;
        $(this).removeClass(settings.labelledClass);
      }
    }).blur(function(){
      if (this.value === this.defaultValue) {
        this.value = $(this).data("label");
        $(this).addClass(settings.labelledClass);
      }
    });
    
    var removeValuesOnExit = function() {
      jQuery_labellified_elements.each(function(){
        if (this.value === $(this).data("label")) {
          this.value = this.defaultValue;
          $(this).removeClass(settings.labelledClass);
        }
      })
    };
    
    $(this).parents("form").submit(removeValuesOnExit);
    $(window).unload(removeValuesOnExit);
    
    if (this.value !== this.defaultValue) {
      // user already started typing; don't overwrite their work!
      return;
    }
    // actually set the value
    this.value = $(this).data("label");
    $(this).addClass(settings.labelledClass);

  });
};

$(document).ready(function(){
  $("input[type=text]").labelify({ text: "label" });
});
