/**
 * @author Viames Marino
 */


jQuery(document).ready(function() {

	var player = jQuery('#flashContent')[0];
	
	var autoplay = false;

	jQuery.fn.centerDiv = function() {
		var windowWidth  = document.body.clientWidth;
		var popupWidth  = jQuery(this).width();
		var valWidth	= Math.round(windowWidth/2 - popupWidth/2);
		jQuery(this).css({"position": "absolute","left": valWidth + 93});
	};
	
	jQuery.extend({
		openGallery: function() {
			if (jQuery.browser.msie) {
				jQuery('#gallery-popup-overlay').css('filter','alpha(opacity=70)');
				if (jQuery.browser.version < 7) {
					jQuery('#gallery-popup-overlay').css('height',jQuery(document).height());
				}
			}
			jQuery('#gallery-popup-overlay').fadeIn('fast');
			jQuery('#gallery-popup-outer').fadeIn(200);
			if (autoplay) {
				setTimeout(function(){player.sendEvent('PLAY','true');},1000);
			}
			return true;
		},
		closeGallery: function() {
	        player.sendEvent('STOP');	
			jQuery('#gallery-popup-outer').fadeOut(300,function(){
				jQuery('#gallery-popup-overlay').fadeOut('fast');
			});
			return true;
		}
	});
	
	jQuery('#guardavideo').click(function() {
		jQuery('#gallery-popup-outer').centerDiv();
		jQuery.openGallery();
	});

	jQuery('#gallery-popup-overlay').click(function() {
		jQuery.closeGallery();
	});
	
	jQuery('#gallery-popup-close').click(function() {
		jQuery.closeGallery();
	});
		
}); 