/**
 * D.M.Maresca
 */

$(document).ready(function(){
	
	$('#lnkGallery').click(function(){
		gallery();
		return false;
	});
						   
	$('a.fancybox').fancybox({
		'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		'frameWidth': 600,
		'frameHeight': 500
	});

	if (document.getElementById('offers') != null) {
		offers();
	}
	
	$('a.blank,a.new').click(function(){
		window.open(this.href);
		return false;
	});
});

function offers(){
	var offers = $("#sidebar #offers li:gt(0)");
	var index = 0;
	offers.hide();
	
	setInterval(function(){
		$("#sidebar #offers li:eq("+(index-1)+")").fadeOut(2000);
		if(index>offers.length) index=0;
		$("#sidebar #offers li:eq("+(index)+")").fadeIn(2000);
		index++;
	},10000);
	
}

function gallery(){
	var overlay = $(document.createElement('div'));
	var newGallery = $(document.createElement('div'));
	var fullGallery = $(document.createElement('div'));
	var close = $('<img src="/images/gallery/close.png" alt="Close" />');
	overlay.attr('id','overlay');
	newGallery.attr('id','newGallery');
	fullGallery.attr('id','fullGallery');
	close.attr('id','close');
	overlay.css({position:'absolute','top':'0px','left':'0px','width':'100%','height':'100%','background':'#333','opacity':0})
		   .fadeTo('slow',0.5);
	close.css({position:'absolute','top':'5px','right':'5px','cursor':'pointer','z-index':'5'})
		.click(function(){
			$(window).unbind('scroll');
			$(this).remove();
			$('#overlay').remove();
			$('#newGallery').remove();
		});
	newGallery.css({position:'absolute','top':'0px','left':'0px','width':'100%','height':'100%','background':'url(/images/gallery/loader.gif) center center no-repeat'})
			  .append(fullGallery);
	var margintop = document.documentElement.scrollTop + 'px';
	$('body').append(overlay)
			 .append(newGallery)
			 .append(close);
	$(window).bind('scroll',function() {
			var margintop = document.documentElement.scrollTop + 'px';
	        $('#overlay,#newGallery,#close').css({'marginTop': margintop});
	})
	swfobject.embedSWF("/images/gallery/new2/gallery.swf", "fullGallery", "100%", "100%", "9.0.0", false, null,{wmode:"transparent"},null);
	$('#overlay,#newGallery,#close').css({'marginTop': margintop});
	return false;
}

