function getPermUrl(){
	var strPerm = "";
	//if we've got both ? and #, we'll need to tweak a bit
	if(window.location.toString().indexOf('?')>=0&&window.location.toString().indexOf('#')>=0){
		//get page
		mySplit1 = window.location.toString().split('?');
		strTemp1 = mySplit1[0];
		//get video
		mySplit2 = mySplit1[1].split('#');
		strTemp2 = mySplit2[1];
		//concat
		strPerm = strTemp1 + '?' + strTemp2;
	}
	//if we've already got ...?12345, we're probably ok
	else if(window.location.toString().indexOf('?')>=0){
		strPerm = window.location.toString();
	}
	//or we'll translate #12345 to ?12345
	else if(window.location.toString().indexOf('#')>=0){
		strPerm = window.location.toString().replace('#','?');
	}
	//otherwise, we're viewing the first in a playlist, append the title_id
	else {
		strPerm = window.location.toString() + '?' + title_id;
	}
	return encodeURIComponent(strPerm);
}

function getShareHeadline(){
	return encodeURIComponent(document.getElementById('VideoTitle').childNodes[0].innerHTML);
}

function getShareDescription(){
	return encodeURIComponent(document.getElementById('txtVideoDescription').innerHTML);
}

function videoShare(site) {
	var permLink = getPermUrl();
    var title = getShareHeadline();
    var description = getShareDescription();
	switch (site) {
	case "newsvine":
		sharePopUp('http://www.newsvine.com/_wine/save?popoff=1&u=' + permLink, 'newsvine', 'toolbar=0,status=0,height=445,width=720,scrollbars=yes,resizable=yes');
		//s_code_linktrack('Article-Tool-Share-Newsvine');
		break;
	case "facebook":
		sharePopUp('http://www.facebook.com/sharer.php?u=' + permLink, 'facebook', 'toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes');
		//s_code_linktrack('Article-Tool-Share-Facebook');
		break;
	case "digg":
		sharePopUp('http://digg.com/remote-submit?phase=2&url=' + permLink + '&title=' + title + '&bodytext=' + description + '&media=video&topic=environment', 'digg', 'toolbar=0,status=0,height=500,width=650,scrollbars=yes,resizable=yes');
		//s_code_linktrack('Article-Tool-Share-Digg');
		break;
	case "furl":
		sharePopUp('http://furl.net/storeIt.jsp?u=' + permLink + '&t=' + title, 'furl', '');
		break;
	case "reddit":
		sharePopUp('http://reddit.com/submit?url=' + permLink + '&title=' + title, 'reddit', '');
		break;
	case "stumbleupon":
		sharePopUp('http://www.stumbleupon.com/submit?url=' + permLink + '&title=' + title, 'stumbleupon', 'toolbar=0,status=0,height=450,width=720,scrollbars=yes,resizable=yes');
		break;
	case "permalink":
		sharePopUp('/LinkPop.aspx?url=' + permLink + '&title=' + title+ '&description=' + description, 'permalink', 'toolbar=0,status=0,height=480,width=490,scrollbars=yes,resizable=yes');
		//s_code_linktrack('Article-Tool-Share-Permalink');
		break;	
	case "delicious":
		sharePopUp('http://del.icio.us/post?v=4&noui&jump=close&url=' + permLink + '&title=' + title + '&bodytext=' + description, 'delicious', 'toolbar=0,status=0,height=400,width=700,scrollbars=yes,resizable=no');
		//s_code_linktrack('Article-Tool-Share-Delicious');
		break;			
	}
}

function sharePopUp(url, name, params) {
	var win = window.open(url, name, params);
}

function switchTab(el,box) {
	//turn off all tabs
	var container = document.getElementById('TabsBox');
	for (i=0;i<container.childNodes.length;i++) {
		container.childNodes[i].className = "inactive";
	}
	//activate requested tab
	document.getElementById(el).className = "active";
	//hide boxes
	document.getElementById('VideoBox').className = "hide";
	document.getElementById('ShareBox').className = "hide";
	//display requested box
	document.getElementById(box).className = "show";
}

function addShareEvents() {
	var parentEl = document.getElementById("ShareBox");
	for (i=0;i<parentEl.childNodes.length;i++) {
		currEl = parentEl.childNodes[i];
		if (currEl.tagName == "DIV") {
			//get the classname
			currId = currEl.id;
			//use it to create an appropriate function
			myFunc = "switchInfo(\"" + currId + "\")";
			//attach the function to the mouseover event
			currEl.onClick = "switchInfo(\"" + currId + "\")";
		}
	}
}

function switchInfo(el) {
	//update info text
	document.getElementById('shareInfoDesc').innerHTML = getInfoText(el);
}

function getInfoText(el) {
	switch(el) {
		case "facebook":
			return "<b>Facebook</b> is a social utility that connects people with friends and others who work, study and live around them. People use Facebook to keep up with friends, upload an unlimited number of photos, share links and videos, and learn more about the people they meet.";
			break;
		case "newsvine":
			return "At <b>Newsvine</b>, you can read stories from established media organizations as well as individual contributors from all around the world. Placement of stories is determined by a multitude of factors including freshness, popularity, and reputation. Contribution is open to all, and editorial judgement is in the hands of the community.";
			break;
		case "delicious":
			return "On <b>del.icio.us</b>, you can use tags to organize and remember your bookmarks. You can also see the interesting links that your friends and other people bookmark, and share links with them in return. You can even browse and search del.icio.us to discover the cool and useful bookmarks that everyone else has saved.";
			break;
		case "furl":
			return "<b>Furl</b> saves the important items you find on the Web and enables you to quickly find them again. When you want to recall it, you can find it instantly by searching the full text your archived items. Furl also offers the best ways to share the content you find on the Web.";
			break;
		case "digg":
			return "<b>Digg</b> is a place for people to discover and share content from anywhere on the web. Once something is submitted, other people see it and Digg what they like best. If your submission rocks and receives enough Diggs, it is promoted to the front page for the millions of our visitors to see.";
			break;
		case "reddit":
			return "<b>Reddit</b> is a source for what's new and popular on the web -- personalized for you. All of the content on reddit is from users who are rewarded for good submissions (and punished for bad ones) by their peers; you decide what appears on your front page and which submissions rise to fame or fall into obscurity.";
			break;
		case "stumbleupon":
			return "<b>StumbleUpon</b> helps you discover and share great websites. These pages have been explicitly recommended by your friends or one of millions of other websurfers with interests similar to you. Rating these sites you like automatically shares them with like-minded people – and helps you discover great sites your friends recommend.";
			break;
		case "permalink":
			return "A <b>permalink</b> is a URL that points to a specific Web item. Because a permalink remains unchanged indefinitely, it is less susceptible to link rot. Most modern weblogging and content-syndication software systems support such links. Permalink is a portmanteau word made from permanent link.";
			break;
	}
}

function nextObject(o) {
	var n = o;alert(o);
	do {n = n.nextSibling;}
	while (n && n.nodeType != 1);
	return n;
}

function previousObject() {
	var p = this;
	do p = p.previousSibling;
	while (p && p.nodeType != 1);
	return p;
}
