function html_entity_decode(str) {
  var ta=document.createElement("textarea");
  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
  return ta.value;
}
	
	
	  // getPageScroll() by 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;	
	    }
	    return new Array(xScroll,yScroll) 
	  }
	
	  // Adapted from getPageSize() by quirksmode.com
	  function getPageHeight() {
	    var windowHeight
	    if (self.innerHeight) {	// all except Explorer
	      windowHeight = self.innerHeight;
	    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	      windowHeight = document.documentElement.clientHeight;
	    } else if (document.body) { // other Explorers
	      windowHeight = document.body.clientHeight;
	    }	
	    return windowHeight
	  }

	$(function() {
				
		//if ($.browser.msie && $.browser.version.substr(0,1)<7) ;//return true;

		$("#register_member_form").validate();
		
		$('#slideshow').serialScroll({
			items:'li',
			//offset:-230, //when scrolling to photo, stop 230 before reaching it (from the left)
			//start:2, //as we are centering it, start at the 2nd
			duration:9000,
			force:true,
			//stop:true,
			//lock:false,
			interval:1,
			cycle:true, //don't pull back once you reach the end
			easing:'linear', //use this easing equation for a funny effect
		});
		
		$('#slideshow a').lightBox();
		
		$("#filters input[type=checkbox]").change( function() {
			if($(this).val()=='tutti') {
				if($(this).is(':checked')) {
	  				$("#filtra").unCheckCheckboxes();
	  				$("#filtra").toggleCheckboxes("#m_tutti");//attr('checked')
	  			}
			} else {
				$('#m_tutti').attr('checked', false);
			}
			$("#filtra").submit();
		});
		
		$("#filters input[type=radio]").change( function() {
			$("#filtra").submit();
		});
		
		
		$('#filtra').submit( function() {
			//?action=ajax&rs=dispach&rsargs[]=view_list&rsargs[]=noleggio&rsargs[]=m:tutti/b:50/a:100/
		    var $inputs = $('#filtra :input');
		    var args = '';
		    $inputs.each( function() {
		        if($(this).is(':checked')) { 		        	
					var char = $(this).attr('name').charAt(5); //args[m][]
		        	args += char+':'+$(this).val()+'/';
		        }
	    	});
	    	//var iid = $(this).attr('id');alert(iid);

	    	sajax_do_call( "dispach" , ['view_list', 'noleggio', args], function(x) {
				$('#allItems').html( x.responseText );
			});
			return false;
		});
		
		$('#allItems a').live("click", function(e) {
			//http://www.pianagru.it/new/noleggio/gru/211  ->to->
			//?action=ajax&rs=dispach&rsargs[]=view_one&rsargs[]=noleggio&rsargs[]=211
			var href = $(this).attr('href').split('/');
			var call = ($(this).attr('class')=='gruppi') ? 'view_one_gruppo' : 'view_one';

	    	sajax_do_call( "dispach" , [call, $(this).attr('class'), href[(href.length)-1]], function(x) {
				$('#widg').html( html_entity_decode(x.responseText) );
				$('#widg').css({
					top:    getPageScroll()[1] + (getPageHeight() / 10)
				}).fadeIn('fast');
			});
			return false;
		});
		
				
		$('#widg .ui-btn-close').live("click", function(e) {
			$('#widg').fadeOut('normal', function(){$('#widg').html('');});
		});
		
	});

