var active = null;
var browser=navigator.appName;
var currentTime;

//var root = "http://www.johnlegend.com/";

var merchUrl = null;
var forumUrl = null;
var objectPlaying = null;
var oXMLHttp = null;
var oXMLHttpClick = null;
var oXMLHttpRelease = null;
var oXMLHttpTour = null;
var oXMLHttpFlashNav = null;

var under13 = false;

var horzBackgrounds = new Array();

var horzBackgroundCount = 16;

var monthArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

var justLoaded = true;

var agent = navigator.userAgent.toLowerCase(); 
var isMac = (agent.indexOf("mac") != -1) ? true : false;
var isMSIE = (navigator.appVersion.indexOf("MSIE")!=-1) ? true : false;

var browserName = "";

var historyXML = new Object;

var ua = navigator.userAgent.toLowerCase();


if ( ua.indexOf( "opera" ) != -1 )
{
	browserName = "opera";
} else if ( ua.indexOf( "android" ) != -1 )
{
	browserName = "android";
} else if ( ua.indexOf( "msie" ) != -1 )
{
	browserName = "msie";
} else if ( ua.indexOf( "ipad" ) != -1 )
{
	browserName = "ipad";
} else if ( ua.indexOf( "safari" ) != -1 )
{
	browserName = "safari";
} else if ( ua.indexOf( "mozilla" ) != -1 )
{
	if ( ua.indexOf( "firefox" ) != -1 )
	{
		browserName = "firefox";
	} else {
		browserName = "mozilla";
	}
}

var paneDifference = 0;

function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    
    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}

var bgArray = new Array("http://assets.sonymusic.com/columbia/johnlegend/backgrounds/john-legend-38.jpg", 
			"http://assets.sonymusic.com/columbia/johnlegend/backgrounds/john-legend-48.jpg", 
			"http://assets.sonymusic.com/columbia/johnlegend/backgrounds/john-legend-60.jpg", 
			"http://assets.sonymusic.com/columbia/johnlegend/backgrounds/john-legend-139.jpg", 
			"http://assets.sonymusic.com/columbia/johnlegend/backgrounds/john-legend-207.jpg", 
			"http://assets.sonymusic.com/columbia/johnlegend/backgrounds/john-legend-245.jpg", 
			"http://assets.sonymusic.com/columbia/johnlegend/backgrounds/bg_wakeup.jpg",
			"http://www.johnlegend.com/images/bg_black.jpg");

//var currentBGIndex = Math.floor(Math.random()*bgArray.length);

var currentBGIndex = null;

function loadNav()
{

	var localization = siteObj[terr].localization;
	
	var nav = siteObj[terr].nav;
	
	var html = '<div id="logo"><a href="http://www.johnlegend.com/home" onclick="loadSection(\''+terr+'\', \'home\'); return false;"><img src="../../images/logo_b.png" border="0" /></a></div>';
	for(var item in nav)
	{
		var navItem = nav[item];
		
		html += '<div id="navItem">';
		switch(navItem.TARGET)
		{
			case "_self":
				html += '<a href="http://www.johnlegend.com/'+ navItem.URI +'" onclick="loadSection(\''+ terr +'\', \''+ navItem.URI +'\'); return false;">';
				break;
			
			case "_blank":
				html += '<a href="'+ navItem.URI+'" target="_blank">';
				break;
		}
		
		html += navItem.NAME+'</a></div>';
	}
	
	html +='<div style="float:right; margin: 15px 10px 0px 0px"><a href="http://www.listn.to/johnlegend" target="_blank"><img src="../../images/soc_facebook.jpg"  width="24" height="24" border="0" style="margin: 0px 5px 0px 0px" /></a><a href="http://www.twitter.com/johnlegend" target="_blank"><img src="../../images/soc_twitter.jpg" border="0"  width="24" height="24" style="margin: 0px 5px 0px 0px" /></a><a rel="author" href="https://plus.google.com/118343229422358233590"><img src="https://www.google.com/images/icons/ui/gprofile_button-32.png" width="24" height="24" margin: 0px 5px 0px 0px"></a></div>';

	document.getElementById('nav').innerHTML = html;

	//document.getElementById('fbNewsletterCont').innerHTML = '<form id="coppaCheck" name="coppaCheck"><input type="hidden" name="U13" id="U13" value=""/></form>';
	
	document.getElementById('contactFooter').innerHTML = '<div id="contactFooterElement"><a href="javascript:void(0)" onclick="loadContactForm();">'+ localization.Contact +'</a></div><div id="contactFooterIcon"><a href="javascript:void(0)" onclick="loadContactForm();"><img src="../../images/contact_i.png" border="0" /></a></div>';

	document.getElementById('flagsDiv').innerHTML = loadFlags();

	checkForCookie();
	
	loadBuyBlock();
}


function loadFlags()
{

	var localization = siteObj[terr].localization;
	
	var flags = siteObj.flags;
	
	var html = '';
	
	var currflag = flags[terr];
		
	html += '<div id="moreFlagsDiv" class="initiallyHidden">';
	
	for(property in flags)
	{
		
		if(property != terr)
		{
			var flag = flags[property];
		
			html += '<div id="flagDiv"><a href="http://www.johnlegend.com/'+ flag.terr +'/home"><img src="'+ flag.img +'" border="0" alt="'+ flag.name +'" title="'+ flag.name +'" /></a></div>';
		}
	}
	
	html += '</div>';
	html += '<div id="currentFlagDiv"><div id="moreFlagsButton" style="float:right"><a href="javascript:void(0);" onclick="jQuery(\'#moreFlagsButton\').fadeOut(200, function () { document.getElementById(\'currentFlagDiv\').style.width = \'15px\'; jQuery(\'#moreFlagsDiv\').show(350);});">'+ localization.More +'</a></div><img src="'+ currflag.img +'" border="0" alt="'+ currflag.name +'" title="'+ currflag.name +'" style="margin: 0px 0px 0px 0px" /></div>';

	return html;
	
}

function showFlags()
{
	
	jQuery("#moreFlagsDiv").show(500);

}

function loadSection()
{

	t = arguments[0];	
	s = arguments[1];	
	p1 = arguments[2];	
	p2 = arguments[3];	
	p3 = arguments[4];
	p4 = arguments[5];
	
	if(t != terr)
	{
		terr = t;
		var info = siteObj[terr].info;
		resetTerritory(info.t_code, info.t_id, info.t_language);
		loadNav();
	}
	
	
	if(s != undefined && s != "" && s != section) section = s;
	
	var trackUrl = root+terr+'/'+section;
	
	trackPage(trackUrl, section, section)
	
	switch(section)
	{
		case "home":
			loadHome(p1);
			break;
			
		case "news":
			loadNews(p1, p2);
			break;
			
		case "video":
			loadVideos(p1, p2);
			break;
			
		case "music":
			loadMusic(p1);
			break;
		
		case "tour":
			loadTour(p1, p2)
			break;
		
		case "give":
			loadGive()
			break;
			
		case "store":
			loadStore()
			break;
			
		case "community":
			loadCommunity()
			break;

		case "extras":
			loadExtras()
			break
			
		case "photos":
			loadPhotos()
			break
			
		case "bgtest":
			loadBGTest()
			break
	}
	
}

var currentHomeDiv = "";

