// JavaScript Document

function showMessages() {
	jQuery("#messages").css("opacity",0.8).animate({top:0},1000,function callback() {
		var timeout = setTimeout("hideMessages()",6000);														   
	});	
}

function hideMessages() {
	jQuery("#messages").animate({top:"-80px"},600);
}

function showPromotion(PromotionID) {
	$.ajax({
		type	: "POST",
		cache	: false,
		url		: "/Resources/Php/autoload-event.php?p=show-content",
		data    : {lang: lang, langurl: langurl, PromotionID:PromotionID},
		success: function(data) {
			if(data != '0') {
				$.fancybox.showActivity();
				$.fancybox(data, 
				{
					'autoDimensions'	: true,
					'width'         	: 'auto',
					'height'        	: 'auto',
					'transitionIn'		: 'elastic',
					'enableEscapeButton': true,
					'speedOut'      : 0,
					'centerOnScroll'    :  true,
					'overlayShow'       : PromotionID == 0 ? true : false,
					'onClosed'          : function() {
						$.ajax({
							type	: "POST",
							cache	: false,
							url		: "/Resources/Php/autoload-event.php?p=set-session"
						});
					}
				});
			}
		}
	});
	
}

function hidePromotion() {
	$.fancybox.close();
}

jQuery(document).ready(function() {

	jQuery('.hpromotie').each(function() {
		var prom = jQuery(this);
		prom.mouseenter(function() {
			var id = prom.attr("id");
			 	id = id.split("-");
				id = id[1];
			
			showPromotion(id);
			
		}).mouseleave(function() {
			hidePromotion();	
		});
	});
	
	$('marquee').marquee('marquee').mouseover(function () {
	  $(this).trigger('stop');
	}).mouseout(function () {
	  $(this).trigger('start');
	}).mousemove(function (event) {
	  if ($(this).data('drag') == true) {
		this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
	  }
	}).mousedown(function (event) {
	  $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
	}).mouseup(function () {
	  $(this).data('drag', false);
	});
	
	jQuery(".lightbox").fancybox({
		'zoomSpeedIn'		:	500,
		'zoomSpeedOut'		:	500,
		'transitionIn'      :   'elastic',
		'transitionOut'     :   'elastic',
		'centerOnScroll'    :   true
	});
	
	jQuery(".rounded").corner();
	
	if(showMessage)
		showMessages();
		
	if(scrollPage)
		jQuery(this.window).scrollTo( jQuery('#navigare'), 800);
	
	/*jQuery(window).bind("scroll",function(e) {
		//alert(e.pageY);
		jQuery("#messages").css("top",e.pageY + "px");									
	});*/
	
	if(showAutoloadEvent)
		showPromotion(0);
		
	var docSize = jQuery(window).width();
	docSize -= 986;
	
	if(parseInt(docSize / 2) > 133) {
		jQuery(".right-banner").css("right","0").css("display","block");	
	} else {
		jQuery(".right-banner").css("display","block");
	}
	
	jQuery(window).resize(function(){
		var docSize = jQuery(this).width();
		docSize -= 986;
		if(parseInt(docSize / 2) > 133) {
			jQuery(".right-banner").css("right","0");	
		} else {
			jQuery(".right-banner").css("right","-113px");
		}						   
	});
	jQuery("body").css("min-width","986px");
});

