
var newsContent=new Object();
var appearancesInfo=new Object();
var appearancesDates=new Object();
var pictureType={stage:'Stage Pictures', portraits:'Portraits', inprint:' In Print', personal:'Personal Pictures', artwork:'Artwork'};

function setDynamicColor(color){

}
function displayInfo(data){
// =====================
// ! display latest news   
// =====================

	for(i=0;i<data.news.length;i++){
		$('#LatestNewsContent').append('<div id="news_'+data.news[i].id+'" class="homeNewsContainer"><div class="homeNewsDate">'+humanDate(data.news[i].newsDate)+'</div><div class="homeNewsTitle">'+data.news[i].newsHeader+'</div><div class="homeNewsRead glowingButton" title="'+data.news[i].newsHeader+'" date="'+data.news[i].newsDate+'">more</div></div>');
		newsContent['news_'+data.news[i].id]={title:data.news[i].newsHeader, message:data.news[i].newsContent};
	}
	
/* vechi conflict la message
		for(i=0;i<data.news.length;i++){
		$('#LatestNewsContent').append('<div id="news_'+data.news[i].id+'" class="homeNewsContainer"><div class="homeNewsDate">'+humanDate(data.news[i].newsDate)+'</div><div class="homeNewsTitle">'+data.news[i].newsHeader+'</div><div class="homeNewsRead glowingButton" title="'+data.news[i].newsHeader+'" date="'+data.news[i].newsDate+'" message="'+data.news[i].newsContent+'">more</div></div>');
	}
*/
	
// =============================
// ! display latest appearances   
// =============================

	for(j=0;j<data.appearances.length;j++){
		$('#appearancesContent').append('<div id="appearance_'+data.appearances[j].info.id+'" class="homeAppearancesContainer"><div class="homeAppearancesDate">'+humanDate(data.appearances[j].info.date)+'</div><div class="homeAppearancesTitle">'+data.appearances[j].info.name+'</div><br><div class="homeAppearancesLocation">'+data.appearances[j].info.venue+' - '+data.appearances[j].info.location+'</div><div class="homeAppearancesRead glowingButton" title="'+data.appearances[j].info.name+'"link="'+data.appearances[j].info.detailsLink+'">details</div></div>');
		appearancesInfo['appearance_'+data.appearances[j].info.id]={title:data.appearances[j].info.name, dates:data.appearances[j].dates,venue:data.appearances[j].info.venue,venueLink:data.appearances[j].info.venueLink,location:data.appearances[j].info.location,country:data.appearances[j].info.country,programme:data.appearances[j].info.programme,programmeLink:data.appearances[j].info.programmeLink,orchestra:data.appearances[j].info.orchestra,orchestraLink:data.appearances[j].info.orchestraLink, detailsLink:data.appearances[j].info.detailsLink,bookingLink:data.appearances[j].info.bookingLink};
		appearancesDates['appearance_'+data.appearances[j].info.id]=data.appearances[j].dates;
	}

// ======================
// ! display latest album   
// ======================
/*
	
	$('#NewestAlbumContent').append('<div class="homeAlbumPicture"><img src="albums/'+data.album.id+'.jpg"/></div><div class="homeAlbumAndGalleryInfo"><p class="homeAlbumName">'+data.album.name+'</p><p class="homeAlbumArtists">'+data.album.artists+'</p><p class="homeAlbumDetails glowingButton">details</p></div>')
*/

// ==============================
// ! display latest gallery items   
// ==============================
$('#LatestGalleryContent').append('<div class="homeGalleryItem" type="stage"><img width="110px" height="80" src="gallery/'+data.gallery[0]+'_thumb.jpg" class="homeGalleryPicture"/><p class="homeGalleryType">Latest in<br><span class="justBold">Stage</span></p></div>');
$('#LatestGalleryContent').append('<div class="homeGalleryItem"type="personal"><img width="110px" height="80" src="gallery/'+data.gallery[1]+'_thumb.jpg" class="homeGalleryPicture"/><p class="homeGalleryType">Latest in<br><span class="justBold">Personal</span></p></div>');
$('#LatestGalleryContent').append('<div class="homeGalleryItem" type="portraits"><img width="110px" height="80" src="gallery/'+data.gallery[2]+'_thumb.jpg" class="homeGalleryPicture"/><p class="homeGalleryType">Latest in<br><span class="justBold">Portraits</span></p></div>');
//video icon
//alert(seeObject(data.gallery));
var movie=(data.gallery[3].split('/')[4]).split('?')[0];
var videoIcon='http://i4.ytimg.com/vi/'+movie+'/default.jpg';
$('#LatestGalleryContent').append('<div class="homeGalleryItem" type="video"><img width="110px" height="80" src="'+videoIcon+'" class="homeGalleryPicture"/><p class="homeGalleryType">Latest in<br><span class="justBold">Video</span></p></div>');

// ================================================================
// ! asign mouse events functions for dinamically generated classes   
// ================================================================
	$('.homeGalleryItem').hover(
		function(){
			$(this).css('cursor','pointer');
			$('.homeGalleryType', this).addClass('justDynamicColor');
		},
		function(){
			$('.homeGalleryType', this).removeClass('justDynamicColor');
			$(this).css('cursor','default');			
		}
	)
	
	$('.homeGalleryItem').click(function(){
		if(Modernizr.localstorage){
			localStorage['openGallerySection']=$(this).attr('type');
		}
		window.location = 'gallery.html';
	})

	$('.glowingButton').hover(
		function(){
			buttonBehavior(this,'buttonMouseOver','hover');
			glowingBackground(this,'#33323a');
		},
		function(){
			buttonBehavior(this,'buttonMouseOver','leave');
			glowingBackground(this,'#9298aa');
		}
	)
	
	$('.homeNewsRead').click(function(){		
		var messageID=$(this).parent().attr('id');
		var content={date:$('#'+messageID+'>.homeNewsDate').html(),title:newsContent[messageID].title,picture:newsContent[messageID].picture, message:newsContent[messageID].message};
		createPopUpWindow('news',content);
	})
	
	$('.homeAppearancesRead').click(function(){
		var messageID=$(this).parent().attr('id');
		var content={date:appearancesDates[messageID],title:appearancesInfo[messageID].title,info:appearancesInfo[messageID]};
		createPopUpWindow('appearances',content);
	})
	
	//correct footer position
	$('#footer').css('top','40px');

}
$(document).ready(function(){
	$.post('scripts/getIndexInfo.php',displayInfo,'json');
	
	$('.seeAll').hover(function(){
		buttonBehavior(this,'buttonMouseOver','hover')
	})
	
	$('.seeAll').mouseleave(function(){
		buttonBehavior(this,'buttonMouseOver','leave')
	})
	
	$('.seeAll').click(function(){
		window.location.href=this.id+".html"
	})
	

	
})

	
