﻿//<![CDATA[

// ItmWebSite.js

if (window.top != window.self) {window.top.location.replace(location.href);}
 debugger;

$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
	if ( options.dataType == 'script' || originalOptions.dataType == 'script' ) {
		options.cache = true;
	}
});


$(document).ready(function() {

// http://www.opera.com/support/kb/view/827/
	try{
		opera.setOverrideHistoryNavigationMode('compatible');
		history.navigationMode = 'compatible';
	}catch(ex){}

//CLASSMETEO
//var cm = document.getElementById('a_cm_module_13761')
//if (cm) {cm.href='http://classmeteo.weather.com/meteo/cm/todayPage.xhtml?idCity=ITXX0017'}
//cm = document.getElementById('script_cm_module_13761')
//if (cm) {cm.src='http://classmeteo.weather.com/ClassMeteoOnYourWebsite/cmwidget/WidgetServlet?uid=d28a3705-a8db-4bdd-b834-520a5715117a&div=cm_module_13761'}

// STAMPARE
// Crea il pulsante Stampare
//debugger;
//	$('span[id^="print"]').print({printText: '<img class="img-inline" src="App_Themes/Itm/printer.png" alt="" />', printTag: 'anchor'});

});


$(window).load(function() {

 debugger;
	var fb_share = $('#fb_share');
//alert ('fb_share'):
	var fb_like = $('#fb_like');
//alert ('fb_like');
	if ((fb_share.length > 0) || (fb_share.length > 0)) {

		$.getScript('https://connect.facebook.net/' + gItm.culture.replace('-', '_') + '/all.js', function(data, textStatus){
debugger;
//  alert(data); //data returned
//  alert(textStatus); //success
//  alert('Load was performed.');

			if (textStatus === 'success') {

															/*	FACEBOOK INIT	*/

debugger;
				window.fbAsyncInit = function() {
					FB.init ({
						appId      : gItm.fb_AppId, // App ID
						status     : true, // check login status
						cookie     : true, // enable cookies to allow the server to access the session
						oauth      : true, // enable OAuth 2.0
						xfbml      : true  // parse XFBML
					});
	//	channelURL : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File

	// Additional initialization code here
				};

// Metodo asincrono consigliato da Facebook
//	(function() {
//		var e = document.createElement('script');
//		e.src = document.location.protocol + '//connect.facebook.net/' + gItm.culture.replace('-', '_') + '/all.js';
//		e.async = true;
//		document.getElementById('fb-root').appendChild(e);
//	}());


															/*	FACEBOOK SHARE	*/

debugger;
				if (fb_share.length > 0) {

					$('#fb_share').click(function(e) {
						e.preventDefault();
						FB.ui( {
							method: 'feed',
							name: 'This is the content of the "name" field.',
							link: ' http://www.campingjonio.com/',
							picture: 'http://www.campingjonio.com/App_Themes/cpj_logo.png',
							caption: 'This is the content of the "caption" field.',
							description: 'This is the content of the "description" field, below the caption.',
							message: ''
						});
					});
				}
			}
		});
	}

															/*	TWITTER STREAM	*/

	var wdgTwitter = {};

// debugger;
	var twt_stream = $('#twt_stream');
	if (twt_stream.length > 0) {
//alert ('twt_stream')

		$.getScript('http://widgets.twimg.com/j/2/widget.js', function(data, textStatus){
//debugger;
		//	alert(data); //data returned
		//	alert(textStatus); //success
		//	alert('Load was performed.');

			if (textStatus === 'success') {

				wdgTwitter = new TWTR.Widget({
					id: 'twt_stream',
					title: '',
					version: 2,
					type: 'profile',
					rpp: 12,
					interval: 30000,
					width: 300,
					height: 150,
					theme: {
						shell: {
							background: '#8EB2B4',
							color: '#ffffff'
						},
						tweets: {
							background: '#BDD1D3',
							color: '#000000',
							links: '#657678'
						}
					},
					features: {
						avatars: true,
						fullscreen: false,
						hashtags: false,
						live: true,
						loop: false,
						scrollbar: true,
						timestamp: true,
						toptweets: true,
						behavior: 'all'
					}
				});
	// jQuery functions to initialize after the page has loaded.
				wdgTwitter.render().setUser('campingjonio').start();
				twt_stream.show();
			}
		});
	}
});

