var happyNewsHeight = 300;

document.getElementsByClassName = function (needle)
{
    var s = [document.documentElement || document.body], i = 0, r = [], l = 0, e;
    var re = new RegExp('(^|\\s)' + needle + '(\\s|$)');

    do
    {
        e = s[i];
        while (e)
        {
            if (e.nodeType == 1)
            {
                if (e.className && re.test(e.className)) r[l++] = e;
                s[i++] = e.firstChild;
            }
            e = e.nextSibling;
        }
    }
    while (i--);
    return r;
}

function setActivePhotoNum(elm){
	
	var allnums = document.getElementsByClassName('photonum');
	
	for ( var i=0;i<allnums.length;i++ ) {
		allnums[i].className='photonum';
	}
	
	elm.className='photonum active';
	
	return false;
}

function setBodyHeight(){
	var viewportwidth;
	var viewportheight;
	if (typeof window.innerWidth != 'undefined')
	{
	viewportwidth = window.innerWidth,
	viewportheight = window.innerHeight
	}
	else if (typeof document.documentElement != 'undefined'
	&& typeof document.documentElement.clientWidth !=
	'undefined' && document.documentElement.clientWidth != 0)
	{
	viewportwidth = document.documentElement.clientWidth,
	viewportheight = document.documentElement.clientHeight
	}
	else
	{
	viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}

	document.getElementById('content_container').style.height = viewportheight-75-1-26+'px';
}
window.onload = setBodyHeight;
window.onresize = setBodyHeight;
/*
function toggleHappyNews(){
	var container = document.getElementById('footer_happy_news_content');
	if ( container.style.height == happyNewsHeight+'px' ) {
		slideDiv('footer_happy_news_content', happyNewsHeight, 0, happyNewsHeight, "document.getElementById('footer_happy_news_button').style.backgroundImage='url(/images/arrow_up.jpg)';");
	} else {
		slideDiv('footer_happy_news_content', 0, happyNewsHeight, 0, "document.getElementById('footer_happy_news_button').style.backgroundImage='url(/images/arrow_down.jpg)';");
	}
}

function slideDiv(elmid, from, to, curr, finishfunct){

	var speed = 10;
	var timeout = 20;

	var elm = document.getElementById(elmid);
	var curHeight = elm.style.height?elm.style.height:'0px';

	if ( from > to ) {
		if ( curr <= to ) {
			elm.style.height = '0px';
			eval(finishfunct);
		} else {
			elm.style.height = (curr-speed)+'px';
			setTimeout("slideDiv('"+elmid+"', "+from+", "+to+", "+(curr-speed)+", \""+finishfunct+"\");", timeout);	
		}
	} else {
		if ( curr >= to ) {
			elm.style.height = to+'px';
			eval(finishfunct);
		} else {
			elm.style.height = (curr+speed)+'px';
			setTimeout("slideDiv('"+elmid+"', "+from+", "+to+", "+(curr+speed)+", \""+finishfunct+"\");", timeout);	
		}
	}
}
*/

function setBigImage(url, type){
	if ( type == 'mp3' ) {
		
		var irandom = Math.round(Math.random()*1234);
		irandom=120;
		
		document.getElementById('brands_large_thumb').innerHTML = '<div id="randomplayer'+irandom+'" style="position:absolute;bottom:0;left:0;width:501px;height:20px;">HOI!!!!!!!!!</div>';
		   var sor = new SWFObject("/player.swf", "mymovie"+irandom, "501", "20", "9", "#ffffff");
		   //sor.addParam("wmode", "transparent");
		   sor.addParam("flashvars","file="+url.replace("&amp;", "&"));
		   sor.write("randomplayer"+irandom);
		document.getElementById('brands_large_thumb').style.backgroundImage='url(/images/mp3back.jpg)';
	} else {
		document.getElementById('brands_large_thumb').innerHTML = '&nbsp;';
		document.getElementById('brands_large_thumb').style.backgroundImage='url('+url+')';
	}
}

window.addEvent('domready', function(){
	hideSharepopup();
	if ( $('footer_happy_news_content') ) {
	newsheight=$('footer_happy_news_content').offsetHeight;
	}
	
	$$('a[rel=external]').each(function(el){el.setAttribute('target','_blank');});
});


function showSharepopup(){
	$('share_popup').setStyle('display','block');
	$('share_popup_back').setStyle('display','block');
	$('share_popup').fade('in');
	$('share_popup_back').fade('0.7');
}

function hideSharepopup(){
	$('share_popup').fade('out');
	$('share_popup_back').fade('out');
	$('share_popup').setStyle('display','none');
	$('share_popup_back').setStyle('display','none');
}

var newsstate=true;
var newsheight=0;

function toggleHappyNews(){
	var myFx = new Fx.Tween($('footer_happy_news_content'));
	if ( newsstate ) {
		myFx.start('height', newsheight+'px', '0');
		newsstate=false;
		$('footer_happy_news_button').setStyle('background-image','url(/images/arrow_down.jpg)');
	} else {
		myFx.start('height', '0', newsheight+'px');
		newsstate=true;
		$('footer_happy_news_button').setStyle('background-image','url(/images/arrow_up.jpg)');
	}
}

function check_dobberen_code(cod){
	var req = new Request.JSON({url:'/ajax.php', 
		onSuccess: function(jsonObj) {
			if ( jsonObj.msg == 'ok') {
				location.href='/dobberen_welkom.html';
			} else {
				alert(jsonObj.msg);
			}
		},
		onFailure: function() {
			
		}
	}).post({'action':'check_dobberen_code', 'code':cod});
}