// Ajax
var is_working = false;
var response;
var home_content = '';
var lang = 'en';
var bar = new Array();
bar['it'] = "<ul><li><a href=\"javascript:Show('profile')\">Profilo</a></li><li><a href=\"javascript:Show('collections')\">Collezioni</a></li><li><a href=\"javascript:Show('contact_us')\">Contatti</a></li><li><a href=\"javascript:Show('press')\">Stampa</a></li></ul>";
bar['en'] = "<ul><li><a href=\"javascript:Show('profile')\">Profile</a></li><li><a href=\"javascript:Show('collections')\">Collections</a></li><li><a href=\"javascript:Show('contact_us')\">Contacts</a></li><li><a href=\"javascript:Show('press')\">Press</a></li></ul>";
document.location.href = "index.php#home";
var PressText = new Array();
PressText['it'] = new Array(2006 > "");
PressText['en'] = new Array();

function GetHomeContent()
{
	home_content = document.getElementById("content").innerHTML;
}

function SetLang(use_lang)
{
	lang = use_lang;
	document.getElementById("bar").innerHTML = bar[use_lang];
	
	var expire = new Date();
	expire.setTime(expire.getTime() + (180*24*60*60*1000) );
	document.cookie = "karisma_lang="+use_lang+"; expires="+expire.toGMTString();
}

function getHTTPObject()
{
	var xmlhttp;
	
	/*@cc_on
	@if (@_jscript_version >= 5)
		try
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (E)
			{
				xmlhttp = false;
			}
		}
	@else
		xmlhttp = false;
	@end @*/
	
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		} 
		catch (e)
		{
			xmlhttp = false;
		}
	}
	
	return xmlhttp;
}

var http = getHTTPObject();

function handleHttpResponse()
{
	if (http.readyState == 4)
	{
		is_working = false;
		
		if (http.responseText.indexOf('invalid') == -1)
		{
			response = http.responseText;
			
			is_working = false;
		}
	}
}

function Show(page)
{
	if(page != "home")
	{
		if (!is_working && http)
		{
			document.getElementById("content").innerHTML = '<div style="text-align: center; margin-bottom: 10px;">Loading...</div>';
			
			http.open("GET", "ajax.php?page="+page+"&lang="+lang, true); // http.open("GET", "http://localhost/karisma/ajax.php?page="+page, true);
			http.onreadystatechange = function()
			{
				handleHttpResponse();
				
				if(response)
				{
					document.getElementById("content").innerHTML = response;
					response = "";
				}
				
				if(page == "press")
				{
					GetPressText(0);
				}
			}
			
			is_working = true;
			
			http.send(null);
		}
	}
	else
	{
		document.getElementById("content").innerHTML = home_content;
		SetLang(lang);
	}
}


// Collections
var i;
var images = new Array();
var description = new Array();
var thmbnails;

images['classic'] = new Array('Classic', Array('classic1','classic2','classic3','classic4','classic5'), "Collane e bracciali in oro massiccio lavorate completamente a mano.", "Necklaces and bracelets in solid gold, entirely handmade.");
images['jazz'] = new Array('Jazz', Array('jazz1','jazz2','jazz3','jazz4','jazz5'), "Disegno armonico e ritmo: queste le caratteristiche della collezione. Espressamente dedicata all&rsquo;uomo, &egrave; una linea che ne interpreta lo stile proponendo accostamenti di forme e colori decisi, propri di chi sa esprimersi con ironia e un po&rsquo; di nonchalance.", "Harmonic and rhythmical drawing: these are the characteristics of the collection. Explicitly dedicated to men, it is a line which interprets the style by proposing combinations of forms and marked colours. Suitable for those who can express themselves with a bit of irony and nonchalance.");
images['fancy'] = new Array('Fancy', Array('fancy1','fancy2','fancy3','fancy4','fancy5'), "Collane e bracciali, anch’essi creati a mano, dai disegni innovativi e dal peso contenuto.", "Handmade necklaces and bracelets, with innovative light weight designs.");
images['xlight'] = new Array('X-Light', Array('xlight1','xlight2','xlight3','xlight4','xlight5'), "Catene lavorate a mano, estremamente leggere, disponibili nella combinazione oro giallo e bianco, con finitura satinata o lucida. Una linea raffinata e sottile, pronta per essere portata con disinvoltura dalla persona che certamente ama la cura dei dettagli, ma desidera la discrezione.", "Handmade chains, extremely light, available in the combination of yellow and white gold with satined or polished finishing. A refined and thin line, ready to be worn with nonchalance from a person who loves taking care of details, but wishes discretion.");
images['xxlight'] = new Array('XX-Light', Array('xxlight1','xxlight2','xxlight3','xxlight4','xxlight5'), "Catene lavorate a mano, delicate e sottili, caratterizzate da un peso leggerissimo nella combinazione oro giallo e bianco, con finitura satinata o lucida. Monili adattissimi da indossare come collane, abbinate a ciondoli e pendenti, espressamente dedicate a chi ama il movimento, la vita attiva, con il giusto tocco di ironia.", "Handmade chains, delicate and thin, characterized by a very light weight available in the combination of yellow and white gold with satined or polished finishing; a right touch of irony, suitable for someone who loves movement and an active life.");
images['flamenco'] = new Array('Flamenco', Array('flamenco1','flamenco2','flamenco3','flamenco4'), "Collane, bracciali ed orecchini fashion per la donna moderna.", "Necklaces, bracelets and fashionable earrings for modern women.");
images['soul'] = new Array('Soul', Array('soul1'), "Pendenti di varie forme, colori e grandezze adatte ad impreziosire le nostre collane.", "Pendants of various forms, colours and width, ideal to enhance our Necklaces.");
images['boy_girl'] = new Array('Boy & Girl', Array('boy_girl1','boy_girl2','boy_girl3'), "La linea simpatica e fantasiosa dedicata ai bambini: bracciali e catene, con targa ed elementi pendenti assortiti, smaltati in vari allegri colori.", "A likeable and imaginative line dedicated to children: bracelets and chains with a plaque and assorted elements, enamelled in various bright colours.");


