Shadowbox.init();

$(document).ready(function(){

	$(document).pngFix();

	$('div.country-seller').prev('a').bind("click", function (event) {
		event.preventDefault();
		lightBoxContent = $(this).next('div.country-seller').html();
		openMessage();
	});

	adjustFooter();
	$(window).bind("resize", adjustFooter);

	var loadFlash = $.flash.create({
		swf: '../swf/animazione_en.swf',
		height: 350,
		width: 656,
		wmode: 'transparent'
	});
	$('#flash').html(loadFlash);

	$('#select-brand>a').bind("click", function (event) {
		event.preventDefault();
		$(this).next('div').fadeIn('slow');
	});
		
	$('span.close').bind("click", function (event) {
		event.preventDefault();
		$(this).parent('div').fadeOut('slow');
	});
	
	$('a.blank').bind("click", function (event) {
		event.preventDefault();
	});
	
	$('#lang-menu a.active').bind("click", function (event) {
		event.preventDefault();
	});
	
	caricaNewsWide('../xml/news-en.wide.xml');
	$('#wide-mag').html(caricaNewsWideTxt);
	caricaNews('../xml/news-en.xml');
	$('#news').html(caricaNewsTxt);

});

function caricaNews(quale){
	var xmlDoc;
	if (window.XMLHttpRequest)
	  {
	  xmlDoc=new window.XMLHttpRequest();
	  xmlDoc.open("GET",quale,false);
	  xmlDoc.send("");
	  xmlDoc=xmlDoc.responseXML;
	  }
	// IE 5 and IE 6
	else if (ActiveXObject("Microsoft.XMLDOM"))
	  {
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async=false;
	  xmlDoc.load(quale);
	  }
	
	var x=xmlDoc.getElementsByTagName("news");
	caricaNewsTxt='';
	for (i=0;i<x.length;i++)
		{
		caricaNewsTxt+=
		("<h4><a href='")
		+(x[i].getElementsByTagName("collegamento")[0].childNodes[0].nodeValue)
		+("' target='_blank'>")
		+(x[i].getElementsByTagName("titolo")[0].childNodes[0].nodeValue)
		+("</a></h4><p>")
		+(x[i].getElementsByTagName("testo")[0].childNodes[0].nodeValue)
		+("</p>");
		}
		
}

function caricaNewsWide(quale){
	var xmlDoc;
	if (window.XMLHttpRequest)
	  {
	  xmlDoc=new window.XMLHttpRequest();
	  xmlDoc.open("GET",quale,false);
	  xmlDoc.send("");
	  xmlDoc=xmlDoc.responseXML;
	  }
	// IE 5 and IE 6
	else if (ActiveXObject("Microsoft.XMLDOM"))
	  {
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async=false;
	  xmlDoc.load(quale);
	  }
	
	var x=xmlDoc.getElementsByTagName("news");
	for (i=0;i<x.length;i++)
	  { 
	  caricaNewsWideTxt=("<a title='Wide Magazine' href='")
	  +(x[i].getElementsByTagName("collegamento")[0].childNodes[0].nodeValue)
	  +("' target='_blank'>")
	  +("<img width='102' height='95' alt='Wide Piaggio Magazine' src='")
	  +(x[i].getElementsByTagName("immagine")[0].childNodes[0].nodeValue)
	  +("' /></a>")
	  +("<p>")
	  +(x[i].getElementsByTagName("titolo")[0].childNodes[0].nodeValue)
	  +("<br />")
	  +("<a href='")
	  +(x[i].getElementsByTagName("collegamento")[0].childNodes[0].nodeValue)
	  +("'>Read online the latest issue</a> or <a href='")
	  +(x[i].getElementsByTagName("collegamentoArchivio")[0].childNodes[0].nodeValue)
	  +("'>go to the archives</a>.")
	  +("</p>")
	  +("<p id='clicca-qui'><a href='")
	  +(x[i].getElementsByTagName("collegamento")[0].childNodes[0].nodeValue)
	  +("' title='Wide Magazine'>Click here</a></p>")
	  +("<p id='bt-sondaggio-en'><a href='http://www.vyrtucom.com/piaggio_ws/index.asp?lang=2' title='Wide Magazine Survey'>Wide Magazine Survey</a></p>");
	  }
	  
}

function adjustFooter() {
	wh = $(window).height();
	if(wh>854){
		$('#footer').css('position','fixed');
		$('#footer').css('bottom','0');
	}else{
		$('#footer').css('position','relative');
		$('#footer').css('bottom','0');
	}
}

function openMessage() {
    Shadowbox.open({
        player: "html",
        content: lightBoxContent,
        height: 214,
        width: 342
    });
}
