
$D = YAHOO.util.Dom;
$ = $D.get;

fixFooter = function(){
	
	var h = $D.getViewportHeight();

	var r = $D.getRegion(document.getElementsByTagName('body')[0]);
		
	var bodyHeight = r.bottom - r.top;
	
	var viewportHeight = $D.getViewportHeight();
	
	if (bodyHeight < viewportHeight){
		
		var n = viewportHeight - bodyHeight + 170;
	
		$D.setStyle('ft', 'height', n + 'px');
	
	}else{
		
		$D.setStyle('ft', 'height', '170px');
		
	}
	
}

var currentBox = 1;
var timeoutBox;

showHomePanel = function (num){
    if(!num){
        num = currentBox+1;
    }
    if(num>5 || num<0){
        num = 1;
    }
    window.clearTimeout(timeoutBox);
    for(var i=1; i<6; i++){
        var b = $("box-"+i);
        var m = $("item-"+i);
        if(i == num){
            b.style.display = "block";
            m.className = "selected";
        }else{
            b.style.display = "none";
            m.className = "";
        }
    }
    currentBox = num;
    timeoutBox = window.setTimeout(showHomePanel, 5000);
}

YAHOO.util.Event.onDOMReady(function(){
	
	var els = $D.getElementsByClassName('newwin', 'a');
	
	for (var i = 0; i < els.length; i++){
		
		els[i].target = '_blank';
		
		fixFooter();

        timeoutBox = window.setTimeout(showHomePanel, 5000);
	}
	
	YAHOO.util.Event.on(window, 'resize', fixFooter);

        $D.get('credits').getElementsByTagName('a')[0].target = '_blank';

	//new win for launching activities

        els = $D.getElementsByClassName('launch-activity', 'a');

	for (var a = 0; a < els.length; a++){
            YAHOO.util.Event.on(els[a], 'click', launchActivity);
	}
					  
});
/*
YAHOO.util.Event.on('launch-timer', 'click', function(e){
    var $E = YAHOO.util.Event;

    $E.stopEvent(e);
    var href = $E.getTarget(e).href;

    var w = 1008;
    var h = 76;

    var features = 'resizable=no,scrollbars=no,location=no,width=' + w + ',height=' + h;
    window.open(href, 'timer', features);
});
*/

launchActivity = function(e) {

    var $E = YAHOO.util.Event;

    $E.stopEvent(e);
    var href = $E.getTarget(e).href;

    if(href == undefined || href.toString().substr(href.toString().length-3, 3) == 'png'){
        href = $E.getTarget(e).parentNode.href;
    }
    //console.log(href);

    var features = '';//resizable=no,scrollbars=no,location=no,width=' + w + ',height=' + h;
    if (parent.location.href==window.location.href){
        window.open(href, 'activity', features);
    }else{
        window.open("/activities/countdown/frameset.php?page="+href, 'activity', features);
    }

};
