var Browser = Class.create({
  initialize: function() {
    var userAgent = navigator.userAgent.toLowerCase();
    this.version = (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1];
    this.safari = /webkit/.test( userAgent );
    this.opera = /opera/.test( userAgent );
    this.msie = /msie/.test( userAgent ) && !/opera/.test( userAgent );
    this.mozilla = /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent );
  }
});

function ShowOver (_top,_left) {
	arrayPageSize=getPageSize();
	
	$('container').insert({after: '<div id="wOver_overlay" style="display: none;"></div>'});	

	$('wOver_overlay').style.width=arrayPageSize[0]+'px';
	$('wOver_overlay').style.height=arrayPageSize[1]+'px';	
	$('wOver_overlay').show();
	$('wOver_overlay').setOpacity(0.8);
	
	
	//SET WAIT
	$('container').insert({top: '<div id="wOver" style="display:none;"><div id="wOverContainer"><img src="/img/loader2.gif" width="16" height="16" border="0" align="absmiddle" /> loading...</div></div>'});
	//SET POS
	$('wOverContainer').setStyle({ 
		top: (_top?_top:(document.viewport.getScrollOffsets().top+Math.ceil((arrayPageSize[3]-$('wOverContainer').getHeight())/2)))+'px', 
		marginLeft: (_left?_left+'px':(document.viewport.getScrollOffsets().left+Math.ceil((arrayPageSize[2]-300)/2))+'px')
	});	

	$('wOver').show();
}


function OpenPlayerVideo(file) {
	arrayPageSize=getPageSize();

	var bro=new Browser;	
	

	$('container').insert({top: '<div id="wOver" style="display: none; height: '+arrayPageSize[1]+'px;"><div id="wOverContainer" style="width: '+arrayPageSize[0]+'px; "><div style="text-align:center;" ><br /><br /><div style="background-color:#FFF; width:320px; height:280px; padding-top:10px;text-align:center;margin:auto;"><div id="video_mina_caramella"></div><div style="width:320px;  margin:0 auto; margin-bottom:10px; margin-right:10px;"><br /><a href="#" onClick="CloseOver()" style="font-family:Verdana;font-size:11px;text-decoration:none;font-weight:bold;color:#ff0000;">Chiudi</a></div></div></div></div></div>'});
        
	swfobject.embedSWF('/swf/mina_caramella.swf', 'video_mina_caramella', '300', '250', '9.0.45','/swfobject/expressinstall.swf',{allowFullScreen: 'true', bgcolor: '#000000', menu: 'false', wmode: 'opaque'}, {id: 'video_mina_caramella'});
	
	/*$('container').insert({after: '<div id="wOver_overlay" style="display: none;"></div>'});
	$('wOver_overlay').style.width=arrayPageSize[0]+'px';
	$('wOver_overlay').style.height=arrayPageSize[1]+'px';	
	$('wOver_overlay').show();
	$('wOver_overlay').setOpacity(0.6);*/
  
        	
	var _top=document.viewport.getScrollOffsets().top+Math.ceil(arrayPageSize[3]/2-200);
				
	if (Prototype.Browser.IE && bro.version<7) {
		var _left=document.viewport.getScrollOffsets().left+Math.ceil(arrayPageSize[2]/2);
		$('wOverContainer').setStyle({ 
			top: _top+'px', 
			left: _left+'px'
		});	
	} else {
		$('wOverContainer').setStyle({ 
			top: _top+'px'
		});
	}
	
	$('wOver').show();	
	
	return false;
}

function CloseOver () {
	$('wOver').remove();
	return false;
}


// -----------------------------------------------------------------------------------
// getPageSize() from lightbox by Lokesh Dhakar
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
// 2 Edit by me
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}
