
var global_perc = 'http://anteprima.provincia.tn.it/pat_giunta_09/';

var global_lang = '_it';

/********************************************************************************************************************************************************************************/
var zooming = {
	idx:				null,
	list:				null,
	z:					null,
	height_adj:			null,

	getScrolling:		function() {
							var obj = jQuery(window);
							return { top: obj.scrollTop()-0, left: obj.scrollLeft()-0 };
						},
	getObjectDims:		function(obj) {							
							return { width: obj.width()-0, height: obj.height()-0 };
						},
	getWindowDims:		function() {
							return zooming.getObjectDims(jQuery(window));
						},
	getDocumentDims:	function() {
							return zooming.getObjectDims(jQuery(document));
						},
	getBodyDims:		function() {
							return zooming.getObjectDims(jQuery('body'));
						},
	getZoomDims:		function(img) {
							var wind = zooming.getWindowDims();
							var ar = img.width / img.height;		
							if (img.width + 40 > wind.width) {
								img.width = wind.width - 60;
								img.height = Math.round(img.width / ar);
							}
							if (img.height + 80 > wind.height) {
								img.height = wind.height - 100;
								img.width = img.height * ar;
							}		
							return { width: img.width, height: img.height };
						},
	configNoImage:		function(z) {
							if (z.size || z.size != 'undefined') {
								z.width = 200;
								z.height = 140;
							}
							return z;
						},
	gallery:			function (idx, list) {			// ### called to show gallery ###
							zooming.background();
							zooming.image(idx, list);
						},
	resize_bg:			function(body, zct, zbg) {								
							zct.css({
										width:				body.width+'px',
										height:				body.height+'px',
										position:			'absolute',
										top:				'0px',
										left:				'0px',
										zIndex:				'999998',
										overflow:			'hidden'
									});
							zbg.css({
										width:				body.width+'px',
										height:				body.height+'px',
										backgroundColor:	'#000000',
										opacity:			'0.5',
										filter:				'alpha(opacity=50)',
										position:			'absolute',
										top:				'0px',
										left:				'0px',
										zIndex:				'999999'
									});
							setTimeout(function(){ //serve a sincronizzare correttamente IE
								var docu = zooming.getDocumentDims();
								if (docu.width != body.width) {
									zct.css({
											width:				docu.width+'px',
											height:				body.height+'px',
											position:			'absolute',
											top:				'0px',
											left:				'0px',
											zIndex:				'999998',
											overflow:			'hidden'
										});
									zbg.css({
											width:				docu.width+'px',
											height:				body.height+'px',
											backgroundColor:	'#000000',
											opacity:			'0.5',
											filter:				'alpha(opacity=50)',
											position:			'absolute',
											top:				'0px',
											left:				'0px',
											zIndex:				'999999'
										});
								}
							},1);
						},
	background:			function () {
							var zct = jQuery('<div class="zooming_dlg"></div>');			
							var zbg = jQuery('<div class="zooming_bgi"></div>');
							zooming.resize_bg(zooming.getBodyDims(), zct, zbg);
							jQuery('body').append(zct);
							jQuery('.zooming_dlg').append(zbg);
						},
	positionit:			function(dlg, z, height_adj) {
							if ((jQuery.browser.mozilla || jQuery.browser.safari) && (navigator.appVersion+'').indexOf('Chrome') < 0) {
								if (dlg.find('object').length > 0) {
									dlg.hide();
								}
							}
							var docu = zooming.getDocumentDims();
							var wind = zooming.getWindowDims();
							var scroll = zooming.getScrolling();							
							dlg.css({
										width:				docu.width + 'px',
										height:				docu.height + 'px',
										backgroundColor:	'transparent',
										position:			'absolute',
										top:				( scroll.top + Math.round((wind.height -z.height -height_adj) / 2) ) +'px',
										left:				'0px',
										zIndex:				'9999991'
									});
							dlg.stop(true);
							if ((jQuery.browser.mozilla || jQuery.browser.safari) && (navigator.appVersion+'').indexOf('Chrome') < 0) {
								if (dlg.find('object').length > 0) {
									dlg.show();
								}
							}
						},
	attach_events:		function(idx, list) {
							jQuery('.close_image_gal').click(function(){
								jQuery('.zooming_dlg').remove();
								jQuery(window).unbind('scroll', zooming.scroll_hook);
								jQuery(window).unbind('resize', zooming.resize_hook);
							});

							if (list.length > 1) {
								jQuery('.prev_image_gal').click(function(){
									if (jQuery(this).find('img').attr('src').indexOf('_dis') < 0) {
										jQuery('.zooming_img').remove();
										zooming.show(idx-1, list);
									}
								});
								jQuery('.next_image_gal').click(function(){
									if (jQuery(this).find('img').attr('src').indexOf('_dis') < 0) {
										jQuery('.zooming_img').remove();
										zooming.show(idx+1, list);
									}
								});
							}
						},
	resize_to:			function (z, ddim) {
							var asprat = z.width / z.height;
							if (z.width > ddim.width) {
								z.width = ddim.width;
								z.height = Math.round(z.width / asprat);
							}
							if (z.height > ddim.height) {
								z.height = ddim.height;
								z.width = Math.round(z.height * asprat);
							}
							return z;
						},
	resize_zoom:		function(z, height_adj) {
							var wd = zooming.getWindowDims();
							if (z.width > wd.width -40 || z.height > wd.height-(height_adj +40)) {
								z = zooming.resize_to(z,{ width: wd.width -40, height: wd.height-(height_adj +40) });
							}
							return z;
						},
	resize_tpl:			function(z, height_adj) {
							if (! z.isVideo) {
								z.width = z.original_width;
								z.height = z.original_height;
								z = zooming.resize_zoom(z, height_adj);
								jQuery('.zoomed_image').css({
																width:  (z.width +22)+'px',
																height: (z.height +height_adj)+'px'
															});
								var zp = jQuery('.zoomed_picture');
								zp.attr('width', z.width);
								zp.attr('height', z.height);
							}
						},
	show:				function(idx, list) {
							var isGallery = false;
							var height_adj = 50;
							if (list.length > 1) {
								isGallery = true;
								height_adj = 70;
							}

							var z = list[idx];
							z.original_width = z.width;
							z.original_height = z.height;

							zooming.z = z;
							zooming.height_adj = height_adj;

// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
							var isImage = true;
							if (z.size) {
								isImage = false;
								z = zooming.configNoImage(z);									
							}
							else {
								z = zooming.resize_zoom(z, height_adj);
							}

							var isVideo = false;
							if (z.isVideo) {
								isVideo = true;
							}

							var dlg = jQuery('<div class="zooming_img" align="center"></div>');
							zooming.positionit(dlg, z, height_adj);
							var closebut = {
											'_it':	'CHIUDI',
											'_en':	'CLOSE'
										};

							var extra_style = '';
							if (isGallery) {								
								if (jQuery.browser.msie) {
									extra_style = ' style="margin-top:5px;"';
								}
							}
							else {
								extra_style = ' style="margin-top:10px;"';
								if (jQuery.browser.msie) {
									extra_style = ' style="margin-top:15px;"';
								}
							}

							if (isGallery) {
								var arrow_sx = 'foto_sx_dis';
								if (idx > 0) {
									arrow_sx = 'foto_sx';
								}
								var arrow_dx = 'foto_dx_dis';
								if (idx < list.length-1) {
									arrow_dx = 'foto_dx';
								}
							}

							var dialog = '';
							dialog += '<div class="zoomed_image" style="background:#FFFFFF; border:1px solid #666; width:'+(z.width +22)+'px; height:'+(z.height +height_adj)+'px;">';
								//dialog += '<div style="padding:10px 10px 50px 10px;">';
								dialog += '<div style="padding:10px 10px 10px 10px;">';
									if (isVideo) {
										dialog += '<object style="display:block;" width="'+z.width+'" height="'+z.height+'"><param name="movie" value="http://www.youtube.com/v/'+z.url+'&hl=it&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+z.url+'&hl=it&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+z.width+'" height="'+z.height+'" style="display:block;"></embed></object>';
									}
									else {
										if (isImage) {
											dialog += '<img class="zoomed_picture" src="'+z.url+'" width="'+z.width+'" height="'+z.height+'" style="border:1px solid #C5C2BC;" />';
										}
										else {
											var ext = 'FILE';
											var arr = z.url.split('.');
											ext = (arr[arr.length-1]+'').toUpperCase();
											dialog += '<a href="'+z.url+'" style="text-decoration:none;">';
												dialog += '<img class="zoomed_picture" src="../../immagini/polaroid.png" width="'+z.width+'" height="'+z.height+'" />';
												dialog += '<div style="text-align:left; margin-left:70px; margin-top:-100px; font-size:1em; height:100px; color:#888; font-weight:bold;">'+ext+', '+Math.round(z.size/1024)+' KB</div>';
											dialog += '</a>';
										}
									}
									dialog += '<div align="center"'+extra_style+'>';
										if (isGallery) {
											dialog += '<div class="title_image_gal" style="font-size:0.9em; font-weight:bold; color:#0099D3; font-family:Arial,Helvetica,sans-serif;height:35px;overflow:hidden;text-align:left;">';
												dialog += '<table border="0" cellspacing="0" cellpadding="0" style="height:1.8em;"><tr><td style="vertical-align:middle;">';
												dialog += z.title;
												dialog += '</td></tr></table>';
											dialog += '</div>';
											dialog += '<div class="prev_image_gal" style="width:12px;float:left;cursor:pointer;"><img src="http://'+custom_OD.SERVER['SERVER_NAME']+'/ravennafestival2009'+'/immagini/'+arrow_sx+'.gif" /></div>';
											dialog += '<div class="next_image_gal" style="width:12px;float:right;cursor:pointer;"><img src="http://'+custom_OD.SERVER['SERVER_NAME']+'/ravennafestival2009'+'/immagini/'+arrow_dx+'.gif" /></div>';
										}
										dialog += '<div style="text-align:center;"><span class="close_image_gal" style="cursor:pointer;font-size:0.7em;">'+closebut[global_lang]+'</span></div>';
									dialog += '</div>';
								dialog += '</div>';
							dialog += '</div>';
							jQuery('.zooming_dlg').append(dlg);
							jQuery('.zooming_img').append(dialog);							
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
							zooming.attach_events(idx,list);
						},
	scroll_hook:		function() {	//alert('scroll');
							zooming.positionit(jQuery('.zooming_img'), zooming.z, zooming.height_adj);
						},
	resize_hook:		function() {	//alert('resize');
							zooming.resize_bg(zooming.getBodyDims(), jQuery('.zooming_dlg'), jQuery('.zooming_bgi'));
							zooming.resize_tpl(zooming.z, zooming.height_adj);
							zooming.positionit(jQuery('.zooming_img'), zooming.z, zooming.height_adj);
						},
	image:				function (idx, list) {
							zooming.show(idx, list);

							jQuery(window).bind('scroll', zooming.scroll_hook);
							jQuery(window).bind('resize', zooming.resize_hook);
						}
};
/********************************************************************************************************************************************************************************/
function zoom_video(zoom_yt_id) {
	zooming.gallery(0, [{url:zoom_yt_id, width:425, height:344, isVideo:1}] );
	return false;
}

