$(document).ready(function() {
	eshopWizard();

	$('#holidays').hide();
	$('#holidays').slideDown('slow');

	// Source di esempio da una directory del sito
	id_comodo = 1;
	$('.example').each(function(){
		id_comodo++;
		$(this).before("<img class='source_show' src='/images/icon_zoom.png' title='Show the source'/> ")
		$(this).after("<pre id='" + id_comodo + "' class='prettyprint'>" + "Loading..." + "</pre>");
		$('#' + id_comodo).hide();
		$('#' + id_comodo).load('geturl.php?from=example&id=' + $(this).attr("dir") + "/" + $(this).text(), function() 		{prettyPrint()});
	});

	// Source di esempio da GitHub utenza AcmeSystems

	$('.github').each(function(){
		id_comodo++;
		$(this).before("[<a href='?id=playground' title='How to try this source on your FOX Board using the playground'>PG</a>] ");
		//$(this).before("<img class='source_show' src='/images/icon_playground.png' title='Show the source'/> ")
		$(this).after("<pre id='" + id_comodo + "' class='prettyprint'>" + "Loading from GitHub..." + "</pre>");
		$('#' + id_comodo).hide();

		if ($(this).attr("user")==undefined) {
			var url_to_get='geturl.php?class=github&user=AcmeSystems&project=playground&file=' + $(this).attr("file");
		} else {
			var url_to_get='geturl.php?class=github&user=' + $(this).attr("user") + '&project=' + $(this).attr("project") + '&file=' + $(this).attr("file");
		}
		$('#' + id_comodo).load(url_to_get, function() {
			prettyPrint();
		});
	});


	$('.example').click(function() {
		$(this).next().toggle('slow');
	});

	$('.github').click(function() {
		$(this).next().toggle('slow');
	});

	$('.source_show').click(function() {
		$(this).next().next().toggle('slow');
	});
	
	// Gestione tasto TIP
	id_tips=0;
	$('.tip').each(function(){
		$(this).before('<img id="' + (id_tips++) +'" src="images/icon_tip.png" class="tip_icon" title="Click to view the tip"/> <span class="tip_title">' + $(this).attr("title") + '</span>');
		$(this).hide();
	});

	$('.tip_icon').click( function() {
		$(this).next().next().toggle('slow');
	});

	$('.tip_title').click( function() {
		$(this).next().toggle('slow');
	});

	// Levare questo commento per abilitare la pubblicita
	// sulla sinistra
	// setInterval('getAvd()',12000);
});

var focusFlag = 1;

jQuery(window).bind("focus", function(event) {
	focusFlag = 1;
});

jQuery(window).bind("blur", function(event) {
	focusFlag = 0;
});

// Pubblicita sulla colonna a sinistra 

function getAvd() {
	$.getJSON('adv/adv.php', function(data) {
		$.each(data, function(key, val) {
			if (key=="name") {
				$('#adv_icon').html("<img src='/adv/" + val + ".png' border='0' title='Click to see the link'>");
			}
			if (key=="link") {
				$('#adv_link').attr('href',val);
			}
		});	
		avdIn();
		setTimeout('avdOut()',10000);
	});
}

function avdIn() {
	if (focusFlag==1) {
		$('#adv_icon').animate ({
			'left' : '5px'
		},'slow');
	}
}

function avdOut() {
	if (focusFlag==1) {
		$('#adv_icon').animate ({
			'left' : '-200px'
		},'fast');
	}
}


