root = '/'; 
jQuery(document).ready(function() {
	contentWidth = 0;
	//fotoFondo.init();------
	screenshotPreview();
//	alert()
	jQuery('.box').each(function(){ contentWidth += jQuery(this).width()+parseInt(jQuery(this).css('padding-right'))+1; });
	jQuery('.content').css({'width': contentWidth+'px'});contentWidth+'px';
	
	jQuery('#email').focus(function(){
		if (jQuery('#email').val() == 'e-mail') {jQuery('#email').val('')}
	}).blur( function(){
		if (jQuery('#email').val() == '') {jQuery('#email').val('e-mail')}
	})
	
	jQuery('.container').bind('mousewheel', function(event, delta) {
		var dir = delta > 0 ? -120 : 120;
		jQuery(this).scrollLeft(jQuery(this).scrollLeft() + dir);
		return false;
	});

	jQuery.ajax({
		url: root+"dream/dream.txt",
		dataType: 'json',
		success: function(msg){
			var numRand = Math.floor( Math.random()*(msg.length) )
			jQuery.get(root+'dream/'+msg[numRand].id+'.html', function(data) {
				jQuery('#top').html(data);
				fotoFondo.init();
			});
		}
	});
	jQuery.get(root+'footer/inc_footer.html', function(data) {
		jQuery('.footer').html(data);
	});

	
	jQuery('#newsError a').click(function() {
		jQuery('#formNewsletter').css('display','block');
		jQuery('#newsError').css('display','none');
		return false;
	});
	
	jQuery('#formNewsletter').submit(function() {
																						
		jQuery.ajax({
			type: "POST",
			url: " /newsletter.php",
			data: jQuery('#formNewsletter').serialize(),
			success: function(msg){
				jQuery('#formNewsletter').css('display','none');
				jQuery('#newsSend').css('display','block');
			},
			error: function(){
				jQuery('#formNewsletter').css('display','none');
				jQuery('#newsError').css('display','block');
			}
		});
		return false;
	});
	
	
});


var fotoFondo = {
	winwidth : jQuery(window).width(),
	winheight : jQuery(window).height()-420,
	contenedor : '.sourceimage',
	fotoHeight : '',
	fotowidth : '',
	img : jQuery(".sourceimage img"),
	init :function(e) {
		jQuery(window).bind("resize", function(){
			fotoFondo.winwidth = jQuery(window).width();
			fotoFondo.winheight = jQuery(window).height()-420;
			fotoFondo.rfondo();
		});
		fotoFondo.rfondo();
	},
	rfondo : function(){
		//alert(fotoFondo.winwidth);
		jQuery(fotoFondo.contenedor).css({
			'width': fotoFondo.winwidth+'px',
			'height': fotoFondo.winheight+'px'
		});
		//jQuery('.container').css({'width': fotoFondo.winwidth+'px'});
		if( jQuery(fotoFondo.contenedor).is('.imageResize') ) {		
			fotoFondo.fotoheight = fotoFondo.winwidth * jQuery(fotoFondo.contenedor+" img").height() / jQuery(fotoFondo.contenedor+" img").width();
			if (fotoFondo.winheight > fotoFondo.fotoheight) {
				fotoFondo.fotowidth = jQuery(fotoFondo.contenedor+" img").width() * fotoFondo.winheight / jQuery(fotoFondo.contenedor+" img").height();
				jQuery(fotoFondo.contenedor+" img").attr({
					width: fotoFondo.fotowidth,
					height: fotoFondo.winheight
				}).css({
					'left': -(fotoFondo.fotowidth-fotoFondo.winwidth)/2+'px',
					'top' : 0
				});
			} else {
				jQuery(fotoFondo.contenedor+" img").attr({
					width: fotoFondo.winwidth,
					height: fotoFondo.fotoheight
				}).css({
					'left': 0,
					'top' : -(fotoFondo.fotoheight-fotoFondo.winheight)/2+'px'
				});
			}
		}
	}
}

/*
 * Url preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.screenshotPreview = function(){	
	/* CONFIG */
		
		yOffset = 100;
		xOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	jQuery("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		jQuery("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		jQuery("#screenshot")
			.css("bottom",(yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		jQuery("#screenshot").remove();
    });	
	jQuery("a.screenshot").mousemove(function(e){
		jQuery("#screenshot")
			.css("bottom",(yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px");
	});			
};