/**************************************************************************
*                                                                                                             *
*		PARTE JQUERY                                                                          *
*                                                                                                             *
**************************************************************************/
	
jQuery.noConflict();
jQuery(document).ready(function(){
	//alert('So Long, and Thanks for All the Fish');
	if (jQuery('.jq-map-imm').length>0) {
		/*jQuery('area').click(function(){
			var myalt = ''+jQuery(this).attr('alt');
			myalt = myalt.replace(' - ',"\n");
			var myurl = ''+jQuery(this).attr('href');
			jQuery(this).attr('href','#');
			//alert(myalt);
			jQuery(this).bt({
								padding: 		20,
								width: 			100,
								spikeLength: 	40,
								spikeGirth: 	40,
								cornerRadius: 	40,
								fill: 			'rgba(0, 0, 0, .8)',
								strokeWidth: 	3,
								strokeStyle: 	'#CC0',
								cssStyles: 		{color: '#FFF', fontWeight: 'bold'}
							});
			return false;
		});*/
		jQuery('area').each(function(idx){
			var corner_where = ['bottomLeft','bottomLeft','bottomLeft','bottomMiddle','bottomMiddle','bottomMiddle','bottomRight','bottomRight','bottomRight'];
			var x_offsets = [-30,-30,-35,-150,-160,-165,-280,-280,-270];
			var y_offsets = [-265,-260,-245,-245,-265,-295,-270,-275,-240];
			//.qtip .qtip-tip{ -moz-opacity: 0.8; -webkit-opacity: 0.8; opacity: 0.8; filter:alpha(opacity=80); }
/*			var coords = ''+jQuery(this).attr('coords');
			var coordsplit = coords.split(',');*/
/*			var areadiv = jQuery('<div style="position:absolute;left:'+(coordsplit[0]-0+jQuery('.jq-map-imm').position().left)+'px;top:'+(coordsplit[1]-0+jQuery('.jq-map-imm').position().top)+'px;width:'+(coordsplit[2]-coordsplit[0])+'px;height:'+(coordsplit[3]-coordsplit[1])+'px;background:rgb('+(Math.floor(Math.random()*256))+','+(Math.floor(Math.random()*256))+','+(Math.floor(Math.random()*256))+');overflow:hidden;"></div>');
			jQuery('body').append(areadiv);
*/
			/*var myurl = ''+jQuery(this).attr('href');
			jQuery(this).attr('href','#');*/
			var myalt = ''+jQuery(this).attr('alt');
			myalt = '<div style="font-size:0.8em;"><strong>'+myalt.replace(' - ',"</strong><br/>")+'</div>';//+'<br>'+(coordsplit[3]-coordsplit[1]+110)
			jQuery(this).removeAttr('alt')			
			jQuery(this).qtip({
				content:	myalt,
				show:		'mouseover',
				hide:		'mouseout',
				position:	{
								adjust:		{	
												x:			x_offsets[idx],
												y:			y_offsets[idx]
											}
							},
				style:		{
								background:	'#202020',
								border:		{
												width: 1,
												radius: 4,
												color: '#AC8F5A'
											},
								tip:		{	// Now an object instead of a string
												corner:	corner_where[idx],	// We declare our corner within the object using the corner sub-option
												color:	'#AC8F5A',
												size:	{
															x:	24,		// Be careful that the x and y values refer to coordinates on screen, not height or width.
															y:	24		// Depending on which corner your tooltip is at, x and y could mean either height or width!
														}	
											},
								name: 'dark' 	// Inherit from preset style
							},
				api:		{
								onShow:		function() {
												jQuery('.qtip-contentWrapper').css({
													opacity:	0.9,
													filter:		'alpha(opacity=90)'
												});
											}
							}
			});
			/*jQuery(this).bt({
								padding: 		20,
								width: 			100,
								spikeLength: 	40,
								spikeGirth: 	40,
								cornerRadius: 	40,
								fill: 			'rgba(0, 0, 0, .8)',
								strokeWidth: 	3,
								strokeStyle: 	'#CC0',
								cssStyles: 		{color: '#FFF', fontWeight: 'bold'}
							});*/
		});
		/*jQuery('area').each(function(){
			var myurl = ''+jQuery(this).attr('href');
			jQuery(this).attr('href','#');
			jQuery(this).click(function(){
				var myalt = ''+jQuery(this).attr('alt');
				myalt = myalt.replace(' - ',"\n");
				alert(myalt);
				//setTimeout(function(){location.href=myurl;},3000);
				return false;
			});
		});*/		
	}

	// opacita bottone play lista video
	jQuery('.jq_play_button').css({
		'opacity':	0.75,
		'filter':	'alpha(opacity=75)'
	});
});
