// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function() {
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
// make it safe to use console.log always
//(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});

// Apre la finestra della videocopertina e carica dinamicamente il video.

/*
function ShowVideoCopertina() {
	var urlVideo="http://tv.quattroruote.it/embed/314fcbca-c250-4122-bf5c-8d06aaf2a07c&ap=1&rnd="+Math.random();
	$("#frameVideoCopertina").attr("src", urlVideo).attr("width", "535").attr("height", "300");
	$("#dialog-videocopertina").dialog("open");
}
*/

$(document).ready( function() {
		
	// Accordion
	$("#accordion").accordion({ header: "h3" });
	
	// Tabs
	$('#tabs').tabs();
	
	// Dialog			
	$('#dialog').dialog({
		autoOpen: false,
		width: 470,
		modal: true,
		open: function() {		
			$('#dialog-password').dialog("close"); 
		}
		//show: "slide",
		//hide: "slide",
		//buttons: {
			//"Ok": function() { 
				//$(this).dialog("close"); 
			//}, 
			//"Cancel": function() { 
				//$(this).dialog("close"); 
			//} 
		//}
	});
				
	// Dialog			
	$('#dialog-password').dialog({
		autoOpen: false,
		width: 470,
		modal: true,
		open: function() {
			$('#dialog').dialog("close"); 
				}
		//show: "slide",
		//hide: "slide",
		//buttons: {
			//"Ok": function() { 
				//$(this).dialog("close"); 
			//}, 
			//"Cancel": function() { 
				//$(this).dialog("close"); 
			//} 
		//}
	});
				
	// Dialog	
	//$('#dialog-videocopertina').css({border:"4px solid red", position:"relative", top:"50px", right:"10px"}); 
	
	/*
	$('#dialog-videocopertina').dialog({
		autoOpen: false,
		width: 566,
		height:370,
		modal: false,
		show: "slide",
		hide: "slide",
		position: ['200', '400'],
		resizable: false,
		draggable:false,
		close: function() { 
			$("#frameVideoCopertina").attr("src", ""); 
		}
	});
	*/
	//$('#contenitore-video-copertina').append($('#dialog-videocopertina').parent());
	
	$('#sendToFriendDialog').dialog({
		autoOpen: false,
		width: 470,
		modal: true
	});
	
	// Dialog Link
	$('#login').click(function(){
		$('#dialog').dialog('open');
		return false;
	});
	
	
	// Dialog Link
	/*
	$('#open-videocopertina').click(function(){
		ShowVideoCopertina();
		return false;
	});
	*/
	
	// Dialog Link
	$('#recupera-password').click(function(){
		$('#dialog-password').dialog('open');
		return false;
	});

	// Datepicker
	$('#datepicker').datepicker({
		inline: true
	});
	
	// Slider
	$('#slider').slider({
		range: true,
		values: [17, 67]
	});
	
	// Progressbar
	$("#progressbar").progressbar({
		value: 20 
	});
	
	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
	
	
	try {
		if ($("#qrt-main .qrt-b").length > 0) {
			$("#qrt-main .qrt-b").textResize({
				createNav: 0,
				innerTags: "*",
				navHolder: "#tool-text",
				maxSteps: {
					increase: 5,
					decrease: 4
				}
			});
		}
	} catch (e) {
		// problems with IE7 on some pages...
		//alert(e.message);
		//$("#tool-text").hide();
	}
		
	 /*$("#simplePrint").click(function() {
         printElem({});
     });
     $("#PrintinPopup").click(function() {
         printElem({ printMode: 'popup' });
     });
     $("#ChangeTitle").click(function() {
         printElem({ pageTitle: 'thisWillBeTheNameInThePrintersLog.html' });
     });
     $("#PopupandLeaveopen").click(function() {
         printElem({ leaveOpen: true, printMode: 'popup' });
     });
     $("#stripCSS").click(function() {
         printElem({ overrideElementCSS: true });
     });
     $("#externalCSS").click(function() {
         printElem({ overrideElementCSS: ['http://assets3.github.com/stylesheets/bundle.css?180c214baeba2d8a1194e7b48ea7581cfee3e505'] });
     });*/
	//$('.articolo').printElement({});

// print x bottone in toolbox
	
	$(".print").click(function() {
		printFullPage({});
    });
});

function printFullPage(options) {
	$(".margini").printElement(options);
}