function ShowImage(name)
{
	document.getElementById("image").innerHTML = '<img src="collections/'+name+'" alt="'+name+'" style="width: 100%; height: 100%;" />';
}

function ShowThumbnails(type)
{
	var key = (lang == 'it') ? 2 : 3;
	document.getElementById("description").innerHTML = '<div style="margin-bottom: 10px;"><h3>'+images[type][0]+'</h3>'+ images[type][key]+'</div>';
	document.getElementById("image").innerHTML = "&nbsp;";
	
	document.getElementById("thumbnails").innerHTML = '';
	for(i = 0; i < images[type][1].length; i++)
	{
		document.getElementById("thumbnails").innerHTML += '<a href="javascript:ShowImage(\''+images[type][1][i]+'.jpg\')"><img src="collections/thumb/'+images[type][1][i]+'.jpg" alt="'+images[type][1][i]+'" class="collections_img" /></a> ';
	}
}


// Press
var l_show_image = new Array();
l_show_image['it'] = "Mostra immagine";
l_show_image['en'] = "Show image";

function GetPressText(year)
{
	year = parseInt(year);
	
	if(year == 0)
	{
		year = 2006;
	}
	
	if(year == 2000)
	{
		ShowPressImage(2000);
		return;
	}
	
	if(!PressText[lang][year])
	{
		if (!is_working && http)
		{
			document.getElementById("press_content").innerHTML = 'Loading...';
			
			http.open("GET", "ajax.php?press="+year+"&lang="+lang, true); // http.open("GET", "http://localhost/karisma/ajax.php?page="+page, true);
			http.onreadystatechange = function()
			{
				handleHttpResponse();
				
				if(response)
				{
					PressText[lang][year] = response;
					document.getElementById("press_content").innerHTML = '<h3 style="margin-bottom: 6px; margin-left:0; text-align: center;">Advertising '+year+'</h3>'
						+ "<div style=\"margin-bottom: 3px;\"><a href=\"javascript:ShowPressImage("+year+")\">"+l_show_image[lang]+"</a></div>"
						+ "<div style=\"text-align: justify;\">"+PressText[lang][year]+"</div>";
					response = "";
				}
			}
			
			is_working = true;
			
			http.send(null);
		}
	}
	else
	{
		document.getElementById("press_content").innerHTML = '<h3 style="margin-bottom: 6px; margin-left:0; text-align: center;">Advertising '+year+'</h3>'
			+ "<div style=\"margin-bottom: 3px;\"><a href=\"javascript:ShowPressImage("+year+")\">"+l_show_image[lang]+"</a></div>"
			+ "<div style=\"text-align: justify;\">"+PressText[lang][year]+"</div>";
	}
}

function ShowPressImage(year)
{
	year = parseInt(year);
	
	document.getElementById("press_content").innerHTML = '<h3 style="margin-bottom: 6px; margin-left:0; text-align: center;">Advertising '+year+'</h3>'
			+ '<div style="text-align: center"><a href="javascript:GetPressText('+year+')"><img src="advertising/'+year+'.jpg"" alt="Advertising '+year+'" /></a></div>';
}