function loadHome(p)
{
	
	if(p == "" || p == undefined) p = "news";
	
	//if(p == "" || p == undefined) p = "";
	
	currentHomeDiv = p +'Div';

	var html = "";
	
	var content = getElement('content');
	
	var localization = siteObj[terr].localization;
	
	switch(terr)
	{
		case "us":
		case "ca":
		
		fadeBG(7);
		
		var news = siteObj[terr].news;
		
		var tourdates = siteObj[terr].tour;
		
		var home = siteObj[terr].home;
		
		content.innerHTML = "";
		
		var block1 = "";
		
		var block2 = "";
		
		var block3 = "";
		
		var block4 = "";
		
		var feat1 = "";
		
		var feat2 = "";
		
		var featuresHtml = ""; 
		
		for(var x in home.articles)
		{
			var homeBlock = home.articles[x]
			
			switch(homeBlock.title)
			{
				case "Bottom Block 1":

					block1 = '<div id="homeBlock1">' + homeBlock.body +'</div>';
					break;
					
				case "Bottom Block 2":

					block2 = '<div id="homeBlock1">' + homeBlock.body +'</div>';
					break;
					
				case "Bottom Block 3":
				
					block3 = '<div id="homeBlock1">' + homeBlock.body +'</div>';
					break;
					
				case "Bottom Block 4":
				
					block4 = '<div id="homeBlock2">' + homeBlock.body +'</div>';
					break;
					
				case "Primary Feature":
				
					feat1 = '<div id="homeFeat1">' + homeBlock.body +'</div>';
					break;
					
				case "Secondary Feature":
				
					feat2 = '<div id="homeFeat2">' + homeBlock.body +'</div><div id="clearFix"></div>';
					break;
			}
			
		}
		
		var propCount = 0;

		var newsHtml = '<div id="homeNewsBlock">';
		
		for(property in news.articles)
		{
			propCount++;
			newsHtml += '<div id="homeDivContent" style="padding: 0px 0px 10px 0px">';
			newsHtml += '<div id="homeDate">' + news.articles[property].date +'</div>';
			newsHtml += '<div id="homeHeadline"><a href="news/'+ news.articles[property].urlDate+'/'+ news.articles[property].query +'" onclick="loadSection(\''+ terr +'\', \'news\', \''+ news.articles[property].urlDate +'\', \''+ news.articles[property].query+'\'); return false">' + news.articles[property].title +'</a></div>';
			newsHtml += '<div id="homeBody">'+ news.articles[property].abstract +'</div>';
			
			newsHtml += '</div>'
			if(propCount > 2) break;

		}		
		
		newsHtml += '</div>';
		
		var tourHtml = '<div id="homeTourBlock">';
		
		var tourdates = siteObj[terr].tour;
		
		var dates = tourdates.articles.all;
		
		var pages = tourdates.pagination;

		if(pages.length > 0) {

			tourHtml += '<div id="tourHomeRow"><div id="tourHomeDate">DATE</div><div id="tourHomeLocation">CITY/STATE</div><div id="tourHomeTix">TICKETS</div><div id="tourHomeRSVP">RSVP</div></div>';
			tourHtml += '<div id="tourHomeRow" style="margin-top: -5px"><div style="background-color: #ffffff; height: 1px; width:100%"></div></div>';
			var c = 0;
			
			var tourCount = 0;
			
			for(property in dates)
			{
				
				tourCount++;
				
				x = property;

				tourHtml += '<div id="tourHomeRow">';
				tourHtml += '<div id="tourHomeDate">' + dates[x].date +'</div>';

				if(dates[x].location != "")
				{
					tourHtml += '<div id="tourHomeLocation">' + dates[x].location +'</div>';
				} else {
					tourHtml += '<div id="tourHomeLocation">&nbsp;</div>';
				}

				tourHtml += '<div id="tourHomeTix">';
				if(dates[x].links.Tickets){
					tourHtml += '<a href="' + dates[x].links.Tickets.LINK_URI +'" target="_blank"><img src="../../images/buyTix.png" border="0" /></a>';
				} else {
					tourHtml += '&nbsp';
				}

				tourHtml += '</div>';

				tourHtml += '<div id="tourHomeRSVP">';
				if(dates[x].links.RSVP){
					tourHtml += '<a href="' + dates[x].links.RSVP.LINK_URI +'" target="_blank"><img src="../../images/rsvp.png" border="0" /></a>';
				} else {
					tourHtml += '&nbsp';
				}

				tourHtml += '</div>';	

				tourHtml += '<div id="clearFix"></div></div>';

				if(tourCount > 10) break;
			}

			tourHtml += '<div style="float: right"><div id="moreNews" style="padding: 0px 10px 0px 0px"><div style="padding: 5px 0px 0px 0px"><a href="http://www.johnlegend.com/tour" onclick="loadSection(\''+ terr +'\', \'tour\'); return false;">More Dates</a></div></div></div>';

		} else {
			tourHtml += '<div id="tourHomeRow">No upcoming dates, check back soon!</div><div id="clearFix"></div>';
		}	
		
		tourHtml += '</div><div id="clearFix"></div>';
		
		html = feat1 + feat2 + newsHtml + tourHtml + block1 + block2 + block3 + block4 +'<div id="clearFix" style="padding-bottom: 10px"></div>';
		
		content.innerHTML = html;
		
		break;
		
		
		
		default:
		
		fadeBG(0);
	
		var news = siteObj[terr].news;

		var tourdates = siteObj[terr].tour;

		var video = siteObj[terr].home.video;

		var audio = siteObj[terr].home.audio;

		var friends = siteObj[terr].home.friends;

		var content = getElement('content');

		var propCount = 0;

		content.innerHTML = "";

		for(property in news.articles)
		{
			propCount++;
			html = '<div id="homeContent"><div id="homeNews" style="width:100%; height: 100%" onmouseover="toggleBgColor(this.id,\'in\'); this.style.cursor=\'pointer\';"  onmouseout="toggleBgColor(this.id,\'out\');" onclick="showHomeDiv(\'newsDiv\');"><div id="homeHeader"> <a href="'+ root +terr+'/rss" target="_blank"><img src="'+ root +'/images/rss.png" border="0"></a> '+ localization["Latest Updates"] +'</div></div>';
			html += '<div id="newsDiv"';

			if(p != "news") html+= ' class="initiallyHidden"';

			html += '><div id="homeDivContent">';
			html += '<div id="homeHeadline"><a href="'+ news.articles[property].url +'" target="_blank">' + news.articles[property].title +'</a></div>';
			html += '<div id="homeDate">' + news.articles[property].date +'</div>';
			if(news.articles[property].abstract != "")
			{
				html += '<div id="homeBody">'+ news.articles[property].abstract +'</div>';
			} else {
				html += '<div id="homeBody">'+ news.articles[property].body +'</div>';
			}
			html += '<div id="homeShare"><table width="100%" height="20" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><table width="300" cellspacing="0" cellpadding="0"><tr valign="top"><td>' + news.articles[property].like +'</td><td>'+ news.articles[property].twitter +'</td><td><div id="moreComments"><div style="padding: 4px 0px 0px 0px"><a href="javascript:void(0);" onclick="showComments(\'comments\');">'+ news.articles[property].localization.comments +'</a></div></div></td><td><div id="moreNews" style="padding: 0px 10px 0px 0px"><div style="padding: 4px 0px 0px 0px"><a href="http://www.johnlegend.com/news" onclick="loadSection(\''+ terr +'\', \'news\');  return false;">'+ localization["More news"] +'</a></div></div></td></tr></table></td></tr></table></div>';
			html += '<div style="padding: 10px 10px 10px 10px"><div id="comments" class="initiallyHidden">'+ news.articles[property].comments +'</div></div>';
			html += '</div></div>'
			html += '</div>'
			content.innerHTML += html;
			if(propCount > 0) break;

		}


		var dates = tourdates.articles.all;

		var headers = tourdates.headers;

		var dateCount = 5;

		html = '<div id="homeContent"><div id="homeTour" style="width:100%; height: 100%" onmouseover="toggleBgColor(this.id,\'in\'); this.style.cursor=\'pointer\';"  onmouseout="toggleBgColor(this.id,\'out\');" onclick="showHomeDiv(\'tourDiv\');"><div id="homeHeader">'+ localization["Upcoming Shows"] +'</div></div>';

		html += '<div id="tourDiv"';

		if(p != "tour") html += ' class="initiallyHidden"';

		html += '><div id="homeDivContent">';


		var tourdates = siteObj[terr].tour;


		var pages = tourdates.pagination;


		if(pages.length > 0) {


			html += '<div id="tourRow"><div id="tourDate">'+ localization.Date +'</div><div id="tourVenue">'+ localization.Venue +'</div><div id="tourLocation">'+ localization.Location+'</div><div id="tourTix">'+ localization.Tickets +'</div><div id="tourRSVP">'+ localization.RSVP +'</div></div>';

			var c = 0;

			for(property in dates)
			{

				x = property;

				html += '<div id="tourRow"><div id="row'+c+'" onmouseover="toggleBgColor(this.id,\'in\');"  onmouseout="toggleBgColor(this.id,\'out\');" style="background-color: transparent">';
				html += '<div id="tourDate">' + dates[x].date +'</div>';

				html += '<div id="tourVenue">';
				if(dates[x].links.Venue){
					html += '<a href="' + dates[x].links.Venue.LINK_URI +'" target="_blank">'+ dates[x].venue +'</a>';
				} else {
					html += dates[x].venue;
				}
				html += '</div>';

				if(dates[x].location != "")
				{
					html += '<div id="tourLocation">' + dates[x].location +'</div>';
				} else {
					html += '<div id="tourLocation">&nbsp;</div>';
				}

				html += '<div id="tourTix">';
				if(dates[x].links.Tickets){
					html += '<a href="' + dates[x].links.Tickets.LINK_URI +'" target="_blank"><img src="../../images/buyTix.png" border="0" /></a>';
				} else {
					html += '&nbsp';
				}

				html += '</div>';

				html += '<div id="tourRSVP">';
				if(dates[x].links.RSVP){
					html += '<a href="' + dates[x].links.RSVP.LINK_URI +'" target="_blank"><img src="../../images/rsvp.png" border="0" /></a>';
				} else {
					html += '&nbsp';
				}

				html += '</div>';	

				if(dates[x].presale != "")
				{
					html += '<div id="tourInfo">';
					html += '<div id="moreNews"><div style="padding: 2px 0px 0px 0px"><a href="javascript:void(0);" onclick="showComments(\'infoDiv'+ x +'\');">'+ localization["Pre-Sale Info"] +'</a></div></div>';
					html += '</div><div id="clearFix"></div>';
					html += '<div id="infoDiv'+ x +'" class="initiallyHidden"><div id="tourInfoMore">' + dates[x].presale +'</div></div>';
				} else if(dates[x].notes != "")
				{
					html += '<div id="tourInfo">';
					html += '<div id="moreNews"><div style="padding: 2px 0px 0px 0px"><a href="javascript:void(0);" onclick="showComments(\'infoDiv'+ x +'\');">'+ localization["More Info"] +'</a></div></div>';
					html += '</div><div id="clearFix"></div>';
					html += '<div id="infoDiv'+ x +'" class="initiallyHidden"><div id="tourInfoMore">' + dates[x].notes +'</div></div>';
				} 
				html += '<div id="clearFix"></div></div></div>';

				c++;
			}

			html += '<div id="clearFix"></div><div style="float: right"><div id="moreNews" style="padding: 0px 10px 0px 0px"><div style="padding: 5px 0px 0px 0px"><a href="http://www.johnlegend.com/tour" onclick="loadSection(\''+ terr +'\', \'tour\'); return false;">'+ localization.More +'</a></div></div></div>';

		} else {
			html += '<div id="tourRow">No upcoming dates, check back soon!</div>';
		}
		html += '<div id="clearFix"></div></div></div>';
		html += '</div>'
		content.innerHTML += html;	

		if(video.articles.length > 0)
		{

			html = '<div id="homeContent"><div id="homeVideo" style="width:100%; height: 100%" onmouseover="toggleBgColor(this.id,\'in\'); this.style.cursor=\'pointer\';"  onmouseout="toggleBgColor(this.id,\'out\');" onclick="showHomeDiv(\'videoDiv\');"><div id="homeHeader">'+ video.articles[0].title +'</div></div>';
			html += '<div id="videoDiv"';

			if(p != "video") html+= ' class="initiallyHidden"';

			html += '><div id="homeDivContent">';
			html += '<div id="homeDate>' + video.articles[0].date +'</div>';
			html += '<div id="homeBody">' + video.articles[0].body +'</div>';
			html += '<div id="homeShare"><table width="100%" height="20" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><table width="300" cellspacing="0" cellpadding="0"><tr valign="top"><td>' + video.articles[0].like +'</td><td>' + video.articles[0].twitter +'</td><td><div id="moreNews" style="padding: 0px 10px 0px 0px"><div style="padding: 6px 0px 0px 0px"><a href="javascript:void(0);" onclick="loadSection(\''+ terr +'\', \'video\');">'+ localization.More +'</a></div></div></td></tr></table></td></tr></table></div>';
			html += '</div></div>'
			html += '</div>'
			content.innerHTML += html;
		}

/*
		if(audio.articles.length > 0)
		{

			html = '<div id="homeContent"><div id="homeHeader"><a href="javascript:void(0);" onmouseover="showHomeDiv(\'audioDiv\');">'+ audio.header +'</a></div>';
			html += '<div id="audioDiv"';

			if(p != "audio") html+= ' class="initiallyHidden"';

			html += '><div id="homeDivContent">';
			html += '<div id="homeHeadline">' + audio.articles[0].title +'</div>';
			html += '<div id="homeDate>' + audio.articles[0].date +'</div>';
			html += '<div id="homeBody">' + audio.articles[0].body +'</div>';
			html += '<div id="homeShare"><table width="100%" height="20" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><table width="300" cellspacing="0" cellpadding="0"><tr valign="top"><td>' + audio.articles[0].like +'</td><td>' + audio.articles[0].twitter +'</td></tr></table></td></tr></table></div>';
			html += '</div></div>'
			html += '</div>'
			content.innerHTML += html;
		}
*/

		if(friends.articles.length > 0)
		{

			html = '<div id="homeContent"><div id="homeFriend" style="width:100%; height: 100%" onmouseover="toggleBgColor(this.id,\'in\'); this.style.cursor=\'pointer\';"  onmouseout="toggleBgColor(this.id,\'out\');" onclick="showHomeDiv(\'friendDiv\');"><div id="homeHeader">'+ friends.articles[0].title +'</div></div>';
			html += '<div id="friendDiv"';

			if(p != "friends") html+= ' class="initiallyHidden"';

			html += '><div id="homeDivContent">';
			html += '<div>' + friends.articles[0].body +'</div><br/><br/>';
			html += '<div id="homeShare"><table width="100%" height="20" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><table width="300" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><div id="moreNews" style="padding: 0px 10px 0px 0px"><div style="padding: 5px 0px 0px 0px"><a href="http://www.johnlegend.com/community" onclick="loadSection(\''+ terr +'\', \'community\'); return false;">'+ localization.More +'</a></div></div></td></tr></table></td></tr></table></div>';
			html += '</div></div>'
			html += '</div>'
			content.innerHTML += html;
			loadTwitter('2', 'home');
		}

		socialNets();
	
		break
	}

	if(justLoaded == false) 
	{
		FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	} else {
		justLoaded = false;
	}
}

function loadPhotos()
{
	fadeBG(1);
	getPhotoFeed('johnlegend', 'albums');
}

function socialNets()
{
	/*
	var content = getElement('content');
	html = '<div id="socialNets">';
	html +='<a href="http://www.facebook.com/johnlegend" target="_blank"><img src="../../images/soc_facebook.jpg" border="0" style="margin: 0px 5px 0px 0px" /></a><a href="http://www.twitter.com/johnlegend" target="_blank"><img src="../../images/soc_twitter.jpg" border="0" style="margin: 0px 5px 0px 0px" /></a><a href="http://www.myspace.com/johnlegend" target="_blank"><img src="../../images/soc_myspace.jpg" border="0" style="margin: 0px 5px 0px 0px" /></a>';
	html +='<div>';
	content.innerHTML += html;
	*/
}

function showHomeDiv(id)
{

	if(id != currentHomeDiv)
	{
		if(currentHomeDiv != "Div")
		{	
			if(document.getElementById(currentHomeDiv).style.display != "none")
			{
				jQuery("#"+ currentHomeDiv+"").slideUp();
			}
		}
		jQuery("#"+ id +"").slideDown();

		currentHomeDiv = id;
	}

}

