// This function is able to open the RZ newsticker in a popup window and is suggested to be used in a "href" attribute within an <a>-element.
function openNewsticker(newstickerUrl, messageIndex)
{
	if (messageIndex<0||isNaN(messageIndex)) messageIndex='';
	window.open(
		newstickerUrl,
		'rzNewsticker',
		'resizable=yes,scrollbars=yes,directories=no,toolbar=no,status=no,location=no,width=610,height=515,left=100,top=100'
	);
	return false;
}

/* This function starts a countdown */
function startCountdown(id, endTime)
{
	var spanContainer = $('#microsite_countdown_'+id);
	var spanDay = spanContainer.find('span[type="day"]');
	var spanHour = spanContainer.find('span[type="hour"]');
	var spanMin = spanContainer.find('span[type="minute"]');
	var spanSec = spanContainer.find('span[type="second"]');
	
	var countdown = function()
	{
		curTime = new Date();
		diffTime = endTime - curTime;
		if (diffTime > 0)
		{
			diffTime = Math.floor(diffTime/1000);
			
			valDays = Math.floor(diffTime/86400);
			if (valDays < 10) valDays = '0' + valDays;
			diffTime %= 86400;
			
			valHours = Math.floor(diffTime/3600);
			if (valHours < 10) valHours = '0' + valHours;
			diffTime %= 3600;
			
			valMinutes = Math.floor(diffTime/60);
			if (valMinutes < 10) valMinutes = '0' + valMinutes;
			diffTime %= 60;
			
			valSeconds = diffTime;
			if (valSeconds < 10) valSeconds = '0' + valSeconds;
		} 
		else 
		{
			valDays = valHours = valMinutes = valSeconds = '00';
			window.clearInterval(runCountdown);
		}
	
		spanDay.html(valDays);	
		spanHour.html(valHours);	
		spanMin.html(valMinutes);	
		spanSec.html(valSeconds);	
	}
	
	var runCountdown = window.setInterval(countdown, 500);
}

function showHideLayerAdvert() {
  var i,p,v,obj,args=showHideLayerAdvert.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}

function toggleDisplay(id) {
	var obj = MM_findObj(id);
	if (obj != null) {
		if (obj.style.display == 'none') { 
			obj.style.display = 'block'; 
		} else if (obj.style.display == 'block') {
			obj.style.display = 'none';
		}
	}
}


function share(hoster, mmid)
{		
	var url = document.location.toString();
	var title = document.title;
	var description = $('meta[name=description]').attr('content');
	var mediaImage = $('#articledetailimages li:first img').attr('src');
	
	var hosterServices = new Object();
	hosterServices['myspace'] 		= 'http://www.myspace.com/Modules/PostTo/Pages/?u='+encodeURIComponent(url);
	hosterServices['meinvz'] 		= 'http://www.meinvz.net/Link/Selection/Url/?u='+encodeURIComponent(url)+'&desc='+encodeURIComponent(title);
	hosterServices['google'] 		= 'http://www.google.com/bookmarks/mark?op=add&hl=en&bkmk='+encodeURIComponent(url)+'&title='+encodeURIComponent(title);
	hosterServices['reddit'] 		= 'http://reddit.com/submit?url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title);
	hosterServices['digg'] 			= 'http://digg.com/submit?url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title);
	hosterServices['delicious'] 	= 'http://www.delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title);
	hosterServices['misterwong'] 	= 'http://www.mister-wong.de/index.php?action=addurl&bm_url='+encodeURIComponent(url)+'&bm_description='+encodeURIComponent(title);
	hosterServices['twitter']       = 'http://twitter.com/share?url='+encodeURIComponent(document.location)+'&amp;text='+encodeURIComponent(document.title);
	
	fbUrl = document.location;
	if ( url.indexOf('mmid') == -1 )
	{
		fbUrl += '&mmid='+mmid;		
	}
	
	hosterServices['fb']            = 'http://www.facebook.com/sharer.php?u='+encodeURIComponent(fbUrl)+'&amp;title='+encodeURIComponent(document.title);

	if (hoster == 'facebook') {		
		var attachment = {
			name: title,
			href: url,
			caption: description	
		};
		
		if (mediaImage != null) {
			attachment["media"] =  [{
				type: "image",
				src: mediaImage,
				href: url
			}];
		} else if (typeof(flvObj) != "undefined") {
			attachment["media"] =  [{
				type: "flash",
				swfsrc: "http://" + document.location.host + flvObj.variables.file,
				imgsrc: "http://" + document.location.host + flvObj.variables.image,
				width: 80,
				heigth: 60,
				expanded_width: 480,
				expanded_height: 320
			}];
		}
		
		FB.ui({	method: "stream.publish", attachment: attachment}, fbCallback);		
	} else {
		window.open(hosterServices[hoster]).focus();
	}
	
	return false;
}