/// <summary>
/// Utilities
///		Decodifica gli indirizzi e-mail da esadecimale.
///		Carattere iniziale 0127 0x7f DEL NO Not allowed by RFC2822.
/// </summary>
/// <remarks>
/// Note:
//!http://www.ietf.org/rfc/rfc2068.txt
//| Servers should be cautious about depending on URI lengths above
//| 255 bytes, because some older client or proxy implementations
//| may not properly support these lengths.
//		if (this.href.length > 255) {throw new Error('MAILTO_HREF_LIMIT');}
///</remarks>
$(function() {
	$('a[href^="mailto:"]').each(function(i) {
//debugger;

		var xr = this.href.match(/^mailto:([0-9A-F]+)$/i);
		if(!xr) return;

//0127 0x7f DEL NO Not allowed by RFC2822.
		var x = xr[1].substr(2);
		var sz= x.length;
		var s = '';

		for (var j = 0; j < sz; j += 2) {
			s += String.fromCharCode(parseInt(x.substr(j, 2), 16));
		}

// optionally split real address from email addresses used by X.400 gateways
//		xr = s.split(/\|/); this.href = "mailto:" + xr[0]; if(xr.length > 1) $(this).html(xr[1]);

		this.href = 'mailto:' + s;
		$(this).empty();
//$.trim($(this).text(s));
		$(this).text(s);

	});
});

/// <summary>
/// Utilities
///		Inserisce pulsante o link per la stampa dell pagina.
///		Permette di non stampare gli elementi con classe notPrintClass.
/// </summary>
/// <remarks>
/// jQuery(function($) {$('#utilities>li:eq(1)').print();} );
///</remarks>
(function($) {
	$.fn.print = function(customOptions) {
//debugger;

		var options = $.extend({}, $.fn.print.defaultOptions, customOptions);
		var printClass = options.printClass;

		return this.each(function(i) {
			var id = options.printId + i.toString();
			$(this).append((options.printTag === $.fn.print.defaultOptions.printTag) ? '<button id=' + id + '" type="button" class="' + printClass + '"' + ((i === 0) ? (' accesskey="' + options.printAccessKey + '"') : '') + '>' + options.printText + '</button>&nbsp;' : '<a id="' + id + '" href="#" class="' + printClass + '"' + ((i === 0) ? (' accesskey="' + options.printAccessKey + '"') : '') + '>' + options.printText + '</a>');

			$(this).click(function() {
				var notPrint = $('.' + options.notPrintClass + '');
				notPrint.toggle();
				window.print();
				notPrint.toggle();
				return false;
			});
		});
	};

	$.fn.print.defaultOptions = {
		notPrintClass: 'notPrint',
		printClass: 'print filter',
		printId: 'Print',
		printText: 'Stampare',
		printTag: 'button',
		printAccessKey: '3'
	};

})(jQuery);

/// <summary>
/// Utilities
///		Crea ToolTip
/// </summary>
/// <remarks>
/// Note:
//|	http://stackoverflow.com/questions/4980088/jquery-error-null-or-not-an-object-any-jquery-ninjas-that-can-help#answer-4980409
//|	Vedi Itm.ToolTip per html e style
///</remarks>
$(function() {
	$('.tip_trigger').each(function() {
//debugger;
		var tip = $(this).find('.tip');

		$(this).hover (
			function() { tip.appendTo('body'); },
			function() { tip.appendTo(this); }
		).mousemove(function(e) {
			var x = e.pageX + 20,
			y = e.pageY + 20,
			w = tip.width(),
			h = tip.height(),
			dx = $(window).width() - (x + w),
			dy = $(window).height() - (y + h);

			if ( dx < 20 ) { x = e.pageX - w - 20; }
			if ( dy < 20 ) { y = e.pageY - h - 20; }

			tip.css({ left: x, top: y });
		});
	});

});

//]]>


