var pageLoc = window.location.pathname.substr(window.location.pathname.indexOf('/')+2); 
var pageTitle = document.title;

/*
var addthis_config = {
	username: "capellavc"
}
//Set the url and title for share elements
var addthis_share = {
	url: pageLoc,
	title: pageTitle
}*/
function popupEmailThisPage(url,height,width){
	var H1Tag = "";
	url = url.replace("%20&%20","%20and%20");
	url = url.replace(" & ","%20and%20");
	if (url.indexOf("u=/") > -1){
		url = url.replace("u=/","u=http://www.capella.edu/");
	}
	popupPage("EmailThisPage",url + escape(H1Tag),630,575,'1','0','1');
}
	
	jQuery(document).ready(function(){
	cbItems=jQuery("a[class*='cbSize']");
	//console.log(cbItems);
	if (cbItems) {
		cbItems.each(function() {
			var allClasses = jQuery(this).attr("class");
		//	console.log(allClasses);
			allClasses = allClasses.substring(allClasses.indexOf("cbSize"), allClasses.length);  //  chop off everything before cbSize
		//	console.log(allClasses);
			if (allClasses.indexOf(" ") != -1) allClasses = allClasses.substring(0, allClasses.indexOf(" "));  //  if anything after, chop it off too
		//	console.log("final: "+allClasses);
			cboxWidth = allClasses.replace("cbSize", "").split("x")[0];  //  remove "cbSize" then slit numbers into array, grab first number
			cboxHeight = allClasses.replace("cbSize", "").split("x")[1];  //  remove "cbSize" then slit numbers into array, grab second number
		//	console.log(cboxWidth);
		//	console.log(cboxHeight);
		//	if (!jQuery(this).attr("id")) jQuery(this).attr("id", "cb_" + cbNum);
			jQuery(this).colorbox({width:cboxWidth, height:cboxHeight, iframe:true, scrolling:false, 
			onCleanup:function(){  
				window.frames[0].document.getElementById('videoContainer').style.display="none"; //Gets rid of video quickly to correct IE lag time
			}
			}, function(){
				//jQuery('#btn_email a')[0].focus(); //Focus starts on video on colorbox expand.
			})/*.click(function() {
				jQuery("#colorbox #btn_email a").attr("href", "javascript:popupEmailThisPage('http://www.capella.edu/aspscripts/aspapps/Refer_a_Friend/refer_a_page.asp?EmailThisPage=Capella+University&u=" + pageLoc + ((jQuery(this).attr("id")) ? jQuery(this).attr("id") : "") + "&t=" + pageTitle + "','630','575');");
			});
			if (jQuery(this).attr("id")) addthis_share.url = pageLoc + "#" + jQuery(this).attr("id");*/
		});
	}
							 

	jQuery('<div id="cboxCloseCap"><a href="#" title="Close button">close</a></div>').appendTo('#cboxTopRight');
	jQuery('#cboxCloseCap').click(function(){
		//StopVideo();
		parent.jQuery.fn.colorbox.close();
		return false;
	}); 
	jQuery('#cboxCloseCap a').hover(
		function () {
			jQuery(this).css({'background-position':'0 -22px'});
		},
		function () {
			jQuery(this).css({'background-position':'0 0'});
		}
	).focus(
		function () {
			jQuery(this).css({'background-position':'0 -22px'});
		}
	).blur(
		function () {
			jQuery(this).css({'background-position':'0 0'});
		}
	);
		
	jQuery('<div id="btn_email"><a href="javascript:popupEmailThisPage(\'http://www.capella.edu/aspscripts/aspapps/Refer_a_Friend/refer_a_page.asp?EmailThisPage=Capella+University&u=' + pageLoc + '&t=' + pageTitle + '\',\'630\',\'575\');">email</a></div>').appendTo('#cboxTopCenter');
	/*jQuery('<div id="btn_share"><a onclick="return false" href="http://www.addthis.com/bookmark.php?v=250&amp;pub=capellavc" class="addthis_button">Share</a></div>').appendTo('#cboxTopCenter');
	*/
	jQuery('#btn_email a').hover(
		function () {
			jQuery(this).css({'background-position':'0 -23px'});
		},
		function () {
			jQuery(this).css({'background-position':'0 0'});
		}
	).focus(
		function () {
			jQuery(this).css({'background-position':'0 -23px'});
		}
	).blur(
		function () {
			jQuery(this).css({'background-position':'0 0'});
		}
	);	
	/*jQuery('#btn_share a').hover(
		function () {
			jQuery(this).css({'background-position':'0 -23px'});
		},
		function () {
			jQuery(this).css({'background-position':'0 0'});
		}
	).focus(
		function () {
			jQuery(this).css({'background-position':'0 -23px'});
		}
	).blur(
		function () {
			jQuery(this).css({'background-position':'0 0'});
		}
	);*/
});

	