var getNum = 1 ; 
var overlaysOnScreen = 0; 

/*
function DivOverlay(pos_x, pos_y, text, divIdName) {
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'overlay' + divIdName);
	$(newdiv).addClass('overlay').css({'left': pos_x+'px', 'top': pos_y+'px'}).html(text);
	$('#videostream').append(newdiv);
}
*/

function DivOverlay(pos_x, pos_y, text, divIdName, newWindow, orientation) {
    
	point = new Array(); 
	point= ajustPosition(pos_x, pos_y, orientation);
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'overlay' + divIdName);
	//$(newdiv).addClass('overlay').css({'left': pos_x+'px', 'top': pos_y+'px'}).html(text);
	$(newdiv).addClass('overlay').css({ 'left': point[0] + 'px', 'top': point[1] + 'px' }).html(text);
	$('#videostream').append(newdiv);
}

function ajustPosition( pos_x , pos_y, orientation){
position = new Array(); 
	if(orientation == "bottomLeft")
		{
			position[0] = pos_x; 
			position[1] = pos_y -50;
		return position;
		}else if( orientation == "topRight")
		{
			position[0] = pos_x - 150;
			position[1] = pos_y ;
		return position;
		}else if( orientation == "bottomRight")
		{
			position[0] = pos_x - 150;
	        position[1] = pos_y -50;
    	return position;
		}else{
			position[0] = pos_x;
			position[1] = pos_y
			return position; 
		}
}

function DivOverlayMain(text) {
	var newdiv = document.createElement('div');
	$(newdiv).addClass('overlay-main').html(text);
	$('#videostream').append(newdiv);
}

function removeElement(divNum) {
	  var d = document.getElementById('videostream');
	  var olddiv = document.getElementById('overlay' + divNum);
	  d.removeChild(olddiv);
	}

function RemoveOverlays(){
	  for( var i = 0 ; i < overlaysOnScreen ; i++){
		  removeElement(i);
		  }
}

function GenerateInnerHtmlMain(title, topCopy, topLinkCopy, topLinkUrl, bottomCopy, bottomLinkCopy, bottomLinkUlr) {
	var string = new String();
	string = "<br><div class=\"h7\">" + title + "</div><br>";
	string = string + "<div class=\"h8\">" + topCopy + "</div><br>";
	string = string + "<a href=" + topLinkUrl + ">" + topLinkCopy + "</a><br><br>";
	string = string + "<div class=\"h9\">" + bottomCopy + "</h9><br><br>";
	string = string + "<a href=" + bottomLinkUrl + ">" + bottomLinkCopy + "</a><br><br>";
	return string;
}

function GenerateInnerHtmlOverlay(title, copy, linktext, link, openIn) {
	var string = new String();
	string = string + "<div class=\"h10\">" + title + "</h10>";
	string = string + "<div class=\"h10\">" + copy +  "</h10><br>";
	if(openIn == "newWindow"){
	    string = string + "<a href=" + link + " target=\"_blank\"><font face=\"helvetica, georgia, courier, arial\" size=\"2\" >" + linktext + "</font></a>";
	} else {
		string = string +"<a href=" + link + "><font face=\"helvetica, georgia, courier, arial\" size=\"2\" >" + linktext + "</font></a>";
	}
	return string; 
}

function loadXMLDoc(dname) {
	var xhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
	xhttp.open('GET', dname, false);
	xhttp.send();
	return xhttp.responseXML;
}
	
function loadXMLString(txt) {
	if (window.DOMParser) {
		parser = new DOMParser();
		xmlDoc = parser.parseFromString(txt, 'text/xml');
	} else {
		// IE Only
		xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
		xmlDoc.async = 'false';
		xmlDoc.loadXML(txt);
	}
	return xmlDoc;
}