function loadNews()
{

	fadeBG(0);
	
	var p1 = arguments[0];	
	var p2 = arguments[1];

	var localization = siteObj[terr].localization;
	
	var news = siteObj[terr].news;
	
	var totalArticles = news.length;
	
	var articles = news.articles;
	
	var archive = news.archive;
	
	var pages = news.pagination;
	
	var content = getElement('content');

	var itemsPerPage = 6;
	
	var currPage = 1;

	var totalPages = Math.ceil(pages.length / itemsPerPage);
	
	var start = 0;
	var end = 0;
	
	var html = "";
	content.innerHTML = "";
	
	if(p1 == undefined || p1 == "" || p1 == "page")
	{
		if(p1 == undefined || p1 == "")
		{
			if(itemsPerPage > totalArticles)
			{	
				end = totalArticles;
			} else {
				end = itemsPerPage - 1;
			}
		} else {
			currPage = parseInt(p2);
			if(currPage < totalPages)
			{
				if(currPage == 1)
				{
					start = 0;
					if(itemsPerPage > totalArticles)
					{	
						end = totalArticles;
					} else {
						end = itemsPerPage - 1;
					}
				} else {
					start = itemsPerPage * (currPage - 1);
					end = (start + itemsPerPage) - 1;
				}
			} else {
				start = itemsPerPage * (currPage - 1);
				end = (start + itemsPerPage) - 1;
				if((start + itemsPerPage) - 1 > pages.length)
				{
					end = pages.length;
				}
			}
		}
		
		var paginationHTML = "";
		
		if(totalPages > 1)
		{
			
			paginationHTML += '<div id="paginationDiv">';
			
			var pageStart = 1;
			
			if(totalPages < 11)
			{
				if(currPage > 1) 
				{
					var prevPage = currPage - 1;
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+ prevPage +');"> << </div>';
				}
				for(x = pageStart; x < totalPages + 1; x++)
				{
					if(x == currPage)
					{
						paginationHTML += '<div id="paginationCurr">'+ x+'</div>';
					} else {
						paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+x+');">'+ x +'</div>';
					}
				}
				
				if(currPage > totalPages ) 
				{
					var nextPage = currPage + 1;
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+ nextPage +');"> >> </div>';
				}
			} 
			else if(totalPages > 10)
			{
				if(currPage < 6)
				{
					pageStart = 1;
					if(currPage > 1) 
					{
						var prevPage = currPage - 1;
						paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+ prevPage +');"> << </div>';
					}
					for(x = pageStart; x < 11; x++)
					{
						if(x == currPage)
						{
							paginationHTML += '<div id="paginationCurr">'+ x +'</div>';
						} else {
							paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+x+');">'+ x +'</div>';
						}

					}
					var nextPage = currPage + 1;
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+ nextPage +');"> >> </div>';
					
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+totalPages+');">'+  localization.Last +'</div>';
				} 
				else if(currPage > 5 && totalPages > currPage + 5) 
				{
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', \'1\');">'+ localization.First +'</div>';

					pageStart = currPage - 4;
					var prevPage = currPage - 1;
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+ prevPage +');"> << </div>';
					
					for(x = pageStart; x < (currPage + 5); x++)
					{
						if(x == currPage)
						{
							paginationHTML += '<div id="paginationCurr">'+ x +'</div>';
						} else {
							paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+x+');">'+ x +'</div>';
						}

					}
					var nextPage = currPage + 1;
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+ nextPage +');"> >> </div>';
					
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+totalPages+');">'+  localization.Last +'</div>';
				}
				else if(currPage > 5 && totalPages < currPage + 5)
				{
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', \'1\');">'+ localization.First +'</div>';
					pageStart = totalPages - 9;
					var prevPage = currPage - 1;
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+ prevPage +');"> << </div>';
					
					for(x = pageStart; x < (totalPages + 1); x++)
					{
						if(x == currPage)
						{
							paginationHTML += '<div id="paginationCurr">'+ x +'</div>';
						} else {
							paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+x+');">'+ x +'</div>';
						}

					}
					if(currPage < totalPages ) 
					{
						var nextPage = currPage + 1;
						paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNews(\'page\', '+ nextPage +');"> >> </div>';
					}
	
				}
			} 
			paginationHTML += '</div>';
			paginationHTML += '<div id="clearDiv"></div>';
				
					
		}		
		
		var sHTML = '<div id="homeHeaderSelectDiv"><select id="newsArchiveSelect" onchange="loadArchive(this.selectedIndex);">';
		for(property in archive)
		{
			sHTML += '<option value="'+ property +'"';
			
			if(p1 == property) sHTML += ' selected';
			
			sHTML += '>'+property+'</option>';
		}
		
		sHTML += '</select></div>';
		
		html = '<div id="newsContent"><div id="newsHeader">'+ sHTML +' <a href="'+ root +terr+'/rss" target="_blank"><img src="'+ root +'/images/rss.png" border="0"></a> '+ news.header +'</div>';
		
		html += paginationHTML +'<br/><br/>';
		
		for(x = start; x < end; x++)
		{
			property = pages[x];

			html += '<div id="newsDiv"><div id="newsDivContent">';
			html += '<div id="newsHeadline"><a href="' + news.articles[property].url +'" target="_blank">'+ news.articles[property].title +'</a></div>';
			html += '<div id="newsDate">' + news.articles[property].date +'</div>';
			html += '<div id="newsBody">';
			
			if(news.articles[property].image.thumb != undefined)
			{
				var image = news.articles[property].image.thumb;

				html += '<img src="' + root + image.url +'" width="'+ image.width +'" height="' + image.height +'" align="left" style="margin: 0px 5px 5px 0px;" />';

			}
					
			html += news.articles[property].body +'</div>';
			html += '<div id="clearFix"></div>';
			html += '<div id="newsShare"><table width="100%" height="20" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><table width="300" cellspacing="0" cellpadding="0"><tr valign="top"><td>' + news.articles[property].like +'</td><td>'+ news.articles[property].twitter +'</td><td style="padding: 0px 10px 0px 0px"><div id="moreComments"><div style="padding: 4px 0px 0px 0px"><a href="javascript:void(0);" onclick="showComments(\'comments'+ x +'\');">'+ localization.Comments +'</a></div></div></td></tr></table></td></tr></table></div>';
			html += '<div style="padding: 10px 10px 10px 10px"><div id="comments'+ x +'" ';
			
			if(x > start) html += 'class="initiallyHidden"';
			
			html += '><div id="commentsNews">'+ news.articles[property].comments +'</div></div></div>';
			html += '</div></div>'
			
			if(x < end - 1) html += '<div id="delineator"></div>';

		}
			
		html += paginationHTML;
	
	} else if(news.articles[p1+'_'+p2] != undefined) {
		var art = news.articles[p1+'_'+p2];
		html = '<div id="newsContent"><div id="newsHeader"><a href="'+ root +terr+'/rss" target="_blank"><img src="'+ root +'/images/rss.png" border="0"></a> <a href="javascript:void(0);" onclick="showHomeDiv(\'newsDiv\');">'+ news.header +'</a></div>';
		html += '<div id="newsDiv"><div id="newsDivContent">';
		html += '<div id="newsHeadline"><a href="' + art.url +'" target="_blank">'+ art.title +'</a></div>';
		html += '<div id="newsDate">' + art.date +'</div>';
		html += '<div id="newsBody">' + art.body +'</div>';
		html += '<div id="newsShare"><table width="100%" height="20" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><table width="300" cellspacing="0" cellpadding="0"><tr valign="top"><td>' + art.like +'</td><td>'+ art.twitter +'</td><td><div id="moreNews" style="padding: 0px 10px 0px 0px"><div style="padding: 4px 0px 0px 0px"><a href="http://www.johnlegend.com/news" onclick="loadSection(\''+ terr +'\', \'news\'); return false;">'+ localization["More news"] +'</a></div></div></td></tr></table></td></tr></table></div>';
		html += '<div style="padding: 10px 10px 10px 10px"><div id="commentsNews">'+ art.comments +'</div></div>';
		html += '</div></div>'
	} else {
		loadNews();
	}
		
	html += '</div>'
	content.innerHTML += html;		
	
	socialNets();
	
	if(justLoaded == false) 
	{
		FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	} else {
		justLoaded = false;
	}
}

function loadArchive(dd)
{
	
	var options = document.getElementById('newsArchiveSelect').options;
	if(options[dd].value !=  "all" && options[dd].value != "")
	{
		loadNewsArchive(options[dd].value);
	} else {
		loadNews();
	}
}

function loadNewsArchive()
{

	fadeBG(1);
	
	var p1 = arguments[0];	
	var p2 = arguments[1];
	var p3 = arguments[2];

	var localization = siteObj[terr].localization;
	
	var news = siteObj[terr].news;
	
	var totalArticles = news.length;
	
	var articles = news.archive[p1];
	
	var archive = news.archive;
	
	var pages = new Array();
	
	for(property in articles) pages.push(property);
	
	var content = getElement('content');

	var itemsPerPage = 6;
	
	var currPage = 1;

	var totalPages = Math.ceil(pages.length / itemsPerPage);
	
	var start = 0;
	var end = 0;
	
	var html = "";
	content.innerHTML = "";
	
	if(p2 == undefined || p2 == "" || p2 == "page")
	{
		if(p2 == undefined || p2 == "")
		{
			if(itemsPerPage > totalArticles)
			{	
				end = totalArticles;
			} else {
				end = itemsPerPage - 1;
			}
		} else {
			currPage = parseInt(p3);
			if(currPage < totalPages)
			{
				if(currPage == 1)
				{
					start = 0;
					if(itemsPerPage > totalArticles)
					{	
						end = totalArticles;
					} else {
						end = itemsPerPage - 1;
					}
				} else {
					start = itemsPerPage * (currPage - 1);
					end = (start + itemsPerPage) - 1;
				}
			} else {
				start = itemsPerPage * (currPage - 1);
				end = (start + itemsPerPage) - 1;
				if((start + itemsPerPage) - 1 > pages.length)
				{
					end = pages.length;
				}
			}
		}

		var paginationHTML = "";
		
		if(totalPages > 1)
		{
			
			paginationHTML += '<div id="paginationDiv">';
			
			var pageStart = 1;
			
			if(totalPages < 11)
			{
				for(x = pageStart; x < totalPages + 1; x++)
				{
					if(x == currPage)
					{
						paginationHTML += '<div id="paginationCurr">'+ x+'</div>';
					} else {
						paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', '+x+');">'+ x +'</div>';
					}
				}
			} 
			else if(totalPages > 10)
			{
				if(currPage < 6)
				{
					pageStart = 1;
					for(x = pageStart; x < 11; x++)
					{
						if(x == currPage)
						{
							paginationHTML += '<div id="paginationCurr">'+ x +'</div>';
						} else {
							paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', '+x+');">'+ x +'</div>';
						}

					}
					var prevPage = pageStart - 1;
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', '+ prevPage +');">  >> </div>';
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', '+totalPages+');">'+  localization.Last +'</div>';
				} 
				else if(currPage > 5 && totalPages > currPage + 5) 
				{
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', \'1\');">'+ localization.First +'</div>';
					pageStart = currPage - 4;
					var prevPage = pageStart - 1;
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', '+ prevPage +');"> << </div>';
					for(x = pageStart; x < (currPage + 5); x++)
					{
						if(x == currPage)
						{
							paginationHTML += '<div id="paginationCurr">'+ x +'</div>';
						} else {
							paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', '+x+');">'+ x +'</div>';
						}

					}
					var nextPage = pageStart + 1;
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', '+ nextPage +');">  >> </div>';
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', '+totalPages+');">'+  localization.Last +'</div>';
				}
				else if(currPage > 5 && totalPages < currPage + 5)
				{
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', \'1\');">'+ localization.First +'</div>';
					pageStart = totalPages - 9;
					var prevPage = pageStart - 1;
					paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', '+ prevPage +');"> << </div>';

					for(x = pageStart; x < (totalPages + 1); x++)
					{
						if(x == currPage)
						{
							paginationHTML += '<div id="paginationCurr">'+ x +'</div>';
						} else {
							paginationHTML += '<div id="pagination" onclick="document.getElementById(\'container\').scrollTop = 0; loadNewsArchive(\''+ p1 +'\', \'page\', '+x+');">'+ x +'</div>';
						}

					}
	
				}
			} 
			paginationHTML += '</div>';
			paginationHTML += '<div id="clearDiv"></div>';
				
					
		}		
		var sHTML = '<div id="homeHeaderSelectDiv"><select id="newsArchiveSelect" onchange="loadArchive(this.selectedIndex);"><option value="all">All News</option><option value="">--------</option>';
		for(property in archive)
		{
			sHTML += '<option value="'+ property +'"';
			
			if(p1 == property) sHTML += ' selected';
			
			sHTML += '>'+property+'</option>';
		}
		
		sHTML += '</select></div>';
		
		html = '<div id="newsContent"><div id="newsHeader">'+sHTML + '  <a href="'+ root +terr+'/rss" target="_blank"><img src="'+ root +'/images/rss.png" border="0"></a> '+ news.header +'</div>';
		
		html += paginationHTML +'<br/><br/>';
		
		for(x = start; x < end; x++)
		{
			property = pages[x];

			html += '<div id="newsDiv"><div id="newsDivContent">';
			html += '<div id="newsHeadline"><a href="' + articles[property].url +'" target="_blank">' + articles[property].title +'</a></div>';
			html += '<div id="newsDate">' + articles[property].date +'</div>';
			html += '<div id="newsBody">' + articles[property].body +'</div>';
			html += '<div id="newsShare"><table width="100%" height="20" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><table width="300" cellspacing="0" cellpadding="0"><tr valign="top"><td>' + articles[property].like +'</td><td>'+ articles[property].twitter +'</td><td style="padding: 0px 10px 0px 0px"><div id="moreComments"><div style="padding: 4px 0px 0px 0px"><a href="javascript:void(0);" onclick="showComments(\'comments'+ x +'\');">'+ localization.Comments +'</a></div></div></td></tr></table></td></tr></table></div>';
			html += '<div style="padding: 10px 10px 10px 10px"><div id="comments'+ x +'" ';
			
			if (x > start) html += 'class="initiallyHidden"';
			
			html += '><div id="commentsNews">'+ articles[property].comments +'</div></div></div>';
			html += '</div></div>'
			
			if(x < end - 1) html += '<div id="delineator"></div>';

		}
			
		html += paginationHTML;
	
	} else if(articles[p1+'_'+p2] != undefined) {
		var art = articles[p1+'_'+p2];
		html = '<div id="newsContent"><div id="newsHeader"> <a href="'+ root +terr+'/rss" target="_blank"><img src="'+ root +'/images/rss.png" border="0"></a> <a href="javascript:void(0);" onclick="showHomeDiv(\'newsDiv\');">'+ header +'</a></div>';
		html += '<div id="newsDiv"><div id="newsDivContent">';
		html += '<div id="newsHeadline"><a href="' + art.url +'" target="_blank">' + art.title +'</a></div>';
		html += '<div id="newsDate">' + art.date +'</div>';
		html += '<div id="newsBody">' + art.body +'</div>';
		html += '<div id="newsShare"><table width="100%" height="20" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><table width="300" cellspacing="0" cellpadding="0"><tr valign="top"><td>' + art.like +'</td><td>'+ art.twitter +'</td><td><div id="moreComments"><div style="padding: 4px 0px 0px 0px"><a href="javascript:void(0);" onclick="showComments(\'comments\');">'+ localization.Comments +'</a></div></div></td><td><div id="moreNews" style="padding: 0px 10px 0px 0px"><div style="padding: 4px 0px 0px 0px"><a href="http://www.johnlegend.com/news" onclick="loadSection(\''+ terr +'\', \'news\'); return false;">'+ localization["More news"] +'</a></div></div></td></tr></table></td></tr></table></div>';
		html += '<div style="padding: 10px 10px 10px 10px"><div id="commentsNews">'+ art.comments +'</div></div>';
		html += '</div></div>'
	} else {
		loadNews();
	}
		
	html += '</div>'
	content.innerHTML += html;		
	
	socialNets();
	
	if(justLoaded == false) 
	{
		FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	} else {
		justLoaded = false;
	}
}

function showComments(id)
{

	if(document.getElementById(id).style.display == "block")
	{
		jQuery("#"+ id +"").slideUp();
	} else {
		jQuery("#"+ id +"").slideDown();
	}
}

var rowBGActive = "#666666";

function loadTour()
{

	fadeBG(2);
	
	var localization = siteObj[terr].localization;
	
	var tourdates = siteObj[terr].tour;
	
	var home = siteObj[terr].home;
	
	var dates = tourdates.articles.all;
	
	var pages =tourdates.pagination;

	var headers = tourdates.headers;

	var dateCount = 5;
	
	var content = getElement('content');

	content.innerHTML = "";
	
	html = '<div id="homeContent">';
	
	html += '<div id="homeHeader">'+ headers.header +'</div>';

	
	var p1 = arguments[0];	
	var p2 = arguments[1];		

	for(var x in home.articles)
	{
		var homeBlock = home.articles[x]

		switch(homeBlock.title)
		{
		
			case "Tour Page Feature":

				html += '<div id="tourFeatureRow">' + homeBlock.body +'</div>';
				break;
		}

	}	
	
	
	if(pages.length > 0) {

		
		html += '<div id="tourRow"><div id="tourDate">'+ localization.Date +'</div><div id="tourVenue">'+ localization.Venue +'</div><div id="tourLocation">'+ localization.Location +'</div><div id="tourTix">'+ localization.Tickets +'</div><div id="tourRSVP">'+ localization.RSVP +'</div></div>';
		
		var c = 0;
		
		for(property in dates)
		{
			
			x = property;
			
			if((p1 != undefined && p1 != "") && (p2 != undefined && p2 != "") && property == (p1+"_"+p2))
			{
				bgColor = rowBGActive;
			} else {
				bgColor = "transparent";
			}
			
			html += '<div id="tourRow"><div id="row'+c+'" onmouseover="toggleBgColor(this.id,\'in\');"  onmouseout="toggleBgColor(this.id,\'out\');" style="background-color: '+ bgColor +'">';
			html += '<div id="tourDate">' + dates[x].date +'</div>';

			html += '<div id="tourVenue">';
			if(dates[x].links.Venue){
				html += '<a href="' + dates[x].links.Venue.LINK_URI +'" target="_blank">'+ dates[x].venue +'</a>';
			} else {
				html += dates[x].venue;
			}
			html += '</div>';

			if(dates[x].location != "")
			{
				html += '<div id="tourLocation">' + dates[x].location +'</div>';
			} else {
				html += '<div id="tourLocation">&nbsp;</div>';
			}

			html += '<div id="tourTix">';
			if(dates[x].links.Tickets){
				html += '<a href="' + dates[x].links.Tickets.LINK_URI +'" target="_blank"><img src="../../images/buyTix.png" border="0" /></a>';
			} else {
				html += '&nbsp';
			}
			
			html += '</div>';

			html += '<div id="tourRSVP">';

			if(dates[x].links.RSVP){
				html += '<a href="' + dates[x].links.RSVP.LINK_URI +'" target="_blank"><img src="../../images/rsvp.png" border="0" /></a>';
			} else {
				html += '&nbsp';
			}

			html += '</div>';	

			
			if(dates[x].presale != "")
			{
				html += '<div id="tourInfo">';
				html += '<div id="moreNews"><div style="padding: 2px 0px 0px 0px"><a href="javascript:void(0);" onclick="showComments(\'infoDiv'+ x +'\');">'+ localization["Pre-Sale Info"] +'</a></div></div>';
				html += '</div><div id="clearFix"></div>';
				html += '<div id="infoDiv'+ x +'"';

				if((p1 != undefined && p1 != "") && (p2 != undefined && p2 != "") && property == (p1+"_"+p2))
				{
					html += 'style="display: block"';
				} else {
					html += 'class="initiallyHidden"';
				}

				html += '><div id="tourInfoMore">' + dates[x].presale +'</div></div>';
			} 
			else if(dates[x].notes != "")
			{
				html += '<div id="tourInfo">';
				html += '<div id="moreNews"><div style="padding: 2px 0px 0px 0px"><a href="javascript:void(0);" onclick="showComments(\'infoDiv'+ x +'\');">'+ localization["More Info"] +'</a></div></div>';
				html += '</div><div id="clearFix"></div>';
				html += '<div id="infoDiv'+ x +'"';
				
				if((p1 != undefined && p1 != "") && (p2 != undefined && p2 != "") && property == (p1+"_"+p2))
				{
					html += 'style="display: block"';
				} else {
					html += 'class="initiallyHidden"';
				}
				
				html += '><div id="tourInfoMore">' + dates[x].notes +'</div></div>';
			} 
			html += '<div id="clearFix"></div></div></div>';
			
			c++;
		}
		
	} else {
		html += '<div id="tourRow">No upcoming dates, check back soon!</div>';
	}
	
	html += '<div id="clearFix"></div></div>';
	
	content.innerHTML += html;
	
/*	
	var html2 = "";
	
	html2 = '<div id="homeContent">';
	
	html2 += '<div id="homeHeader">'+ headers.header +'</div>';

	
	var p1 = arguments[0];	
	var p2 = arguments[1];		

	for(var x in home.articles)
	{
		var homeBlock = home.articles[x]

		switch(homeBlock.title)
		{
		
			case "Tour Page Feature":

				html2 += '<div id="tourFeatureRow">' + homeBlock.body +'</div>';
				break;
		}

	}	
	html2 += '<div id="tourRow" style="height: auto"><iframe frameborder="0" width="700" allowTransparency="true" style="overflow-x: hidden; overflow-y: hidden; height: " name="sliframe" id="sliframe" scrolling="no" src="http://api.sonicliving.com/eventlist/collection/104?fb_app_id=2554375427&api_key=1993bea1&css=http%3A%2F%2Fwww.johnlegend.com%2Fcss%2Fsonicliving.css&tickettext=Click+here+for+tickets!&dateformat=F+j"></iframe></div>';
	html2 += '<div id="clearFix"></div></div>';
	content.innerHTML += html2;
		
	sliframeResizer();
	socialNets();
	if(justLoaded == true) justLoaded = false;
*/
	//var resizer = setTimeout(sliframeResizer, 1000);
	/*
	var sliframeResizer = function() {
	    if (document.location.hash.indexOf('#h=') == 0) {
		var sliheight = parseInt(document.location.hash.replace('#h=', ''));
		document.location.hash = null;
		sliframe.style.height = sliheight + 'px';
	    } else if (resizeCount < 100) {
		resizeCount++;
		setTimeout(sliframeResizer, 50);
	    }
	};
	
	
	*/
	
}

function sliframeResizer()
{
	var fileref=document.createElement('script')
	  fileref.setAttribute("type","text/javascript")
	  fileref.setAttribute("src", "http://c390749.r49.cf2.rackcdn.com/javascript/autoresize.js");
	if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref);
}

