(function($){
	$.fn.fieldtag = function(options){
		var opt = $.extend({
				markedClass: "tagged",
				standardText: false
			}, options);
		$(this)
			.focus(function(){
				if(!this.changed){
					this.clear();
				}
			})
			.blur(function(){
				if(!this.changed){
					this.addTag();
				}
			})
			.keyup(function(){
				this.changed = ($(this).val()? true : false);
			})
			.each(function(){
				this.title = $(this).attr("title"); //strange IE6 Bug, sometimes
				if($(this).val() == $(this).attr("title")){
					this.changed = false;
				}
				this.clear = function(){
					if(!this.changed){
						$(this)
							.val("")
							.removeClass(opt.markedClass);						
					}
				}
				this.addTag = function(){
					$(this)
						.val(opt.standardText === false? this.title : opt.standardText )
						.addClass(opt.markedClass);
				}
				if(this.form){
					this.form.tagFieldsToClear = this.form.tagFieldsToClear || [];
					this.form.tagFieldsToClear.push(this);
				
					if(this.form.tagFieldsAreCleared){ return true; }
					this.form.tagFieldsAreCleared = true;
						
					$(this.form).submit(function(){
						$(this.tagFieldsToClear).each(function(){
							this.clear();
						});
					});	
				}
			})
			.keyup()
			.blur();
		return $(this);
	}
})(jQuery);

$(window).load(function() {
	$('#slider_img').nivoSlider({
		effect:'fade',
		slices:15,
		animSpeed:1000,
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
	});
});

$(document).ready(function(){

	
	
	$('#world_map a[href][title]').qtip({
	  content: {
	     text: false
	  },
	   style: { 
	      padding: 2,
	      background: '#CCCCCC',
	      color: 'black',
	      textAlign: 'center',
	      border: {
	         width: 0,
	         radius: 2,
	         color: '#CCCCCC'
	      },
	      name: 'dark'
	   },
	   position: {
	      corner: {
	         target: 'topRight',
	         tooltip: 'bottomLeft'
	      }
	   }

	});
	
	$("#stock_form").validationEngine({
		ajaxSubmit: true,
			ajaxSubmitFile: "includes/submit.php",
			ajaxSubmitMessage: "Thank you, we received your inscription!",
			ajaxSubmitExtraData: "form=stock",
		success :  false,
		failure : function() {}
	})
	
	$("#touch_form").validationEngine({
		ajaxSubmit: true,
			ajaxSubmitFile: "includes/submit.php",
			ajaxSubmitMessage: "Thank you, we received your email!",
			ajaxSubmitExtraData: "form=contact",
		success :  false,
		failure : function() {}
	})
	
	$("#pikame").PikaChoose({
		auto_play:true,
		transition:[0]
	});
	
	$("#name").fieldtag();
	$("#email").fieldtag();
	$("#msg").fieldtag();

});