function CreateOverlays() { CreateOverlays( false )};
function CreateOverlays(NY) {
	if(!NY)
		{
			xml = loadXMLDoc('xml/hotspots.xml');
		}else{
			xml = loadXMLDoc('xml/hotspotsNY.xml');
		}
	//title = xml.getElementsByTagName('top')[0].getAttribute('title');
	
	copy		= new Array();
	links		= new Array();
	popupx		= new Array();
	popupy		= new Array();
	orient		= new Array();
	linkText	= new Array();
	copyDate	= new Array();
	copyTitle	= new Array();
	openIn		= new Array();
	var hotspots= xml.getElementsByTagName("hotspot");
	var count = 0; 
      for ( var i = 0; i < hotspots.length ; i++ )
      {
          count++;           
      }
      
    var hotspotElement;
    var popupElement;
	for (i = 0; i < count; i++) {
		hotspotElement = xml.getElementsByTagName("hotspot")[i];
		
			copy[i] = xml.getElementsByTagName("copy")[i].childNodes[0].nodeValue;
			links[i] = xml.getElementsByTagName("link")[i].childNodes[0].nodeValue;
			popupElement = hotspotElement.getElementsByTagName("popup")[0];
			popupx[i] = xml.getElementsByTagName("popup")[i].getAttribute("x");
			popupy[i] = xml.getElementsByTagName("popup")[i].getAttribute("y");
			orient[i] = popupElement.getAttribute("orientation");
			linkText[i] = xml.getElementsByTagName("link")[i].getAttribute("text");
			copyDate[i] = xml.getElementsByTagName("copy")[ i].getAttribute("cta");
			copyTitle[i] = xml.getElementsByTagName("copy")[ i].getAttribute("title");
			openIn[i] = xml.getElementsByTagName("link")[i].getAttribute("openIn");
	}

	for( i = 0; i< count; i++)
		{
		DivOverlay(popupx[i], popupy[i], GenerateInnerHtmlOverlay(copyTitle[i], copy[i], copyDate[i], links[i], openIn[i]), i, openIn[i],orient[i] );
		}

	overlaysOnScreen = count ; 
} 



function GetTweet()
{
	var TweetAr = new Array();
	TweetAr[0] =  GetTweetText();
	TweetAr[1] =  GetTweetDate();
 	TweetAr[2] =  GetTweetLocation();
return TweetAr; 
}
function GetTweetText()
	{
		if( Tweet1){
			getNum = 0;
			return Tweet1;
		}else{
			return  "The Partners have been terribly busy recently so we haven't had a chance to Tweet. We will sort it out soon We Promise!";
		}
	}
function GetTweetDate(){
	
	var d = ($.format.date( created_at1, "MM"));
	      if(d = "01"){
		var mm = "Jan";
	}else if(d = "02"){
		var mm = "Feb";
	}else if(d = "03"){
		var mm = "Mar";
	}else if(d = "04"){
		var mm = "Apr";
	}else if(d = "05"){
		var mm = "May";
	}else if(d = "06"){
		var mm = "Jun";
	}else if(d = "07"){	
		var mm = "Jul";
	}else if(d = "08"){
		var mm = "Aug";
	}else if(d = "09"){
		var mm = "Sep";
	}else if(d = "10"){
		var mm = "Oct";
	}else if(d = "11"){
		var mm = "Nov";
	}else{
		var mm = "Dec";
	}
		if( getNum == 0)
		{  
			return ($.format.date( created_at1, "hh:mm a dd ") +( mm )) ;
		}else 
		{
			return " ";
		}
	}
function GetTweetLocation(){
		if( getNum == 0)
		{ 
			return Tlocation1;
		}else{
			return " ";
			}
		}

function PassVarsToFlash(){
var swf = swfobject.getObjectById("videostream");
swf.addVariable("variable3", "value3"); 
}

function goUK(){
	//htmlstream =  "<img id=\"thumbnail\" src=\"http://thumbnail.api.livestream.com/thumbnail?name=thepartners\" alt=\"\"  width=\"960\" height=\"450\" />;"
	var flash = swfobject.getObjectById('videostream');
if(flash){
	flash.ukStream();
}else{
	RemoveOverlays();
	CreateOverlays(false);
		UKfeed = setInterval(function(){$('#thumbnail').attr('src', 'http://thumbnail.api.livestream.com/thumbnail?name=thepartners&1'+new Date().valueOf())}, 3500);
		//}
	//htmlstream =  "<img id=\"thumbnail\" src=\"http://thumbnail.api.livestream.com/thumbnail?name=thepartners\" alt=\"\"  width=\"960\" height=\"450\" />;"
	clearInterval(USfeed);
		//setInterval(function(){$('#thumbnail').attr('src', 'http://thumbnail.api.livestream.com/thumbnail?name=thepartners&1'+new Date().valueOf())}, 3500);
	setInterval("UKfeed", 5000);
}
}
function goNY(){	
	var flash = swfobject.getObjectById('videostream');
	//USfeed = setInterval(function(){$('#thumbnail').attr('src', 'http://thumbnail.api.livestream.com/thumbnail?name=thepartnersny&1'+new Date().valueOf())}, 1);
	//setInterval("UKfeed", 3500);
	if(flash){
	flash.usaStream();
	}else{
		RemoveOverlays();
		CreateOverlays(true);
		clearInterval(UKfeed);
			USfeed = setInterval(function(){$('#thumbnail').attr('src', 'http://thumbnail.api.livestream.com/thumbnail?name=thepartnersny&1'+new Date().valueOf())}, 3500);
//		htmlstream =  "<img id=\"thumbnail\" src=\"http://thumbnail.api.livestream.com/thumbnail?name=thepartnersny\" alt=\"\"  width=\"960\" height=\"450\" />;"
		setInterval("USfeed", 5000);	
	}
}