/*
function sliframeResizer () {
    var sliframe = document.getElementById('sliframe');
    alert(document.location.hash.replace('#h=', ''));
    if (document.location.hash.indexOf('#h=') == 0) {
	var sliheight = parseInt(document.location.hash.replace('#h=', ''));
	document.location.hash = null;
	sliframe.style.height = sliheight + 'px';
    } else if (resizeCount < 100) {
	resizeCount++;
	setTimeout(sliframeResizer, 50);
    }
}
	*/
function toggleBgColor(rowId, dir)
{
	
	var row = document.getElementById(rowId);
	
	switch(dir)
	{
		case "in":
			row.style.backgroundColor = ""+ rowBGActive+"";
			break;
		case "out":
			row.style.backgroundColor = "transparent";
			break;
	}
}


var miniPosition = 7;

var propCount = 0;

var prop = "";

var defaultPropRelease = "";

function loadMusic()
{

	propCount = 0;
	
	fadeBG(3);
	
	
	var p1 = arguments[0];	

	var content = getElement('content');

	content.innerHTML = "";
	
	var divWidth = 90;
	
	var localization = siteObj[terr].localization;
	
	var releases = siteObj[terr].releases.articles;
	
	// selector
	
	html = '<div id="homeContent"><div id="homeHeader">'+ siteObj[terr].releases.header +'</div>';
	
	var selHtml = "";
	
	selHtml = '<div id="miniSelector"><div id="miniLeft" onclick="shiftMinis(\'left\');" onmouseover="this.style.cursor=\'pointer\'"><img src="../../images/left.png" /></div><div style="float:left"><div id="miniMask"><div id="miniHolder">';
	
	prop = "";
	
	for(property in releases)
	{
		if(propCount == 0) defaultPropRelease = property;
		
		var release = releases[property];
		
		var mini = release.cover;
		
		selHtml += '<div id="miniDiv" onclick="jQuery(\'#releaseDiv\').slideUp(\'500\', function() { loadRelease(\''+ property +'\'); });" onmouseover="this.style.cursor=\'pointer\'"><img src="'+ root + mini.url +'" width="86" height="86" border="0" /></div>';
		
		propCount++;
	}
	
	selHtml += '</div></div></div><div id="miniRight" onclick="shiftMinis(\'right\');" onmouseover="this.style.cursor=\'pointer\'"><img src="../../images/right.png" /></div></div>';
	
	var relHtml = '<div id="releaseDiv" class="initiallyHidden"></div>';
	
	html += selHtml + relHtml;
	
	html += '<div style="clear:both"></div></div>';

	content.innerHTML += html;		
	
	socialNets();
	
	if(p1 == undefined || p1 == "")
	{
		loadRelease(defaultPropRelease);
	} else {
		loadRelease(p1);
	}
}

function loadRelease(query)
{
	var release = siteObj[terr].releases.articles[query];

	var tracks = release.tracks;

	var links = release.links;
	
	var formats = release.formats;

	var localization = siteObj[terr].localization;
	
	var html = '<div id="releaseHolder"><div id="releaseMini"><img src="' + root + release.cover.url +'" width="300" height="300" /></div>';
	html += '<div style="float: right; width:340px"><div id="releaseTitle">'+ release.title +'</div>';
	html += '<div id="releaseDate">'+ release.date +'</div>';
	if(links.length > 0)
	{
		html += '<div id="releaseLinks">Buy it:<br/>';
		for(var x in links)
		{
			html += '<div id="linkDiv"><a href="'+ links[x].LINK_URI +'" target="_blank">'+ links[x].LINK_TEXT +'</a></div>';
		}
		html += '</div>';
	}

	if(formats.length > 0)
	{
		var tracks = formats[0].TRACKS;
		
		html += '<div id="releaseTracks">';
		for(var x in tracks)
		{
			html += '<div id="trackDiv"><div style="width:17px; float:left; text-align:right; margin: 0px 3px 0px 0px">'+ (parseInt(x) + 1)+'.</div>'+ tracks[x].TRACK_TITLE +'</div>';
		}
		html += '</div>';
	}

	html += '</div>';
	html += '<div style="clear:both"></div>';	
	html += '<div id="homeShare"><table width="100%" height="20" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><table width="300" cellspacing="0" cellpadding="0"><tr valign="top"><td>' + release.like +'</td><td>'+ release.twitter +'</td><td style="padding: 0px 10px 0px 0px"><div id="moreComments"><div style="padding: 4px 0px 0px 0px"><a href="javascript:void(0);" onclick="showComments(\'comments\');">'+ localization.Comments +'</a></div></div></td></tr></table></td></tr></table></div>';
	html += '<div style="clear:both; margin: 0px 0px 20px 0px"></div>';
	if(release.notes != 'null') html += '<div style="float:left; width:100%">'+ release.notes +'</div>';
	html += '<div style="clear:both"></div>';
	html += '<div style="padding: 10px 0px 10px 0px"><div id="comments">'+ release.comments +'</div></div>';
	html += '</div>';

	var content = getElement('releaseDiv');
	
	content.innerHTML = html;
	
	jQuery('#releaseDiv').slideDown(500);
	FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	/*
	if(justLoaded == false) 
	{
		FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	} else {
		justLoaded = false;
		
	}	
	*/
	//showComments('comments');
}
	
