Event.observe(window, "load", showBandiere);

function showBandiere() {
	var google_t = /translate.google.com/;
	var google_res= window.location.href.search(google_t);
	if(google_res != -1)
	{
		$('bandiere').hide();
	}
	else
	{
		$('bandiere').show();
	}
	
}

function IntiView () {
	var className='item';
	if (GetCookie('pmlv')=='D') {
		ChangeView();
		className='row';
	}
	$$('#main p.'+className).each(function (s) {
		s.show();
	});
	$$('a.lang').each(function(obj) {		
		obj.observe('click', function(event) {
			event.stop();
			var element = Event.element(event).up('a');
			window.top.location.href = element.readAttribute('rel');
			window.top.location = element.readAttribute('rel');
		});		
	});
}

function ChangeView() {
	var lv='';
	if ($('chgVW').title=='dettagli') {
		$$('#main p.item').each(function (s) {
			s.className='row over';
			var is=$(s).down('.image img').getDimensions();
			$(s).down('.image img').setStyle({
				'width':'48px',
				'height': Math.ceil((48*is.height)/is.width)+'px'
			});
		});
		$('chgVW').title='icone';
		$$('#chgVW img')[0].hide();
		$$('#chgVW img')[1].show();
		lv='D';
	} else {
		$$('#main p.row').each(function (s) {
			s.className='item over';
			var img=$(s).down('.image img');			
			img.setStyle({
				'width': img.readAttribute('width')+'px',
				'height': img.readAttribute('height')+'px'
			});
		});
		$('chgVW').title='dettagli';
		$$('#chgVW img')[1].hide();
		$$('#chgVW img')[0].show();
		lv='I';
	}
	
	//setCookie
	var exp = new Date(); 
	exp.setTime(exp.getTime() + (1000*60*60*24*365)); 
	setCookie("pmlv", lv, exp, "/", false, false); 
}

function SortItem () {
var google_t = /translate.google.com/;
var lang = /en/;
var google_res= window.location.href.search(google_t);
if(google_res != -1)
{
 	var str = window.location.href.split("&");
 	var lang = str[3].substring(3);
	window.top.location.href='http://translate.google.com/translate?u=http%3A%2F%2Fwww.petitemaisonaosta.it?sb='+$('vSort').value+'&sl=it&tl='+lang+'&hl=&ie=UTF-8';
	}
else
{
	window.location.href=window.location.href.split('?')[0]+($('vSort').value!=''?'?sb='+$('vSort').value:'');
}
}

function setCookie(name, value, expires, path, domain, secure) { 
	 var curCookie = name + "=" + escape(value) + 
		((expires) ? "; expires=" + expires.toGMTString() : "") + 
		((path) ? "; path=" + path : "") + 
		((domain) ? "; domain=" + domain : "") + 
		((secure) ? "; secure" : ""); 
	 document.cookie = curCookie;
}

function GetCookie(name){ 
   var biscotti = document.cookie.split("; ");
   for (i=0; i < biscotti.length; i++) {
      briciola = biscotti[i].split("=");
      if (briciola[0] == name) {
        valore = briciola[1];
        return valore;
      }
   }
}
