$(document).ready(function() {

 	// click on theme link
 	$('a.themeLink').click(function() {
    		url = $(this).attr('href');
			url += "&ajax=true";
   			$.getJSON(url, function(theme) {
				$('#themeDetail').css('display','block');
				$('#themeDetail h2').text(theme.name);
				$('#themeDetail .summary').html(theme.summary == 'null' ? '' : theme.summary);
				$('#themeDetail .date span').text(theme.termsDates);
				if(theme.imageId != null){
					$('#themeDetail img').css('display','block');
					baseImgURL = $('#themeDetail img').attr('src').split('id=')[0] + 'maxImgWidth=339&id=';
					$('#themeDetail img').attr('src', baseImgURL + theme.imageId);
				}
				else{
					$('#themeDetail img').css('display','none');
				}
				
				$('#themeDetail .sponsorLogo').empty();
				if(theme.sponsorLogoId != null) {
					$('#themeDetail .supportTheme').css('display','none');					
					$('#themeDetail .sponsorLogo').html('<img src="' + baseImgURL + theme.sponsorLogoId + '"/>');
					if(theme.sponsorLink != null){
						$('#themeDetail .sponsorLogo img').wrap('<a href="' + theme.sponsorLink + '"/>');
					}
				}
				else {
					$('#themeDetail .supportTheme').css('display','block');
				}
			});
		return false;
   	});

});