function shiftMinis(dir)
{
	switch(dir)
	{
		case "left":
			if(miniPosition > 7)
			{
				miniPosition--;
				jQuery("#miniHolder").animate({"left": "+=90px"}, 500);
			}
			break;

		case "right":
			if(miniPosition < propCount)
			{
				miniPosition++;
				jQuery("#miniHolder").animate({"left": "-=90px"}, 500);
			}
			break;
	}
}

/*
var videoArray = new Object();

videoArray.wakeupeverybody = {title: "Wake Up Everybody", vevo: "USSM21001113", youtube: "DR8a37wdwIY", mp4: "http://release.sonymusic.com/media/release/7e9972ceed621cf09b6a?catalog=catalog_51"};
videoArray.everybodyknows = {title: "Everybody Knows", vevo: "USSM20803518", youtube: "jmWBpSxd63g", mp4: "http://release.sonymusic.com/media/release/624cc8f2d6799d92756a?catalog=catalog_51"};
videoArray.slowdance = {title: "Slow Dance", vevo: "USSM20703622", youtube: "IRYW7vVDKQQ", mp4: "http://release.sonymusic.com/media/release/7cfdb9778ccd890b499f?catalog=catalog_51"};
videoArray.greenlight = {title: "Greenlight feat. Andre 3000", vevo: "USSM20801455", youtube: "5S6dc4KlywI", mp4: "http://release.sonymusic.com/media/release/8b95c8aada2e8f865028?catalog=catalog_51"};
videoArray.showme = {title: "Show Me", vevo: "USSM20702742", youtube: "fMzI7bzLItI", mp4: "http://release.sonymusic.com/media/release/a1fe5d83712df5c41285?catalog=catalog_51"};
videoArray.stereo = {title: "Stereo", vevo: "USSM20700676", youtube: "D6AvYank6xI", mp4: "http://release.sonymusic.com/media/release/85496121b79113a9c98e?catalog=catalog_51"};
videoArray.pda = {title: "P.D.A. (We Just Don't Care)", vevo: "USSM20700392", youtube: "MNddM12irDI", mp4: "http://release.sonymusic.com/media/release/ea9b8f59e1a41753a1fc?catalog=catalog_51"};
videoArray.heaven = {title: "Heaven",  vevo: "USSM20601125", youtube: "d8Aj0ZE9zg4", mp4: "http://release.sonymusic.com/media/release/91054520b8a609aad57f?catalog=catalog_51"};
videoArray.numberone = {title: "Number One", vevo: "USSM20500485", youtube: "ouEqTn2wa5Q", mp4: "http://release.sonymusic.com/media/release/b9a098aa3cd6aabc42bb?catalog=catalog_51"};
videoArray.sohigh = {title: "So High", vevo: "USSM20500633", youtube: "QnFnfImvQio", mp4: "http://release.sonymusic.com/media/release/dcfb1a7b90c727a40e39?catalog=catalog_51"};
videoArray.ordinarypeople = {title: "Ordinary People", vevo: "USSM20403933", youtube: "FspuTRz1alc", mp4: "http://release.sonymusic.com/media/release/492a0aaeed1a4ffe3302?catalog=catalog_51"};
videoArray.usedtoloveu = {title: "Used To Love U",  vevo: "USSM20403176", youtube: "xZFM8L6br_8", mp4: "http://release.sonymusic.com/media/release/dd2569b9e77af1843092?catalog=catalog_51"};

*/

var miniVidPosition = 5;

var propVidCount = 0;

var propVid = "";

var defaultProp = "";

function loadVideos()
{	

	p1 = arguments[0];
	if(p1 == undefined || p1 == "") p1 = "summertour2011";
	fadeBG(4);

	var localization = siteObj[terr].localization;
	
	var video = siteObj[terr].video;
	
	var articles = video.articles;
	
	var content = getElement('content');

	var html = "";
	content.innerHTML = "";
			
	
	var art = articles[0];
	html = '<div id="homeContent"><div id="homeHeader"><a href="javascript:void(0);" onclick="showHomeDiv(\'newsDiv\');">'+ video.header +'</a></div>';
	html += '<div id="newsDiv"><div id="homeDivContent">';
	
	html += '<div id="videoButtons"><div id="videoButton" onmouseover="this.style.cursor=\'pointer\'" onclick="showVideoPane(\'officialVids\');">Official Videos</div><div id="videoButton" onmouseover="this.style.cursor=\'pointer\'" onclick="showVideoPane(\'camVids\');">John\'s Cam</div><div id="videoButton" onmouseover="this.style.cursor=\'pointer\'" onclick="showVideoPane(\'summerTour\');">John Legend Summer 2011 Tour w/Sade</div></div>';
	
	
	
	html += '<div id="officialVids"';
	
	switch(p1)
	{
		case "johnscam":
		
			currentVideoPane = "camVids";
			html += 'class="initiallyHidden"';

			break;

		case "summertour2011":
		
			currentVideoPane = "summerTour";
			html += 'class="initiallyHidden"';

			break;	
	}
		
	html += '>';
	
	var selHtml = "";
	
	selHtml = '<div id="miniVidSelector"><div id="miniVidLeft" onclick="shiftVidMinis(\'left\');" onmouseover="this.style.cursor=\'pointer\'"><img src="../../images/left.png" /></div><div style="float:left"><div id="miniVidMask"><div id="miniVidHolder">';
	
	propVid = "";
	
	for(property in articles)
	{
		if(propVidCount == 0) defaultProp = property;
		
		var release = articles[property];
		
		var miniVid = root+release.image.main.url;
		
		selHtml += '<div id="miniVidDiv" onclick="jQuery(\'#videoDiv\').slideUp(\'500\', function() { loadVideo(\''+ property +'\'); });" onmouseover="this.style.cursor=\'pointer\'"><img src="'+miniVid +'" width="120" height="90" border="0" /></div>';
		
		propVidCount++;
	}
	
	selHtml += '</div></div></div><div id="miniVidRight" onclick="shiftVidMinis(\'right\');" onmouseover="this.style.cursor=\'pointer\'"><img src="../../images/right.png" /></div></div>';
	html += selHtml;
	html += '<div id="videoDiv"></div>';
	html += '</div>';
	html += '<div id="camVids"';

	switch(p1)
	{
		case "johnscam":
		
			currentVideoPane = "camVids";
			break;

		case "summertour2011":
		
			currentVideoPane = "summerTour";
			html += 'class="initiallyHidden"';

			break;	
		
		default:
			html += 'class="initiallyHidden"';
			currentVideoPane = "officialVids";
			break;
	}
	
	html+= '><center><object width="650" height="521"><param name="movie" value="http://www.youtube.com/p/D5235C9057651205?hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/p/D5235C9057651205?hl=en_US&amp;fs=1" type="application/x-shockwave-flash" width="650" height="521" allowscriptaccess="always" allowfullscreen="true"></embed></object></center></div>';
	
	html += '<div id="summerTour"';

	switch(p1)
	{
		case "johnscam":
		
			currentVideoPane = "camVids";
			html += 'class="initiallyHidden"';

			break;

		case "summertour2011":
		
			currentVideoPane = "summerTour";
			break;	
		
		default:
			html += 'class="initiallyHidden"';
			currentVideoPane = "officialVids";
			break;
	}
	
	html+= '><center><object width="650" height="521"><param name="movie" value="http://www.youtube.com/p/CAD19AB1AD5A5F08?hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/p/CAD19AB1AD5A5F08?hl=en_US&amp;fs=1" type="application/x-shockwave-flash" width="650" height="521" allowscriptaccess="always" allowfullscreen="true"></embed></object></center></div>';
		
	
	html += '</div></div>'
	
	html += '</div>'
	content.innerHTML += html;		

	socialNets();
	
	switch(p1)
	{
		case "johnscam":
			loadVideo(defaultProp);
			break;

		case "summertour2011":
		
			loadVideo(defaultProp);
			break;	
		
		default:
			if(p1 == undefined || p1 == "")
			{
				loadVideo(defaultProp);
			} else {
				loadVideo(p1);
			}
			break;
	}

}

var currentVideoPane = "";

function loadVideo(videoName)
{

	
	var localization = siteObj[terr].localization;
	
	var video = siteObj[terr].video.articles[videoName];
	var html = '<div id="homeHeadline" style="margin: 0px 0px 20px 45px"><a href="'+ video.url +'" target="_blank">'+ video.title +'</a></div>';
	html += '<div style="text-align: center; width: 100%; margin: 0px 0px 20px 0px">';
	
	switch(browserName)
	{
		case "ipad":
		case "safari":
		
			videoId = video.mp4;
			
			html+= '<video width="640" height="353" id="videoPlayer" controls>';
			html+= '</video>';			
			break;
			
		default:
		
			switch(terr)
			{

				case "us":
				case "ca":
					
					videoId = video.vevo;
					html += '<object width="575" height="324"><param name="movie" value="http://www.vevo.com/VideoPlayer/Embedded?videoId='+ videoId +'&playlist=false&autoplay=0&playerId=62FF0A5C-0D9E-4AC1-AF04-1D9E97EE3961&playerType=embedded&env=0"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.vevo.com/VideoPlayer/Embedded?videoId='+ videoId +'&playlist=false&autoplay=0&playerId=62FF0A5C-0D9E-4AC1-AF04-1D9E97EE3961&playerType=embedded&env=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="575" height="324" bgcolor="#000000"></embed></object>';
					break;
					
				default:
					videoId = video.youtube;
					html += '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/'+ videoId +'?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+ videoId +'?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>';
					break;
			}
			
			break;
	}

	html += '</div><div id="clearFix"></div>';

	var uri = root + 'video/'+ videoName;
	var xid = videoName + video.vevo;
	var title = video.title;
	
	var comments = '<fb:comments xid="'+ xid +'" title="'+ title +'" url="'+  uri +'" width="600" publish_feed="false" candelete="true" simple="false" css="http://www.johnlegend.com/css/fbcomments.css"></fb:comments>';

	FB_HREF = uri;
	FB_WIDTH = 90;

	FB_HEIGHT = 20;

	FB_FACES = 'false';
	var like = '<iframe src="http://www.facebook.com/plugins/like.php?href='+ FB_HREF +'&amp;layout=button_count&amp;show_faces='+ FB_FACES +'&amp;width='+ FB_WIDTH +'&amp;action=like&amp;font=arial&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:'+ FB_WIDTH +'px; height:'+ FB_HEIGHT +'px"></iframe>';

	var twitter = '<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?url='+ escape(uri)  +'&via=johnlegend&count=horizontal&text=' . title +'" style="width:130px; height:50px;"></iframe>';


	html += '<div id="homeShare"><table width="100%" height="20" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><table width="300" cellspacing="0" cellpadding="0"><tr valign="top"><td>' + like +'</td><td>'+ twitter +'</td><td style="padding:0px 10px 0px 0px"><div id="moreComments"><div style="padding: 4px 0px 0px 0px"><a href="javascript:void(0);" onclick="showComments(\'comments\');">'+ localization.Comments +'</a></div></div></td></tr></table></td></tr></table></div>';
	html += '<div id="clearFix"></div>';
	html += '<div style="padding: 10px 10px 10px 10px"><div id="comments">'+ comments +'</div></div>';
	var content = getElement('videoDiv');
	
	content.innerHTML = html;
	
	switch(browserName)
	{
		case "ipad":
		case "safari":	
		
			var videoAjax = document.getElementsByTagName("video")[0];
			
			videoAjax.src = video.mp4;

			videoAjax.type = "video/mp4";

			videoAjax.load();
			break;
	
	}
	
	jQuery('#videoDiv').slideDown(500);
	FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	/*
	if(justLoaded == false) 
	{
		FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	} else {
		justLoaded = false;
	}	
*/
	//showComments('comments');
}

function showVideoPane(id)
{
	document.getElementById(currentVideoPane).style.display = "none";
	currentVideoPane = id;
	document.getElementById(currentVideoPane).style.display = "block";
}

function shiftVidMinis(dir)
{
	switch(dir)
	{
		case "left":
			if(miniVidPosition > 5)
			{
				miniVidPosition--;
				jQuery("#miniVidHolder").animate({"left": "+=124px"}, 500);
			}
			break;

		case "right":
			if(miniVidPosition < propVidCount)
			{
				miniVidPosition++;
				jQuery("#miniVidHolder").animate({"left": "-=124px"}, 500);
			}
			break;
	}
}


