//Javascript Document
function switchMenuImg(menu){
	menu = (menu==1139)?'collections':menu;
	menu = (menu==1140)?'accessories':menu;
	menu = (menu==1141)?'tshirt':menu;
	document.getElementById('news').src='img/menu/news.gif';
	document.getElementById('contacts').src='img/menu/contacts.gif';
	document.getElementById('collections').src='img/menu/collections.gif';
	document.getElementById('accessories').src='img/menu/accessories.gif';
	document.getElementById('media').src='img/menu/media.gif';
	document.getElementById('video').src='img/menu/video.gif';
	document.getElementById('hall').src='img/menu/hall.gif';
	document.getElementById('eshop').src='img/menu/eshop.gif';
	document.getElementById('stores').src='img/menu/stores.gif';
	document.getElementById('tshirt').src='img/menu/tshirt.gif';
	if(menu!='')
		document.getElementById(menu).src='img/menu/'+menu+'_on.gif';
	menusel = menu;
	//document.getElementById('categorychild').value='';
	try{
		/*changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';*/
	}catch(e){}

}
//INDEX
function Index(){
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=index', IndexHTML);
	document.getElementById('manucontainer').style.display='none';
	document.getElementById('categorychild').value='';
	try{
		changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';
		changeOpac(0,'childdivmedia');
		document.getElementById('childdivmedia').style.display='none';
		collsel='';
	}catch(e){}

}

function IndexHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
	//FadeIn('content',300);
}
//CONTACTS
function Contacts(){
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=contacts', ContactsHTML);
	document.getElementById('manucontainer').style.display='';
	switchMenuImg('contacts');
	document.getElementById('categorychild').value='';
	try{
		changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';
		changeOpac(0,'childdivmedia');
		document.getElementById('childdivmedia').style.display='none';
		collsel='';
	}catch(e){}
}
function ContactsHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
	//FadeIn('content',300);

}
//NEWS
function News(page){
	if(!page){
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=news&page='+page, NewsHTML);
	}else{
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=news&page='+page, NewsListHTML);
	}
	document.getElementById('manucontainer').style.display='';
	switchMenuImg('news');
	document.getElementById('categorychild').value='';
	try{
		changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';
		changeOpac(0,'childdivmedia');
		document.getElementById('childdivmedia').style.display='none';
		collsel='';
	}catch(e){}
}
function NewsListHTML(){
	document.getElementById('newslist').innerHTML = this.req.responseText;	
}
function NewsHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
	//FadeIn('content',300);
}
//NEWS INT
function NewsInt(id){
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=newsint&id='+id, NewsIntHTML);
	document.getElementById('manucontainer').style.display='';
	switchMenuImg('news');
	document.getElementById('categorychild').value='';
	try{
		changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';
		changeOpac(0,'childdivmedia');
		document.getElementById('childdivmedia').style.display='none';
		collsel='';
	}catch(e){}
}
function NewsIntHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
	changeOpac(0,'imagenews');
	FadeIn('newsintslide',300);
	setTimeout("FadeIn('imagenews',300)",300);
}
function changeImgNews(imgsrc){
	changeOpac(0,'imagenews');
	document.getElementById('newsimg').src=imgsrc;
	document.getElementById('newsimg').onload=function(){
		FadeIn('imagenews',300);
		}
	//FadeIn('newsintslide',300);
	//setTimeout("FadeIn('imagenews',300)",300);
}
//COLLECTIONS
function Collections(id){
		//document.getElementById('categorychild').value='';
	//collsel = '';
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=collections&id='+id, CollectionsHTML);
	document.getElementById('manucontainer').style.display='';
	switchMenuImg('collections');
	try{
	document.getElementById('collection'+collsel).className='collezione';
	}catch(e){}
	try{
	collsel=id;
	document.getElementById('collection'+id).className='collezionesel';
	}catch(e){}
	if(!id)
		getChild(1139);
}
function CollectionsHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
	//FadeIn('content',300);
}

