/*
	Default Javascript functionality
	Burson-Marsteller EMEA
	2010 – mhm – http://crossmedia.b-m.ch/
*/


var themepath;

function appendCSS(filepath){
	if(filepath&&document.getElementsByTagName&&document.createElement){
		var headID 		= document.getElementsByTagName("head")[0];         
		var cssNode 	= document.createElement('link');
		cssNode.type 	= 'text/css';
		cssNode.rel		= 'stylesheet';
		cssNode.href 	= filepath;
		//cssNode.media = 'screen';
		headID.appendChild(cssNode);
	}
}

showNetwork=function(){
	Shadowbox.open({
		content:document.getElementById("network").innerHTML,
		player:	"html",
		width:	960,
		height:	647
	});
	return false;
}

SocialMediaBox={
	sidebar_active:null,
	smb_holder:"smb_holder",
	init:function(container){
		appendCSS(themepath+'/socialmediabox.css');
		this.smb_holder=$(this.smb_holder);
		if($$(container)){
			this.container=container;
			//CMLIB.Prototype_extend();
			$$(this.container+' a.smb').each(function(link){
				Element.extend(link);
				link.onclick=function(){this.blur();SocialMediaBox.getSidebar(this.title.toLowerCase());return false}
			});
			//CMLIB.external_links();
		}else{
			alert(container+" does not exist!")
		}
	},
	getSidebar:function(service){
		if(this.smb_holder!=null){
			this.smb_holder.update();
			this.smb_holder.className='';
			this.service=service;
			new Ajax.Request("/wp-content/themes/emea/bm-talk.inc.php?service="+service+"&rn="+(1+Math.floor(Math.random()*9999999)),{
				method:"get",
				onSuccess:function(transport){
					SocialMediaBox.smb_holder.update(transport.responseText);
					$$(SocialMediaBox.container+" a.smb").each(function(link){link.removeClassName("act")});
					$$(SocialMediaBox.container+" a.smb."+SocialMediaBox.service)[0].addClassName("act");
					SocialMediaBox.smb_holder.className=SocialMediaBox.service;
					$$(SocialMediaBox.container+" a").each(function(link){
						if(link.href.indexOf("&autoplay=1")>-1){link.rel="shadowbox;width=640;height=480;player=swf";$(link).addClassName('autoplay')}
					});
				setLinkTargets();
				setAutoplay();
				},
				onFailure:function(transport){
					SocialMediaBox.smb_holder.update("Fehler! Die gewünschten Daten konnten nicht geladen werden. Bitte versuchen Sie es noch einmal.");
					$$(SocialMediaBox.container+" a.smb").each(function(link){link.removeClassName("act")});
					$$(SocialMediaBox.container+" a.smb."+SocialMediaBox.service)[0].addClassName("act");
					SocialMediaBox.smb_holder.className="fail";
				}
			});
		}
	}
}

equalize_height=function(elements){

	var default_height=0;
	$$(elements).each(function(elm){
		if(elm.offsetHeight>default_height){default_height=elm.offsetHeight}
	});
	
	$$(elements).each(function(elm){
		elm.style.height=default_height+"px";
	});

}