function loadGive()
{

	//currentBGIndex = 1;
	
	//setStage();

	var localization = siteObj[terr].localization;
	
	var give = siteObj[terr].give;
	
	var articles = give.articles;
	
	var content = getElement('content');

	var html = "";
	content.innerHTML = "";
			
	
	var art = articles[0];
	html = '<div id="homeContent"><div id="homeHeader"><a href="javascript:void(0);" onclick="showHomeDiv(\'newsDiv\');">'+ give.header +'</a></div>';
	html += '<div id="newsDiv"><div id="homeDivContent">';
	
	if(art.image.main != undefined)
	{
		var image = art.image.main;
		
		html += '<div style="float: left;width:100%"><img src="'+ root + image.url+'" width="'+ image.width +'" height="'+ image.height +'" /></div>';
	}
	
	html += '<div id="homeHeadline">' + art.title +'</div>';
	html += '<div id="homeBody">' + art.body +'</div>';
	html += '<div id="homeShare"><table width="100%" height="20" cellspacing="0" cellpadding="0"><tr valign="top" align="right"><td><table width="300" cellspacing="0" cellpadding="0"><tr valign="top"><td>' + art.like +'</td><td>'+ art.twitter +'</td><td style="padding:0px 10px 0px 0px"><div id="moreComments"><div style="padding: 4px 0px 0px 0px"><a href="javascript:void(0);" onclick="showComments(\'comments\');">'+ art.localization.comments +'</a></div></div></td></tr></table></td></tr></table></div>';
	html += '<div style="padding: 10px 10px 10px 10px"><div id="comments" class="initiallyHidden"><div id="comments">'+ art.comments +'</div></div></div>';
	html += '</div></div>'
		
	html += '</div>'
	content.innerHTML += html;		
	
	socialNets();

	FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	/*
	if(justLoaded == false) 
	{
		FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	} else {
		justLoaded = false;
	}
	*/
}


function loadStore()
{

	fadeBG(5);
	

	var localization = siteObj[terr].localization;
	
	var store = siteObj[terr].store;
	
	var articles = store.articles;
	
	var content = getElement('content');

	var html = "";
	content.innerHTML = "";
			
	
	var art = articles[0];
	html = '<div id="homeContent"><div id="homeHeader"><a href="javascript:void(0);" onclick="showHomeDiv(\'newsDiv\');">'+ store.header +'</a></div>';
	html += '<div id="newsDiv"><div id="homeDivContent">';
	html += '<div id="homeBody">' + art.body +'</div>';
	html += '</div></div>'
		
	html += '</div>'
	content.innerHTML += html;	
	
	socialNets();
	if(justLoaded == true) justLoaded = false;

}


function loadExtras()
{

	fadeBG(5);
	
	var localization = siteObj[terr].localization;
	
	var extras = siteObj[terr].extras;
	
	var articles = extras.articles;
	
	var content = getElement('content');

	var html = "";
	content.innerHTML = "";
			
	
	var art = articles[0];
	html = '<div id="homeContent"><div id="homeHeader"><a href="javascript:void(0);" onclick="showHomeDiv(\'newsDiv\');">'+ localization.Extras +'</a></div>';
	html += '<div>' + art.body +'</div>';
	html += '</div>'
	content.innerHTML += html;	
	//loadTwitter('2', 'community');
	
	socialNets();
	if(justLoaded == true) justLoaded = false;
	
}

function loadCommunity()
{

	fadeBG(5);
	
	var localization = siteObj[terr].localization;
	
	var community = siteObj[terr].community;
	
	var articles = community.articles;
	
	var content = getElement('content');

	var html = "";
	content.innerHTML = "";
			
	
	var art = articles[0];
	html = '<div id="homeContent"><div id="homeHeader"><a href="javascript:void(0);" onclick="showHomeDiv(\'newsDiv\');">'+ community.header +'</a></div>';
	html += '<div id="newsDiv"><div id="homeDivContent">';
	
	if(terr == 'us')
	{
		html += '<div style="width: 330px; height: 587px; float: left; margin: 20px 0px 0px;">';
		html += '<div id="communityTwitter"></div>';
		html += '<div id="communityCitizennet"><iframe allowtransparency="true" src="http://www.johnlegend.com/modules/citizennet.html" style="width: 330px; height: 330px;" frameborder="0" scrolling="no"></iframe></div>';
		html += '</div>';
		html += '<div style="width: 330px; height: 580px; float: left; margin: 20px 0px 0px 20px;">';
		html += '<div id="communityLikeBox"><iframe src="http://www.facebook.com/plugins/likebox.php?id=22516413022&amp;width=330&amp;connections=10&amp;stream=true&amp;header=true&amp;height=580" style="border: medium none; background-color: rgb(255, 255, 255); overflow: hidden; width: 330px; height: 580px;" allowtransparency="false" frameborder="0" scrolling="no"></iframe></div>';
		html += '</div><div id="clearFix"></div>';
	}
	
	html += '<div>' + art.body +'<div id="clearFix"></div></div>';
	html += '</div></div>'
		
	html += '</div>';
	content.innerHTML += html;	
	loadTwitter('3', 'community');
	
	socialNets();

	FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	/*
	if(justLoaded == false) 
	{
		FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	} else {
		justLoaded = false;
	}	
	*/
}

function loadBGTest()
{

	fadeBG(6);
	
	var localization = siteObj[terr].localization;
	
	var community = siteObj[terr].community;
	
	var articles = community.articles;
	
	var content = getElement('content');

	var html = "";
	content.innerHTML = "";
			
	
	var art = articles[0];
	html = '<div id="homeContent"><div id="homeHeader"><a href="javascript:void(0);" onclick="showHomeDiv(\'newsDiv\');">'+ community.header +'</a></div>';
	html += '<div id="newsDiv"><div id="homeDivContent">';
	html += '<div>' + art.body +'</div>';
	html += '</div></div>'
		
	html += '</div>'
	content.innerHTML += html;	
	loadTwitter('2', 'community');
	
	socialNets();

	FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	/*
	if(justLoaded == false) 
	{
		FB.init({appId: '119539424764337', status: true, cookie: true, xfbml: true});
	} else {
		justLoaded = false;
	}	
	*/
}

function tableRollover(obj) {
	document.getElementById(obj).style.backgroundColor='#db0038';
}

function tableRollout(obj) {
	document.getElementById(obj).style.backgroundColor='transparent';
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[ i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[ i];}}
} 

var canSwap = "true";


function printImage(imageUrl, width, height, max) {


	imageWidth = parseInt(width * (max/width));
	imageHeight = parseInt(height * (max/width));


	leftDif = parseInt((max - imageWidth) / 2);
	topDif = parseInt((max - imageHeight) / 2);

	image = "<img src=\""+imageUrl+"\" width=\""+imageWidth+"\" height=\""+imageHeight+"\" border=\"0\" align=\"top\">"; 
	
	return image;

}

function addslashes(str) {

	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}

function stripslashes(str) {
	var thisStr = "";
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

function capitalize(obj) {
        val = obj;
        newVal = '';
        val = val.split(' ');
        for(var c=0; c < val.length; c++) {
                newVal += val[c].substring(0,1).toUpperCase() + val[c].substring(1,val[c].length) + ' ';
        }
        return newVal;
}


function getElement(id){	
	if (!document.getElementById){
	 return;
	}
	//
	if (document.getElementById){
		// this is the way the standards work
		var el = document.getElementById(id);
	}else if (document.all){
		// this is the way old msie versions work
		var  el = document.all[id];
	}else if (document.layers){
		// this is the way nn4 works
		var el = document.layers[id];
	}
	return el;
}

toggleDisplay=function(el){
	el.style.display = el.style.display ? "" : "block";
}


function placePlayer(sDivId, previewUrl, iteration)
{
      var oXMLHttp = GetXMLHttpObject();

	  var url="../php/placePreviewPlayer.php";
	  url=url+"?previewUrl="+previewUrl;
	  url=url+"&iteration="+iteration;
	  url=url+"&browser="+browser;

      oXMLHttp.open("GET", url, true);

      oXMLHttp.onreadystatechange = function()
            {
                  if (oXMLHttp.readyState == 4)
                  {	
                        document.getElementById(sDivId).innerHTML = oXMLHttp.responseText;
                  }
            }

      oXMLHttp.send(null);
}



function changeVal(id)
{
	val = "";
	document.getElementById(id).value = val;
}

function submitEmail(loc)
{
	var email = document.getElementById('email').value;

	if(loc == null)
	{
		thisLoc = "";
	} else {
		thisLoc = loc;
	}
	
	var url = thisLoc + "community/?email="+email;

	document.location = url;
}

//
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i = 0; i<vars.length; i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
}

function scrollToTop()
{
	jQuery('html, body').animate({scrollTop:0}, 'slow');
}
function getScreenSize()
{
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
		screenWidth = window.innerWidth;
		screenHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
		screenWidth = document.documentElement.clientWidth;
		screenHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
		screenWidth = document.body.clientWidth;
		screenHeight = document.body.clientHeight;
	}

	arrayPageSize = new Array(screenWidth,screenHeight)
	return arrayPageSize;
}

/*
function bgSlideShow(){

	setInterval ( "fadeBG()", 5000 );

}

var bgSlideShow = 0;

function fadeBG(){
	
	bgNum = arguments[0];
	
	if(currentBGIndex == null) currentBGIndex = bgNum;
	
	var currentBG = "bgImage"+ currentBGIndex;

	if(document.getElementById(currentBG).style.display == "inline")
	{
		jQuery("#"+ currentBG + "").fadeOut(500, function() { fadeBG(); } );
		
		if(currentBGIndex < bgArray.length - 1)
		{
			currentBGIndex++;
		} else { 
			currentBGIndex = 0;
		}
	
	} else {
	
		jQuery("#"+ currentBG + "").fadeIn(500);
	}
}

*/


function fadeBG(){
	
	bgNum = arguments[0];
	
	if(currentBGIndex == null) currentBGIndex = bgNum;
	
	var currentBG = "bgImage"+ currentBGIndex;

	if(document.getElementById(currentBG).style.display == "inline")
	{
		jQuery("#"+ currentBG + "").fadeOut(500, function() { fadeBG(); } );
		
		currentBGIndex = bgNum;
	
	} else {
	
		jQuery("#"+ currentBG + "").fadeIn(500);
	}
}

var pageSize = new Array();

function setStage()
{

	//img = bgArray[currentBGIndex];

	pageSize = getScreenSize();
	randomNum = Math.floor((6-1)*Math.random()) + 1;

	var bgWidth = pageSize[0];
	
	if(pageSize[0] > 1650)
	{
		bgDim = 2100;
		difference = pageSize[0] / bgDim;
		bgHeight = 1400 * difference;
		
	} else {
		
		bgDim = 1650;
		bgWidth = bgDim;
		difference = pageSize[0] / bgDim;
		bgHeight = 1100;
		
	}
	

	if(pageSize[0] <= 800)
	{
		document.getElementById('container').style.overflowX = "auto";
	} else {
		document.getElementById('container').style.overflowX = "hidden";
	}
		
	var bgImages = document.getElementById('backgroundDiv').childNodes;
	

	for(images in bgArray)
	{
		var thisBG = "bgImage"+images;

		document.getElementById(''+ thisBG +'').style.width= bgWidth +"px";
		document.getElementById(''+ thisBG +'').style.height= bgHeight +"px";
	}

	//document.getElementById('backgroundDiv').innerHTML = "<img src=\"" + img +"\" width=\""+ bgWidth+"\" height=\""+ bgHeight +"\" />";
	document.getElementById('backgroundDiv').style.width = bgDim +"px";
	document.getElementById('backgroundDiv').style.top = "0px";
	
//	document.getElementById('backgroundDiv').style.top = ((pageSize[1]) / 2) - (bgHeight / 2) +"px";
	
	//document.getElementById('backgroundDiv').style.left = (pageSize[0] / 2) - (bgDim / 2) +"px";
	
	//placeSecondary();
	//placeTertiary();

}



function launch(url, name, width, height, options)
	{
	if (!name)
		{
		name = "window_" + Math.floor(1000 * Math.random());
		}
	
	if (!width)
		{
		width = screen.availWidth;
		}
		
	if (!height)
		{
		height = screen.availHeight;
		}
	
	if (!options)
		{
		options = "menubar=1,toolbar=1,location=1,directories=1,status=1,scrollbars=1,resizable=1";
		}
	
	width	= Math.min(width, screen.availWidth);
	height	= Math.min(height, screen.availHeight);
	var x	= Math.max(0, 0.5 * (screen.availWidth - width));
	var y	= Math.max(0, 0.5 * (screen.availHeight - height));

	var config = "";
	config += "left=" + x + ",top=" + y + ",";
	config += "screenX=" + x + ",screenY=" + y + ",";
	config += "width=" + width + ",height=" + height;
	config += "," + options;

	var win = window.open(url, name, config);
	if (win && window.focus)
		{
		win.focus();
		}
	}