function CollectionList(categoria,page){
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=collectionlist&categoria='+categoria+'&page='+page, CollectionListHTML);
}
function CollectionListHTML(){
	document.getElementById('collectionlist').innerHTML = this.req.responseText;	
}
function getCollectionLoadingImage(){
	var objCollInt=document.getElementById('collectionint');
	if(objCollInt.style.textAlign=='right'){
		return '<div style="position:absolute; right:25%; top:40%;"><img src="img/loading.gif" align="absmiddle" /></div>';
	}else{
		return '<div style="width:100px; height:100px; position:absolute; top:40%; left:25%; text-align:center;"><img src="img/loading.gif" align="absmiddle" /></div>';
	}
}

//loading
function startLoading(what){
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','loading');
	objOverlay.style.display = 'none';
	var objBody = document.getElementsByTagName("body").item(0);
	objBody.appendChild(objOverlay);
	var vPageSize=getPageSize();
	var objOverlay = document.getElementById("loading");
	objOverlay.style.display = '';
	objOverlay.className = 'loading';
	objOverlay.style.width = '200px';
	objOverlay.style.left = (((vPageSize[0]/2)-100)/2)*2+'px';
	objOverlay.style.top = (((vPageSize[1]/2))/2)*2+'px';
	if(what=='collection'){
	objOverlay.style.left = (((vPageSize[0]/2)-100)/2)*2-200+'px';
	objOverlay.style.top = (((vPageSize[1]/2))/2)*2-100+'px';
	}
	if(what=='accessories'){
		objOverlay.style.left = (((vPageSize[0]/2)-100)/2)*2+200+'px';
		objOverlay.style.top = (((vPageSize[1]/2))/2)*2-100+'px';
	}

	objOverlay.innerHTML = '<img src="img/loading.gif" align="absmiddle"/>';
}
function stopLoading(){
		var objBody = document.getElementsByTagName("body").item(0);
		objBody.removeChild(document.getElementById('loading'));		
}
//-----------
function CollectionInt(id,what){
	//CREO IL DIV LOADING
	var what = (what)?what:'collection'
	startLoading(what);
	//document.getElementById('collimg'+collsel).className='fucsiaborder';
	//alert(collsel);
	document.getElementById('collimg'+id).className='fucsiaborder';
	try{
		if(collsel!=id)
			document.getElementById('collimg'+collsel).className='blackborder';
	}catch(e){}
	//collsel = id;
	//document.getElementById('collectionint').innerHTML=getCollectionLoadingImage();
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=collectionint&id='+id, CollectionIntHTML);
}
function CollectionIntHTML(){
	document.getElementById('collectionint').innerHTML = this.req.responseText;	
}

//ACCESSORIES
function Accessories(id){
	//collsel=''
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=accessories&id='+id, AccessoriesHTML);
	document.getElementById('manucontainer').style.display='';
	switchMenuImg('accessories');
	try{
	document.getElementById('collection'+collsel).className='collezione';
	}catch(e){}
	try{
	collsel=id;
	document.getElementById('collection'+id).className='collezionesel';
	}catch(e){}
	if(!id)
		getChild(1140);
}
function AccessoriesHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
}
//MEDIA
function Media(){
	mediasel = '';
	mediacatopen='';
	getChildMedia();
	//AyaxRequest('ajax_request.php', 'POST', 'filetocall=media', MediaHTML);
	document.getElementById('manucontainer').style.display='';
	switchMenuImg('media');
	document.getElementById('categorychild').value='';
	try{
		changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';
	}catch(e){}
}
function MediaHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
}
function MediaList(categoria,page){
	try{
	document.getElementById('mediacat'+mediacatopen).className='collezione';
	}catch(e){}
	mediacatopen=categoria;
	document.getElementById('mediacat'+categoria).className='collezionesel';
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=medialist&categoria='+categoria+'&page='+page, MediaListHTML);
}
function MediaListHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
}
function getMediaLoadingImage(){
	return '<div style="width:100px; height:100px; position:absolute; top:40%; left:65%; text-align:center;"><img src="img/loading.gif" align="absmiddle" /></div>';
}

