var jsReady = false;


jQuery(document).ready( function()
{
	jsReady = true;
	var randomnumber=Math.floor(Math.random()*10000);
	
	$("a#chiaro").click( function(e) { 
		e.preventDefault();
		var flashbox = "<div id='flashbox'>\
			<div id='flashboxcontent'>\
			</div>\
		</div>";
		$("body").append(flashbox);
		$('#flashbox').css("border", "1px solid #F97F12" );
		
		if (jQuery.browser.msie && jQuery.browser.version.substr(0,1)=="6")
			$('#flashbox').css("position", "absolute" );
		
		var flashvars = { 
			lang:"IT",
			location_href:location.href,
			book_folder:"/anteprime/books/chiaro_preview/"
		};
		var params = { allowscriptaccess:"always", allowfullscreen:"true" };
		var attributes = { id: "flashboxcontent", name: "flashboxcontent" };

		// embed banner chiaro
		swfobject.embedSWF("/anteprime/KFlipBookPlayer.swf?"+randomnumber, "flashboxcontent", "100%", "100%", "9.0.28","expressInstall.swf", flashvars, params, attributes); 
		
		// unbind domaniresize and reset css
		$(window).unbind( "resize", resizeFlashBox ); 
		$('#flashbox').css({
			"top":"2%",
			"left":"1%",
			"width": "98%",
			"height": "96%"
		});
		
	});
	
	
	$("a#domani").click( function(e) { 
		e.preventDefault();
		var flashbox = "<div id='flashbox'>\
			<div id='flashboxcontent'>\
			</div>\
		</div>";
		$("body").append(flashbox);
		$('#flashbox').css("border", "1px solid #F97F12" );
		if (jQuery.browser.msie && jQuery.browser.version.substr(0,1)=="6")
			$('#flashbox').css("position", "absolute" );

		var flashvars = {};
		var params = { allowscriptaccess:"always", allowfullscreen:"true" };
		var attributes = { id: "flashboxcontent", name: "flashboxcontent" };

		// embed banner domani
		swfobject.embedSWF("/anteprime/Domani1WebPreview.swf?"+randomnumber, "flashboxcontent", "100%", "100%", "9.0.28","expressInstall.swf", flashvars, params, attributes); 
		
		// bind domani resize and resize
		$(window).bind( "resize", resizeFlashBox ); 
		resizeFlashBox();
	});	
	
	// calcolo dimensioni window per calcolo ratio
	var domanidivaspectratio = 1024/768;
	
	// domani resize handler
	function resizeFlashBox() {
		var winW = $(window).width();
		var winH = $(window).height();
		var winAR = winW/winH;
		var boxW,boxH,boxL,boxT;
		if( winAR > domanidivaspectratio ) {
			// center H keep V
			boxH = winH - 20;
			boxW = boxH * (1024/768);
			boxL = (winW-boxW)/2;
			boxT = 10;
		} else {
			// center V keep H
			boxW = winW - 20;
			boxH = boxW * (768/1024);
			boxT = (winH-boxH)/2;
			boxL = 10;
		}
		$('#flashbox').css({
			"left":boxL+"px",
			"top":boxT+"px",
			"width": boxW+"px",
			"height": boxH+"px"
		});
	}

});



function isReady() {
	return jsReady;
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

function sendToActionScript(value) {
	thisMovie("flashboxcontent").sendToActionScript(value);
}

function sendToJavaScript(value) {
	alert(value);
	alert($("#flashboxcontent").sendToActionScript("deh"));
	sendToActionScript(location.href);
}

function closeFlashBox() {
	$("#flashbox").remove();
}