function loadBuyBlock()
{
	var article = siteObj[terr].buyBlock.articles;
	
	if(article.length > 0)
	{
		var html = article[0].body;
		document.getElementById('miniBuyDiv').style.display = "block";
		document.getElementById('miniBuyDiv').innerHTML = html;
	} else {	
		document.getElementById('miniBuyDiv').style.display = "none";
	}
}
		

function showPlaylist()
{

	if(getElement('radioInfo').style.display == "block")
		{
		jQuery("#radioInfo").slideUp();
	}
	
	if(getElement('radioPlaylist').style.display == "block")
	{
		jQuery("#radioPlaylist").slideUp();
		getElement('radioPlaylistButton').innerHTML = '<a href="Javascript:void(0);" onclick="showPlaylist();"><img src="images/playlist_open.jpg" border="0" width="100" height="16" border="0" /></a>';

	} else {
		getElement('radioPlaylistButton').innerHTML = '<a href="Javascript:void(0);" onclick="showPlaylist();"><img src="images/playlist_close.jpg" border="0" width="100" height="16" border="0" /></a>';
		
		var info = '<table width="250" cellspacing="0" cellpadding="0" style="border-left: 1px solid #333333; border-bottom: 1px solid #333333; border-right: 1px solid #333333">';

		for(x = 0; x < radioObj.length; x++)
		{
		   
		   var release = radioObj[x];
		
		   info += '<tr valign="top"><td style="padding: 5px 5px 5px 5px; ';
		   
		   if((x + 1) < radioObj.length) info += 'border-bottom: 1px solid #333333;';

		   info += '"><span id="radioPlaylistText"><a href=\"Javascript:void(0);\" onclick=\"loadSong(\'' + x +'\', \''+ release.location +'\', \''+ escape(release.title) +'\');\">"'+ release.title + '" - '+ release.artistName +'</a></span></td>';
		   
		   info += '<td style="padding: 5px 0px 5px 0px; ';
		   
		   if((x + 1) < radioObj.length) info += 'border-bottom: 1px solid #333333;';

		   info += ' text-align: right;\"><a href=\"Javascript:void(0);\" onclick=\"loadSong(\'' + x +'\', \''+ release.location +'\', \''+ escape(release.title) +'\');\"><img src=\"images/play_button.jpg\" border=\"0\" /></a></td></tr>';
	
		}
		
		info += '<tr align="right"><td colspan="2"><a href="Javascript:void(0);" onclick="showPlaylist();"><img src="images/close_button_s.png" border="0"></a></td></tr></table>';

		getElement('radioPlaylist').innerHTML = info;
		jQuery("#radioPlaylist").slideDown();
		//getElement('radioInfo').style.display = "block";
	}
}

var currentSong = -1;



function stopAudio(id)
{
	if(objectPlaying != getElement(id))
	{
		objectPlaying.stopAudio();
	}
	
	var radio = getElement("radioPlayer");
	
	radio.stopAudio();
}

function loadSong(songNum, url, title)
{
	if(songNum == currentSong) 
	{
		stopAudio();
		currentSong = -1;
	} else {
	
		currentSong = songNum
		setPlaying('radioPlayer');
		objectPlaying.loadInSong(url, title);
	}

}

function playerLoaded()
{
	loadSong(radioObj[0].location, radioObj[0].title);
}

function placeRadio()
{
	var html = '<table width="255" height="20" cellspacing="0" cellpadding="0"><tr valign="center"><td>';
	
	switch(browserName)
	{

		case "firefox" :
				html += "<embed src=\"flash/radio.swf\" wmode=\"transparent\" quality=\"high\" bgcolor=\"#ffffff\" width=\"115\" height=\"18\" id=\"radioPlayer\" name=\"radioPlayer\" align=\"middle\" allowScriptAccess=\"always\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
				break;
		default :

				html += "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"115\"height=\"18\" id=\"radioPlayer\" align=\"middle\">";
				html += "<param name=\"allowScriptAccess\" value=\"always\" />";
				html += "<param name=\"allowFullScreen\" value=\"false\" />";
				html += "<param name=\"wmode\" value=\"transparent\" />";
				html += "<param name=\"movie\" value=\"flash/radio.swf\" />";
				html += "<param name=\"quality\" value=\"high\" />";
				html += "<param name=\"bgcolor\" value=\"#ffffff\" />";
				html += "<embed src=\"flash/radio.swf\" wmode=\"transparent\" quality=\"high\" bgcolor=\"#ffffff\" width=\"115\" height=\"18\" id=\"radioPlayer\" name=\"radioPlayer\" align=\"middle\" allowScriptAccess=\"always\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
				html += "</object>";
				break;
	}
	
	html += '</td><td><div id="radioInfoButton"><a href="Javascript:void(0);" onclick="showSongInfo();"><img src="images/moreSongInfo.jpg" border="0" width="27" height="16" border="0" /></a></div></td><td><div id="radioPlaylistButton"><a href="Javascript:void(0);" onclick="showPlaylist();"><img src="images/playlist_open.jpg" border="0" width="100" height="16" border="0" /></a></div></td></tr></table>';
	
	document.getElementById('radioDiv').innerHTML = html;
	

}

function loadPersistentPlayer()
{

	switch(browserName)
	{
		case "ipad":
			html = '<div id="sc-player"><a href="http://soundcloud.com/johnlegend/wake-up-everybody" class="sc-player">Loading Sound Cloud Player</a></div>';
			break;
			
		default:
			html = '<object height="18" width="320"> <param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Fjohnlegend%2Fwake-up-everybody&amp;auto_play=false&amp;player_type=tiny&amp;font=Arial&amp;theme_color=ffffff&amp;color=ff0000"> <param name="allowscriptaccess" value="always"> <param name="wmode" value="transparent"><embed wmode="transparent" allowscriptaccess="always" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Fjohnlegend%2Fwake-up-everybody&amp;auto_play=false&amp;player_type=tiny&amp;font=Arial&amp;theme_color=ffffff&amp;color=ffffff" type="application/x-shockwave-flash" height="18" width="320"> </object>';
			break;
	}
	var content = getElement('playerDiv');
	
	content.innerHTML = html;
	
	if(browserName == "ipad") jQuery('a.sc-player, div.sc-player').scPlayer();
}


function loadNewSC(artist, track)
{
  	document.getElementById('sc-player').innerHTML = '<a href="http://soundcloud.com/'+ artist +'/'+ track +'" class="sc-player">Test</a>'; // repalces current player with new one

  	jQuery('a.sc-player, div.sc-player').scPlayer();
}

function checkForCookie()
 {

	var form = document.forms['coppaCheck'];

	SONYMUSIC_COPPA_13.updateForm(form);


	// This function checks the value of the hidden "U13" form field and will write the appropriate flash var according to the value passed

	u13 = document.getElementById('U13').value;

	if(u13 == "true")
	{

		// global under13 cookie found, change embed code accordingly
		under13 = true;

	} else {
		//if(browserName != "msie") loadNewsLetter();
		loadNewsLetter();

	}

	

	// write message to div or send the value of u13 as a callBack to the widget

	//under13 = false;

}


function fSubmit()
{

	if(ValidateForm())
	{

		var email = findObj("email").value;
		sendEmail(email);
		jQuery('#fbNewsletterCont').fadeOut(500, function () { confirmNewsLetter() });

	}
}


