/**@author Alexandre Magno
 * @desc Center a element with jQuery
 * @version 1.0
 * @example $("element").center({ vertical: true, horizontal: true });
 * @obs With no arguments, the default is above
 * @license free
 * @param bool vertical, bool horizontal
 * @contribution Paulo Radichi
 */
jQuery.fn.center = function(params) {
		var options = {
			vertical: true,
			horizontal: true
		}
		op = jQuery.extend(options, params);
   return this.each(function(){//initializing variables
		var $self = jQuery(this);//get the dimensions using dimensions plugin
		var width = $self.width();
		var height = $self.height();//get the paddings
		var paddingTop = parseInt($self.css("padding-top"));
		var paddingBottom = parseInt($self.css("padding-bottom"));//get the borders
		var borderTop = parseInt($self.css("border-top-width"));
		var borderBottom = parseInt($self.css("border-bottom-width"));//get the media of padding and borders
		var mediaBorder = (borderTop+borderBottom)/2;
		var mediaPadding = (paddingTop+paddingBottom)/2;//get the type of positioning
		var positionType = $self.parent().css("position");// get the half minus of width and height
		var halfWidth = (width/2)*(-1);
		var halfHeight = ((height/2)*(-1))-mediaPadding-mediaBorder;// initializing the css properties
		var cssProp = {
			position: 'absolute'
		};
		if(op.vertical) {
			cssProp.height = height;
			cssProp.top = '50%';
			cssProp.marginTop = halfHeight;
		}
		if(op.horizontal) {
			cssProp.width = width;
			cssProp.left = '50%';
			cssProp.marginLeft = halfWidth;
		}		//check the current position
		if(positionType == 'static') {
			$self.parent().css("position","relative");
		}		//aplying the css
		$self.css(cssProp);
   });
};
/**@author Fabrizio Zani
 * @desc Animate plate for Spinnaker Lovere
 * @license free
 * @dependencies jQuery UI
 */
jQuery.fn.splashSpin = function(options) {// the plugin functionality goes in here
	var defaults = {};  
	var options = jQuery.extend(defaults, options);
	return this.each(function() {// apply plugin functionality to each element
		var $t = jQuery(this); 
		    positionT = $t.position()
		$t.animate({ 'opacity':'1.0', 'top': (positionT.top+30)+'px'}, {duration:1000, specialEasing: {'opacity': 'linear', 'top': 'easeOutQuint'}});
	});
};
jQuery.fn.splashTitle = function() {
    jQuery('h1').animate({ 'opacity':'1'}, { 'duration': 1250, 'easing': 'easeInCirc' });
};

jQuery(function() {
/*	function preloadImages(id) {
	    var c = new Array();
	    jQuery(id+' img').each( function(j) {
	        c[j] = new Image();
	        c[j].src = this.src;

	        if ( jQuery.browser.msie ) {
	            this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='image',src='"+ this.src +"')"; 
	        }
	    });

	}
	preloadImages('#spinnakerh1');
	preloadImages('#spinnaker25');
	preloadImages('#spinnaker28');
	preloadImages('#spinnaker22');
	preloadImages('#spinnaker07');
*/	
	
	var plate = jQuery('.spinPlate');
		plt28 = jQuery('#spinnaker28');
		plt25 = jQuery('#spinnaker25');
		plt22 = jQuery('#spinnaker22');
		plt07 = jQuery('#spinnaker07');
		h1 = jQuery('H1');
	plate.add('h1').css('opacity','0.0');
	plate.each(function() {
		var positionP = jQuery(this).position();
		jQuery(this).css({'top': (positionP.top-30)+'px'});	
	});
	jQuery('#centered').center();	
	setTimeout('h1.splashTitle()',1000);
	setTimeout('plt25.splashSpin()',2500); setTimeout('plt28.splashSpin()',2750); setTimeout('plt07.splashSpin()',3000); setTimeout('plt22.splashSpin()',3250);
});