function MediaInt(id){
	document.getElementById('mediaimg'+id).className='fucsiaborder';
	try{
		if(mediasel!=id)
			document.getElementById('mediaimg'+mediasel).className='blackborder';
	}catch(e){}
	mediasel = id;
	document.getElementById('mediaint').innerHTML=getMediaLoadingImage();
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=mediaint&id='+id, MediaIntHTML);
}
function MediaIntHTML(){
	document.getElementById('mediaint').innerHTML = this.req.responseText;
	try{FadeIn('mediaslide',300);}catch(e){}
}
function BuildYourBag(){
	document.getElementById('collection1145').className='collezionesel';
	collsel=1145;
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=buildyourbag', BuildYourBagHTML);
}
function BuildYourBagHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
	createGlider(); 
}
//VIDEO

function Video(){
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=video', VideoHTML);
	document.getElementById('manucontainer').style.display='';
	switchMenuImg('video');
	document.getElementById('categorychild').value='';
	try{
		changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';
		changeOpac(0,'childdivmedia');
		document.getElementById('childdivmedia').style.display='none';
		collsel='';
	}catch(e){}
}
function VideoHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
	createGlider(); 
	//FadeIn('content',300);
}

function VideoList(page){
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=videolist&page='+page, VideoListHTML);
}
function VideoListHTML(){
	document.getElementById('videolist').innerHTML = this.req.responseText;	
}

function getVideoLoadingImage(){
	return '<div style="width:100px; height:100px; position:absolute; top:20%; left:45%; text-align:center;"><img src="img/loading.gif" align="absmiddle" /></div>';
}

function VideoInt(id){
	document.getElementById('video'+id).className='fucsiaborder';
	try{
		if(videosel!=id)
			document.getElementById('video'+videosel).className='blackborder';
	}catch(e){}
	videosel = id;
	document.getElementById('videoint').innerHTML=getVideoLoadingImage();
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=videoint&id='+id, VideoIntHTML);
}
function VideoIntHTML(){
		document.getElementById('videoint').innerHTML = this.req.responseText;
}

//HALL
function Hall(){
	hallsel='';
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=halloffame', HallHTML);
	document.getElementById('manucontainer').style.display='';
	switchMenuImg('hall');
	document.getElementById('categorychild').value='';
	try{
		changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';
		changeOpac(0,'childdivmedia');
		document.getElementById('childdivmedia').style.display='none';
		collsel='';

	}catch(e){}
}
function HallHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
	//FadeIn('content',300);

}
function HallList(page){
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=halllist&page='+page, HallListHTML);
}
function HallListHTML(){
	document.getElementById('halllist').innerHTML = this.req.responseText;	
}
function getHallLoadingImage(){
	return '<div style="width:100px; height:100px; position:absolute; top:40%; left:25%; text-align:center;"><img src="img/loading.gif" align="absmiddle" /></div>';
}

function HallInt(id){
	document.getElementById('hallimg'+id).className='fucsiaborder';
	try{
		if(hallsel!=id)
			document.getElementById('hallimg'+hallsel).className='blackborder';
	}catch(e){}
	hallsel = id;
	document.getElementById('hallint').innerHTML=getHallLoadingImage();
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=hallint&id='+id, HallIntHTML);
}
function HallIntHTML(){
	document.getElementById('hallint').innerHTML = this.req.responseText;	
	FadeIn('hallslide',800);
}

//STORES
function Stores(){
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=stores', StoresHTML);
	document.getElementById('manucontainer').style.display='';
	switchMenuImg('stores');
	//FadeIn('content',300);
	document.getElementById('categorychild').value='';
	try{
		changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';
		changeOpac(0,'childdivmedia');
		document.getElementById('childdivmedia').style.display='none';
		collsel='';
	}catch(e){}
}
function StoresHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
}
//TSHIRT
function Tshirt(id){
	collsel=''
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=collections&id='+id, AccessoriesHTML);
	document.getElementById('manucontainer').style.display='';
	switchMenuImg('tshirt');
	try{
	collsel=id;
	document.getElementById('collection'+id).className='collezionesel';
	}catch(e){}
	if(!id)
		getChild(1141);
}
function TshirtHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
	//FadeIn('content',300);

}
//COMMUNITY
function Community(){
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=community', CommunityHTML);
	document.getElementById('manucontainer').style.display='';
	switchMenuImg('');
	document.getElementById('categorychild').value='';
	try{
		changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';
		changeOpac(0,'childdivmedia');
		document.getElementById('childdivmedia').style.display='none';
		collsel='';
	}catch(e){}
}
function CommunityHTML(){
	document.getElementById('content').innerHTML = this.req.responseText;	
	//FadeIn('content',300);

}

