$(document).ready(function(){	
	$('.corn').corner("round 4px");
	$('.pres').hide().delay(150).fadeIn(300, function(){$('.land').pulse();});
	//$('.ban').delay(600).animate({backgroundPosition: -84}, 5200, function(){ $(this).delay(100).animate({backgroundPosition: -14}, 5800); });

	/*$('#logo').click(function(){
				$('#topMenu').animate({height: '208'}, 1460, function(){ });				
			});*/

	var myVar = "<a href=\"http://www.netd.it/articoli/#!article=L'importanza_della_presenza_sul_web\" class='under'><h1 class='news'>[news] New appended di prova <span class='little'>(I Vantaggi di un sito web per le piccole e medie imprese)</span></h1></a>";
	//$('.news').parent().prepend(myVar);	
	//$('.news').delay(300).rotator();
	//$('#n1').fadeIn().pulse();

	$('.noTl').mouseover(function(){
				$(this).attr('title', '');
				});

	$('.actBtn').live('click', function(){
			var url = $(this).attr('ur');
			if(url != undefined){
			nauauWindow(url, "no");
			}
			});

	if(document.location == "http://www.netd.it/"){
		jsImg = new Image();
		jsImg.onload = function(){
		//$('html').css('background', 'url("../backs/bk.jpg") no-repeat 50% 30px fixed #e9e9e9');
		}	
		jsImg.src = "../stk/bigBanEye.jpg";
	}

	
	if ($.browser.mozilla) {
		$('h1, h2').css('letter-spacing', '-2px');
		$('.news').css('letter-spacing', '0px');
	}


	$('.land').live('click', function(){
			var actToLoad = "../"+$(this).attr('act');
			var place = $(this).parent().parent();
			place.fadeOut(200, function(){
						place.load(actToLoad, function(){
										$('.corn').corner("round 4px");
										place.fadeIn();
										});
						});
			});

	$('.altLand').click(function(){
			var obj = $('.pres').find('.actBtn');
			obj.attr('act', $(this).attr('act'));
			obj.trigger('click');
			});
	

});


function fillImg(){
subdom=new Array("t1", "t2","t3");
var indurl = 0;
$(".imageThumb").each(function(index){
		if($(this).offset().top-$(document).scrollTop() > 0 && $(this).offset().top-$(document).scrollTop() < 9100){
		var uuid = $(this).attr('id');
		$(this).css('background', 'url(http://'+subdom[indurl]+'.nauau.com/thumbs/'+uuid+'.jpg.jpg) no-repeat center center');
		indurl++;
		if(indurl > 2){
		indurl = 0;
		}
		}
	}); 
}


function nauauWindow(url, square){

$('.overlay').remove();

var winWidth = 580;
var winHeight = 320;

if(square == "yes"){
var winWidth = 320;
var winHeight = 300;
}

$.ajaxSetup({  cache: true  }); // IMPORTANT !!!!!!!!

var thisDialogId = parseInt(Math.random()*Math.pow(10, 17));
var html = "<div class='nauauWin' id=\""+thisDialogId+"\"><div class='topBar'><a href=\"javascript:void(0)\"><div class='closeBtn'></div></a></div><div class='nauauWinContent'></div>";
var nauauWinQnt = $('.nauauWin').size();

var overHeight = $(document).height();//-64

var overlayCss = {
	'background-color' : '#000000',
	'width' : '100%',
	'height' : overHeight,
	'position' : 'absolute',
	'top' : '64px',
	'display' : 'none'
    }

var dialogCss = {
	'background-color' : '#252525',
	'font-weight' : '',
	'position' : 'fixed',
	'height' : winHeight+'px',
	'left' : (($('body').width()-580)/2)+((nauauWinQnt)*40),
	'top' : ((nauauWinQnt-1)*40+108)+'px',
	'width' : winWidth+'px',
	'color' : '#ffffff',
	'display' : 'none',
	'border' : 'solid 1px #090909',
	'z-index' : '30'
    }

var topBarCss = {
	'position' : 'absolute',
	'height' : '32px',
	'top' : '8px',
	'width' : '100%',
	'color' : '#ffffff'
    }

var dialogContentCss = {
	'position' : 'absolute',
	'top' : '46px',
	'width' : '92%',
	'height' : '84%',
	'margin-left' : '4%',
	'color' : '#ffffff'
    }

var closeBtnCss = {
	'width' : '32px',
	'margin-right' : '8px',
	'height' : '24px',
	'float' : 'right',
	'background' : '#223344 url("../../icons/onlyX.png") center center no-repeat'
    }

//$('body').append(html);
$('body').append("<div class='overlay'></div>").append(html);
$('.overlay').css(overlayCss).fadeTo(300, 0.9);
//$('#'+thisDialogId).css(dialogCss).corner().draggable().fadeIn(300).children('.dialogContent').html(content);
$('#'+thisDialogId).css(dialogCss).corner("round 4px").fadeIn(350).children('.nauauWinContent').load(url, function(){$(document).trigger('ajaxAppended');});
$('.topBar').css(topBarCss);
$('.nauauWinContent').css(dialogContentCss);
$('.closeBtn').css(closeBtnCss).corner("round 4px").hover(function(){$(this).css('backgroundColor', '#00CCFF');}, function(){$(this).css('backgroundColor', '#223344');}).click(function(){
$('.overlay').fadeOut(function(){$(this).remove()}); // REMOVE ALL OERLAYS
var elem = $(this).parent().parent().parent();
elem.fadeOut(260, function(){elem.remove()});
});
}

jQuery.fn.pulse = function() {
    $(this[0]).fadeTo(220, 0.1, function(){
			$(this).fadeTo(350, 1.0, function(){
				$(this).fadeTo(220, 0.1, function(){$(this).fadeTo(280, 1.0);});
			});
			});
};

jQuery.fn.rotator = function() {
	var start = 0;
	var list = new Array();
	var tt;

	this.hide().each(function(){
		list.push($(this));
		start = 0;		
	});

	$(document).trigger("rotatorEvnt");

	list[start].fadeIn(320, function(){$(document).trigger('rotatorEvnt');});

	$(document).bind('rotatorEvnt', function(){
		if(start < list.length-1){ start++; }else{ start = 0; }
		tt = setTimeout("$(document).trigger('clearEvnt');", 4600);
	});

	this.mouseenter(function(){clearTimeout(tt);});
	this.mouseleave(function(){clearTimeout(tt); tt = setTimeout("$(document).trigger('clearEvnt');", 2600);;});

	$(document).bind('clearEvnt', function(){
	$('.news').fadeOut(); list[start].delay(500).fadeIn(500, function(){$(document).trigger('rotatorEvnt');});
	});

};

