/*
  Variables Globales
*/

/*
  Init Functions
*/

//permet de preloader les images d'un div entier
jQuery.fn.onImagesLoaded = function(_cb) {
  return this.each(function() {

    var $imgs = (this.tagName.toLowerCase()==='img')?$(this):$('img',this),
        _cont = this,
            i = 0,
    _done=function() {
      if( typeof _cb === 'function' ) _cb(_cont);
    };

    if( $imgs.length ) {
      $imgs.each(function() {
        var _img = this,
        _checki=function(e) {
          if((_img.complete) || (_img.readyState=='complete'&&e.type=='readystatechange') )
          {
            if( ++i===$imgs.length ) _done();
          }
          else if( _img.readyState === undefined ) // dont for IE
          {
            $(_img).attr('src',$(_img).attr('src')); // re-fire load event
          }
        }; // _checki \\

        $(_img).bind('load readystatechange', function(e){_checki(e);});
        _checki({type:'readystatechange'}); // bind to 'load' event...
      });
    } else _done();
  });
};

//permet de realiser un reset sur une form entiere ou un input particulier
$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		//else if (tag == 'select')
			//this.selectedIndex = -1;
	});
};

$(function($) {

	$('#secondary-menu li a').tooltip({
	    track: true,
	    delay: 0,
	    showURL: false,
	    showBody: " - ",
	    fade: 250
	});

});

/*
	Tools Functions
*/

//init fancybox
function _ToolsInitFancybox () {
	$("a.myfancybox").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'zoomOpacity' : true,
		'overlayShow': true,
		'frameWidth': 640,
		'frameHeight': 480,
		'hideOnContentClick': false,
		'hideOnOverlayClick': false
	});
}
//fermeture de fancybox
function _ToolsCloseFancybox () {
	var argsRef = _ToolsCloseFancybox.arguments;
	$('#fancy_close').trigger('click');
	if (argsRef.length > 0) _ToolsSpecificReload (argsRef[0]);
	else _ToolsGlobalReload ();
}

//reload global
function _ToolsGlobalReload () {
	_MsgShowFloatProcessing ();
	location.reload ();
}
//reload specific
function _ToolsSpecificReload (url) {
	_MsgShowFloatProcessing ();
	location.href = url;
}

/*
	Messages Functions
*/

function _MsgShowFloatProcessing () {
	$.blockUI ({
		message				: '<span class="floatmsg">Processing...</span>',
		centerX				: true,
		centerY				: true,
		allowBodyStretch	: true,
		bindEvents			: true,
		css					: {width: '150px', border: 'solid 1px #E9518E', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: 1, color: '#fff'}
	});
}

function _MsgShowFloatReloading () {
	$.blockUI ({
		message				: '<span class="floatmsg">Reloading...</span>',
		centerX				: true,
		centerY				: true,
		allowBodyStretch	: true,
		bindEvents			: true,
		css					: {width: '150px', border: 'solid 1px #E9518E', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: 1, color: '#fff'}
	});
}

function _MsgShowFloatProblem () {
	$.blockUI ({
		message				: '<span class="floatmsg">A problem ocurred, the system does not recognize you please try again, sorry for the inconvenience. Or contact the administrator.</span>',
		centerX				: true,
		centerY				: true,
		showOverlay			: true,
		allowBodyStretch	: true,
		bindEvents			: true,
		timeout				: 4000,
		css					: {border: 'solid 1px #E9518E', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: 1, color: '#fff'}
	});
}
function _MsgShowFloatNotActive () {
	$.blockUI ({
		message				: '<span class="floatmsg">Our commercial website will be operational during march 2010.<br/>If you wish to <a href="?page=CONTACT" style="color: #fff;">contact us</a> before this date, please feel free to send us an email</span>',
		centerX				: true,
		centerY				: true,
		showOverlay			: true,
		allowBodyStretch	: true,
		bindEvents			: true,
		timeout				: 6000,
		css					: {width: '500px', border: 'solid 1px #E9518E', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: 1, color: '#fff'},
		onUnblock: function() {
			
		}
	});
}
function _MsgShowFloatAllowQty () {
	$.blockUI ({
		message				: '<span class="floatmsg">You exceed the amount of product allowed: 10.<br/>If you want to order more than 10 products, please <a href="?page=CONTACT" style="color: #fff;">contact Vanita Rosa</a>.<br/>Thank you for your understanding.</span>',
		centerX				: true,
		centerY				: true,
		showOverlay			: true,
		allowBodyStretch	: true,
		bindEvents			: true,
		timeout				: 6000,
		css					: {width: '500px', border: 'solid 1px #E9518E', padding: '15px', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: 1, color: '#fff'},
		onUnblock: function() {
			
		}
	});
}