function getSelect(what,value,stile){
	if(what=='provincia'){
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=query_comuni&what='+what+'&value='+value+'&class='+stile, SelectProvincia_html);
	}
	if(what=='citta'){
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=query_comuni&what='+what+'&value='+value+'&class='+stile, SelectCitta_html);
	}
	if(what=='cap'){
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=query_comuni&what='+what+'&value='+value+'&class='+stile, SelectCAP_html);
	}
}
function SelectProvincia_html(){
	document.getElementById('provincia_container').innerHTML=this.req.responseText;
	document.getElementById('citta').value='';
	document.getElementById('citta').disabled=true;
	document.getElementById('cap').disabled=true;
	document.getElementById('cap').value='';
}
function SelectCitta_html(){
	//alert(this.req.responseText);
	document.getElementById('citta_container').innerHTML=this.req.responseText;
}
function SelectCAP_html(){
	document.getElementById('cap').disabled=false;
	document.getElementById('cap').value=this.req.responseText;
}
function StoresList(type,page){	
		var stato = document.getElementById('stato').value;
		if(stato==''){
			alert("Select at least one country");	
		}else{
			document.getElementById('storeslist').innerHTML=getMediaLoadingImage();
			AyaxRequest("ajax_request.php", "POST", "filetocall=storeslist&stato="+stato+"&page=" + page, StoresListHTML);
		}
	}
	function StoresListHTML(){
		document.getElementById('storeslist').innerHTML=this.req.responseText;
	}
	// -------------------------
function getChildMedia(){
	switchMenuImg('media');
	document.getElementById('childdivmedia').style.display='inline';
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=childlistmedia', getChildMediaHTML);
}
function getChildMediaHTML(){
	document.getElementById('childdivmedia').innerHTML=this.req.responseText;
	FadeIn('childdivmedia');
}
//FUNZIONE CHE VISUALIZZA LE SOTTOCATEGORIE
function getChild(id){
	switchMenuImg(id);
	/*var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','childdiv');
	objOverlay.style.display = '';
	var objBody = document.getElementsByTagName("body").item(0);
	objBody.appendChild(objOverlay);
	objOverlay.className='childdiv';*/
	document.getElementById('categorychild').value=id;
	document.getElementById('childdiv'+id).style.display='inline';
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=childlist&id='+id, getChildHTML);
	/*var left = '';
	left=(id==1139)?'54':left;
	left=(id==1140)?'61':left;
	left=(id==1141)?'95':left;
	document.getElementById('childdiv').style.left=left+'%';*/
}
function getChildWithoutBg(id){
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=childlist&id='+id, getChildHTML);
}
function getChildHTML(){
	collsel='';
	changeOpac(0,'childdivmedia');
	document.getElementById('childdivmedia').style.display='none';
	var div = document.getElementById('categorychild').value;
	if(div!='1140' && div!='1141'){
	try{
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
	}catch(e){}
	try{
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';
	}catch(e){}
	}
	if(div!='1139' && div!='1140'){
	try{
		changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
	}catch(e){}
	try{
		changeOpac(0,'childdiv1140');
		document.getElementById('childdiv1140').style.display='none';
	}catch(e){}
	}
	if(div!='1139' && div!='1141'){
	try{
		changeOpac(0,'childdiv1139');
		document.getElementById('childdiv1139').style.display='none';
	}catch(e){}
	try{
		changeOpac(0,'childdiv1141');
		document.getElementById('childdiv1141').style.display='none';
	}catch(e){}
	}
	document.getElementById('childdiv'+div).innerHTML=this.req.responseText;
	FadeIn('childdiv'+div,500);
}
function loadImageColl(){
	changeOpac(0,'imagestill_life');
	FadeIn('image',500);
	setTimeout("FadeIn('imagestill_life',500)",500);
	changeOpac(0,'imageclose_up');
	FadeIn('image',500);
	setTimeout("FadeIn('imageclose_up',500)",800);
	setTimeout("stopLoading()",900);
}