function ValidateForm()
{

	var email = findObj("email").value;

	var filter=/^(("[\w-\s\+]+")|([\w-\+]+(?:\.[\w-\+]+)*)|("[\w-\s\+]+")([\w-\+]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;

	if (!filter.test(email)) {
		alert("Your email appears to be incorrect.");
		findObj("email").focus();
		return false;
	} else {
		var at = findObj("email").value.indexOf("@");
		if((email.charAt(0) == "+") || (email.charAt(at - 1) == "+"))
		{
			alert("Your email appears to be incorrect.");
			findObj("email").focus();
			return false;
		}
	}
	
	return true;
}


function areaOnFocus(element, inputText)
{

	var el = document.getElementById(element);
	if(el.value == inputText)
	{

	  el.value='';

	}

}

function areaOnBlur(element, inputText)
{

	var el = document.getElementById(element);
	if(el.value=='')
	{

	  el.value = inputText;

	}

}

function loadNewsLetterOld()
{
	if(!under13)
	{
		var localization = siteObj[terr].localization;
		
		var html = '<div id="fbNewsletterBox">'+ localization["Join The Mailing List"] +' <br/><input type="text" onfocus="areaOnFocus(\'email\', \'Email\')" onblur="areaOnBlur(\'email\', \'Email\')" name="email" id="email" value="Email"/></div><div style="float:right; margin: 20px 0px 0px 0px"><div id="moreNews" style="padding: 4px 0px 0px 0px"><div style="padding: 0px 4px 0px 0px"><a href="javascript:void(0);" onclick="fSubmit();">'+ localization.Submit +'</a></div></div></div><br/>';
		
		html += '<div id="fbNewsletterPP"><a href="http://www.fanbridge.com" target="_blank">Powered by <img src="../../images/fanbridge.png" width="9" height="10" border="0" align="bottom"  /> Fanbridge</a> | <a href="http://www.fanbridge.com/policies/privacy.php" target="blank">Policies and Terms</a></div>';
		
		var content = document.getElementById('fbNewsletterCont');
		
		//content.innerHTML = "";
		
		content.innerHTML = html;
		
		jQuery("#fbNewsletterCont").fadeIn(500);
	}
	
}

function loadNewsLetter()
{
	if(!under13)
	{
		var localization = siteObj[terr].localization;
		
		var html = '<div id="fbNewsletterBox">'+ localization["Join The Mailing List"] +' <br/><div style="overflow-x: hidden; overflow-y: hidden; height: 30px"><div style="margin-top:-24px; margin-left: -4px;"><div class="topspin-widget topspin-widget-email-for-media"><object type="application/x-shockwave-flash" width="300" height="80" id="TSWidget83686" data="http://cdn.topspin.net/widgets/email2/swf/TSEmailMediaWidget.swf?timestamp=1310400317"> <param value="always" name="allowScriptAccess" /> <param name="allowfullscreen" value="true" /> <param name="quality" value="high" />  <param name="wmode" value="transparent" /><param name="movie" value="http://cdn.topspin.net/widgets/email2/swf/TSEmailMediaWidget.swf?timestamp=1310400317" /> <param name="flashvars" value="widget_id=http://cdn.topspin.net/api/v1/artist/9745/email_for_media/83686?timestamp=1310400317&amp;displayInitialScreen=false&amp;theme=black&amp;highlightColor=0xFFFFFF" /></object></div></div></div></div><br/>';
		
		html += '<div id="fbNewsletterPP"><a href="http://www.topspinmedia.com" target="_blank">Powered by TopSpin</a> | <a href="http://app.topspin.net/account/privacypolicy_public" target="blank">Policies and Terms</a></div>';
		
		var content = document.getElementById('fbNewsletterCont');
		
		//content.innerHTML = "";
		
		content.innerHTML = html;
		
		jQuery("#fbNewsletterCont").fadeIn(500);
	}
	
}
	

function confirmNewsLetter()
{
	var localization = siteObj[terr].localization;
		
	var html = '<div id="fbNewsletterBox"><br/>'+ localization.Success +'</div><div style="float: right; padding: 20px 0px 0px 0px"><a href="javascript:void(0);" onclick="jQuery(\'#fbNewsletterCont\').fadeOut(500, function() { loadNewsLetter() });"><img src="../../images/reload.png"  border="0" /></a></div><br/>';

	html += '<div id="fbNewsletterPP"><a href="http://www.fanbridge.com" target="_blank">Powered by <img src="../../images/fanbridge.png" width="9" height="10" border="0" align="bottom" /> Fanbridge</a> | <a href="http://www.fanbridge.com/policies/privacy.php" target="blank">Policies and Terms</a></div>';

	var content = document.getElementById('fbNewsletterCont');
	
	content.innerHTML = html;

	jQuery("#fbNewsletterCont").fadeIn(500);
}


// Email feed

var oXMLHttpEmail;

function GetEmailXMLHttpObject()
{
     oXMLHttpEmail = null;

      try
      {
            oXMLHttpEmail = new ActiveXObject("MSXML2.XMLHTTP");
      }
      catch (E)
      {
            try
            {
                  oXMLHttpEmail = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (E)
            {
              oXMLHttpEmail = null;
            }
    }

      if ((oXMLHttpEmail == null) && (typeof(XMLHttpRequest) != 'undefined'))
      {
            oXMLHttpEmail = new XMLHttpRequest();
      }

      return oXMLHttpEmail;
}


var tweetObj = new Object;

function sendEmail(email)
{

	if(oXMLHttpEmail)
	{
		oXMLHttpEmail.abort();
	}

	oXMLHttpEmail = GetEmailXMLHttpObject();

	var url = "../../modules/sendEmail.php";

	oXMLHttpEmail.open("POST", url, true);

	var params = "email="+email;


	//Send the proper header information along with the request
	oXMLHttpEmail.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	oXMLHttpEmail.setRequestHeader("Content-length", params.length);
	oXMLHttpEmail.setRequestHeader("Connection", "close");

	oXMLHttpEmail.onreadystatechange = function()
	    {
		  if (oXMLHttpEmail.readyState == 4)
		  {
			//var response = oXMLHttpEmail.responseText;

			//alert(oXMLHttpEmail.responseText);
		  }
	    }


	oXMLHttpEmail.send(params);

}


function setPlaying(id){

	objectPlaying = getElement(id);
	
}


function loadContactForm()
{
	var localization = siteObj[terr].localization;
	var html = '<table width="100%" height="100%"><tr valign="center" align="center">';
	html +='<div id="contactForm" onclick="javascript:void(0);">';
	html +='<div id="contactFormElement"><div style="float: right"><a href="javascript:void(0);" onclick="hideContactForm();">['+ localization.Close +']</a></div></div>';
	html +='<div id="contactFormElement">Send a message to John, his Booking Agency, his Management, or inquire about chritable events and opportunities</div>';
	html +='<div id="contactFormElement">'+ localization.To +': <select id="contactSelectTo"> <option value="john">Email John</option><option value="booking">Booking</option><option value="management">Management</option><option value="charity">Charity</option></select></div>';
	html +='<div id="contactFormElement">'+ localization.Message+':<br/><textarea id="contactBody"></textarea></div>';
	html +='<div style="float:right; margin: 20px 0px 0px 0px"><div id="moreNews" style="padding: 4px 0px 0px 0px"><div style="padding: 0px 4px 0px 0px"><a href="javascript:void(0);" onclick="fSubmitContact();">'+ localization.Submit +'</a></div></div></div>';
	html +='</div>';
	html +='<td></tr></table>';
	
	document.getElementById('contactFormContainer').innerHTML = html;
	
	jQuery('#contactFormContainer').fadeIn(500);
}

function thanksContactForm()
{
	var localization = siteObj[terr].localization;
	var html = '<table width="100%" height="100%"><tr valign="center" align="center">';
	html +='<div id="contactForm" onclick="javascript:void(0);">';
	//html +='<div id="contactFormElement"><div style="float: right"><a href="javascript:void(0);" onclick="hideContactForm();">['+ localization.Close +']</a></div></div>';
	html +='<div id="contactFormElement" style="margin: auto">'+ localization["Thank you, your message has been sent"] +'</div>';
	html +='</div>';
	html +='<td></tr></table>';
	
	document.getElementById('contactFormContainer').innerHTML = html;
	
	jQuery('#contactFormContainer').fadeIn(500, function() { setTimeout( 'jQuery(\'#contactFormContainer\').fadeOut(3000)', 3000); });
}


function hideContactForm()
{
	jQuery('#contactFormContainer').fadeOut(500);
}


function trackPage(url, name, section)
{
	try {

			SME$Analytics.ajaxPageView( {pageURL: ""+ url +"", pageName: "" + name +"", siteSection: ""+ section +""});


	}catch(e){ alert('error');}

}

// Twitter feed

var oXMLHttpTwitter;

function GetTwitterXMLHttpObject()
{
     oXMLHttpTwitter = null;

      try
      {
            oXMLHttpTwitter = new ActiveXObject("MSXML2.XMLHTTP");
      }
      catch (E)
      {
            try
            {
                  oXMLHttpTwitter = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (E)
            {
              oXMLHttpTwitter = null;
            }
    }

      if ((oXMLHttpTwitter == null) && (typeof(XMLHttpRequest) != 'undefined'))
      {
            oXMLHttpTwitter = new XMLHttpRequest();
      }

      return oXMLHttpTwitter;
}


var tweetObj = new Object;

function loadTwitter(tweets, location)
{

	if(oXMLHttpTwitter)
	{
		oXMLHttpTwitter.abort();
	}

	oXMLHttpTwitter = GetTwitterXMLHttpObject();

	var url = "../../modules/twitter-ajax.php?tweets="+tweets;

	oXMLHttpTwitter.open("POST", url, true);

	oXMLHttpTwitter.onreadystatechange = function()
	    {
		  if (oXMLHttpTwitter.readyState == 4)
		  {
			//var JSONObject = new Object;

			var response = oXMLHttpTwitter.responseText;

			switch(location)
			{
				case "home":
				document.getElementById('friendTwitter').innerHTML = response;
				break;
				
				case "community":
				document.getElementById('communityTwitter').innerHTML = response;
				break;
			}
			
			var myscript = document.createElement('script');
			myscript.src = 'http://platform.twitter.com/widgets.js';
			document.getElementById('followbutton').appendChild(myscript);
		  }
	    }

	oXMLHttpTwitter.send(null);

}

// resetn Territory

var oXMLHttpTerritory;

function GetTerritoryXMLHttpObject()
{
     oXMLHttpTerritory = null;

      try
      {
            oXMLHttpTerritory = new ActiveXObject("MSXML2.XMLHTTP");
      }
      catch (E)
      {
            try
            {
                  oXMLHttpTerritory = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (E)
            {
              oXMLHttpTerritory = null;
            }
    }

      if ((oXMLHttpTerritory == null) && (typeof(XMLHttpRequest) != 'undefined'))
      {
            oXMLHttpTerritory = new XMLHttpRequest();
      }

      return oXMLHttpTerritory;
}


function resetTerritory(t_code, t_id, t_language)
{

	if(oXMLHttpTerritory)
	{
		oXMLHttpTerritory.abort();
	}

	oXMLHttpTerritory = GetTerritoryXMLHttpObject();

	var url = "../../modules/reset_territory.php?territory="+t_code+"&territory_id="+t_id+"&language="+t_language;

	oXMLHttpTerritory.open("POST", url, true);

	oXMLHttpTerritory.onreadystatechange = function()
	    {
		  if (oXMLHttpTerritory.readyState == 4)
		  {
		
		  }
	    }

	oXMLHttpTerritory.send(null);

}


// Send EMail

var oXMLHttpContact;

function GetContactXMLHttpObject()
{
     oXMLHttpContact = null;

      try
      {
            oXMLHttpContact = new ActiveXObject("MSXML2.XMLHTTP");
      }
      catch (E)
      {
            try
            {
                  oXMLHttpContact = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (E)
            {
              oXMLHttpContact = null;
            }
    }

      if ((oXMLHttpContact == null) && (typeof(XMLHttpRequest) != 'undefined'))
      {
            oXMLHttpContact = new XMLHttpRequest();
      }

      return oXMLHttpContact;
}

function sendContactForm(to, message)
{

	if(oXMLHttpContact)
	{
		oXMLHttpContact.abort();
	}

	oXMLHttpContact = GetContactXMLHttpObject();

	var url = "../../modules/send_email.php?to="+to+"&message="+message;

	oXMLHttpContact.open("POST", url, true);

	oXMLHttpContact.onreadystatechange = function()
	    {
		  if (oXMLHttpContact.readyState == 4)
		  {
		  	
			jQuery('#contactFormContainer').fadeOut(500, function() { thanksContactForm(); });

		  }
	    }

	oXMLHttpContact.send(null);

}


function fSubmitContact()
{

	if(ValidateFormContact())
	{

		var select = findObj("contactSelectTo");
		var to = select.options[select.selectedIndex].value;
		var message = findObj("contactBody").value;
		
		sendContactForm(to, message);
	}
}


function ValidateFormContact()
{

	if(findObj("contactBody").value == "") 
	{
		alert("Please include a Message.");
		findObj("contactMessage").focus();
		return false;
	}
	
	return true;
}

// photoAlbums

var galleryCount = 0;
var currentGallery = 0;


var albumsObj = new Object;

var albumObj = new Object;

var galleries = new Object;

var oXMLHttpPhoto;

function GetPhotoXMLHttpObject()
{
     oXMLHttpPhoto = null;

      try
      {
            oXMLHttpPhoto = new ActiveXObject("MSXML2.XMLHTTP");
      }
      catch (E)
      {
            try
            {
                  oXMLHttpPhoto = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (E)
            {
              oXMLHttpPhoto = null;
            }
    }

      if ((oXMLHttpPhoto == null) && (typeof(XMLHttpRequest) != 'undefined'))
      {
            oXMLHttpPhoto = new XMLHttpRequest();
      }

      return oXMLHttpPhoto;
}

function getPhotoFeed(id, feedType, divId)
{


	if(oXMLHttpPhoto)
	{
		oXMLHttpPhoto.abort();
	}

	oXMLHttpPhoto = GetPhotoXMLHttpObject();

	//var url = "https://graph.facebook.com/"+ id +"/"+feedType;
	var url = "../../modules/getFBgraph.php?id="+ id;

	switch(feedType)
	{
		case "photos":
			document.getElementById('loadingDiv').innerHTML = '<div id="photoHeadline">Loading gallery '+ (currentGallery + 1) +' of '+ (galleries.length) +' <img src="'+ root+'images/ajax-loader.gif" /></div>';
			url += "&feedType=photos";
			break;

		case "albums":
			url += "&feedType=albums";
			break;
	}

	oXMLHttpPhoto.open("POST", url, true);

	oXMLHttpPhoto.onreadystatechange = function()
	    {

	   // if (oXMLHttpPhoto.readyState == 1) document.getElementById('content').innerHTML = "loading";

	   // if (oXMLHttpPhoto.readyState == 2) document.getElementById('content').innerHTML = "loaded";

		  if (oXMLHttpPhoto.readyState == 4)
		  {

			switch(feedType)
			{
				case "photos":
					var response = oXMLHttpPhoto.responseText;
					albumObj = JSON.parse(response);
					galleries[currentGallery].photos = albumObj.data;
					showGallery(currentGallery);
					if(currentGallery < galleries.length - 1)
					{
						currentGallery++;
						loadGallery(currentGallery);
					}
					break;

				case "albums":
					var response = oXMLHttpPhoto.responseText;

					albumsObj = JSON.parse(response);
					galleries = albumsObj.data;

					//photoHTML += '<div id="homeContent"><div id="homeHeader">'+ siteObj[terr].localizations.photos +'</div></div>';

					document.getElementById('content').innerHTML = '<div id="homeContent"><div id="homeHeader">PHOTOS</div><div id="loadingDiv" style="width: 100%"></div><div id="galleries" class="initiallyHidden"></div><div id="clearFix"></div></div>';

					loadGallery(currentGallery);
					break;
			}

		  }
	    }

	oXMLHttpPhoto.send(null);

}


function loadGallery(i)
{

	var photoHTML = "";
	photoHTML += '<div id="photoDiv">';
	photoHTML += '<div id="photoHeadline">'+ galleries[i].name +'</div><div id="photoHolder"><div id="pDiv_'+i+'"></div></div>';
	photoHTML += '</div>';
	photoHTML += '<div id="clearFix"></div>';
	document.getElementById('galleries').innerHTML += photoHTML;
	getPhotoFeed(galleries[i].id, 'photos');
}

var gallery1;
var gallery2;

function showGallery(i)
{
	var gallery = galleries[i].photos;

	var pDiv = "pDiv_"+ i;

	var thumbsDiv = document.getElementById(pDiv);

	thumbsDiv.innerHTML = "";

	for(var x in gallery)
	{

		var photo = gallery[x];

		thumbsDiv.innerHTML += placePhotoThumb(photo.source, photo.picture, photo.width, photo.height, photo.link, i);

	}


	if(i == (galleries.length - 1))
	{
		jQuery('#loadingDiv').fadeOut('500', function() { setLightbox(); jQuery('#galleries').fadeIn('500') });
	}

}

function setLightbox()
{
	jQuery('#photoDiv #photoHolder').each(function() {
		 jQuery('a.lightbox', $(this)).lightBox();
	});
}

function placePhotoThumb(source, url, width, height, link, count)
{
	width = parseInt(width);
	height = parseInt(height);

	if(width >= height)
	{
		var diffW = width * (87 / height);
		var diffH = height * (87 / height);

	} else {
		var diffW = width * (87 / width);
		var diffH = height * (87 / width);
	}

	var y = (87 - diffH) / 2;
	var x = (87 - diffW) / 2;

	//var thumbdiv = document.getElementById(id);

	var thumb = '<div style="float:left"><div style="position: relative; width: 93px; height:  95px; background-color: transparent"><div style="position:absolute; top: 0px; left: 0px; width: 87px; height: 87px; clear: both"><a href="'+ source +'" class="lightbox"><div style="float: left; width: 87px; height: 87px; overflow: hidden; background-image: url('+ url +'); background-position: '+ x +' '+ y +'; background-repeat: no-repeat"></div></a></div>';
	thumb += '<div id="moreCommentsPhoto" style="margin: 0px 0px 0px 0px"><a href="'+ link +'" target="_blank"><img src="'+ root+'images/fb_small.png" border="0" /></a></div></div></div>';

	return thumb;

}



function trackPage(url, name, section)
{
	try {

			SME$Analytics.ajaxPageView( {pageURL: ""+ url +"", pageName: "" + name +"", siteSection: ""+ section +""});


	}catch(e){ }

}
