//Ticker related
var ticker;
var ticker_content;
var ticker_righttoleft = false;
var speed = 1;
var style = "font-family:Arial; font-size:12px; color:#444444";
var paused = false;
var tickerSupported = false;
var tickerCount = 0;
var ie6 = (document.all && !window.opera && !window.XMLHttpRequest) ? true : false;

//Resize function related
var width;
var height;
var body, wrapper;

window.onresize = function (evt) {
    setWrapper();
}

function init() {
    body = document.getElementsByTagName('body')[0];
    wrapper = document.getElementById("wrapper");
    
    setWrapper();
    
    ticker = document.getElementById("rssticker");
    ticker_content = ticker.innerHTML;
    ticker_width = ticker.style.width;

    // Firefox/Safari/Opera
    if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1 || navigator.userAgent.indexOf("Opera")!=-1) {
        ticker.innerHTML = "<table cellspacing='0' cellpadding='0' width='100%'><tr><td nowrap='nowrapspanSPAN style='"+style+"' id='TICKER_BODY' width='100%'>&nbsp;</span></td></tr></table>";
        tickerSupported = true;
    }
    // IE
    if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {
        ticker.innerHTML = "<div style='width:100%'><span style='"+style+"' id='TICKER_BODY' width='100%'></span></div>";
        tickerSupported = true;
    }
    if(!tickerSupported) ticker.outerHTML = ""; else {
        ticker.scrollLeft = ticker_righttoleft ? ticker.scrollWidth - ticker.offsetWidth : 0;
        document.getElementById("TICKER_BODY").innerHTML = ticker_content;
        ticker.style.display="block";
        ticker_tick();
    }
}

function ticker_tick() {
    if(++tickerCount == 3){
        if(!paused) ticker.scrollLeft += speed * (ticker_righttoleft ? -1 : 1);
        if(ticker_righttoleft && ticker.scrollLeft <= 0) ticker.scrollLeft = ticker.scrollWidth - ticker.offsetWidth;
        if(!ticker_righttoleft && ticker.scrollLeft >= ticker.scrollWidth - ticker.offsetWidth) ticker.scrollLeft = 0;
        tickerCount = 0;
    }
    window.setTimeout("ticker_tick()", 10);
}

function swapRSS(element){
    if(element.className == "swapRSSOff"){
        element.className = "swapRSSOn";
        ticker.style.display = "none";
    }
    else {
        ticker.style.display = "block";
        element.className = "swapRSSOff";
    }
}

function removeRSS(){
    document.getElementById("removeRSS").style.display = "none";
    document.getElementById("addRSS").style.display = "block";
}

function addRSS(){
    document.getElementById("removeRSS").style.display = "block";
    document.getElementById("addRSS").style.display = "none";
}

function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=660,height=500,left = 192,top = 144');");
}

function setWrapper(){
    getSize();
    if(height < 700){
        wrapper.className = "wrapper";
        //document.getElementById("content").style.height = height + "px";
        body.style.overflowY = "scroll";
    }
    else {
        wrapper.className = "wrapperVCenter";
        body.style.overflowY = "hidden";
    }
} 

function getSize() {
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        width = window.innerWidth;
        height = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        width = document.documentElement.clientWidth;
        height = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }
}


$(document).ready(function(){
   if(ie6){ $("#content").pngFix(); alert('ie6');}
   $("a.fancyPortfolio").fancybox({hideOnContentClick:false}); 
   $("a.fancyBergselaan").fancybox({hideOnContentClick:false}); 
   
   //Extend onclick of fancy a's to set the apropriate dimensions
   $("a.fancyPortfolio").click(function(){
     dimensions = $(this).attr("name").split(" ");
     fancyWidth  = parseInt(dimensions[0]), fancyHeight = parseInt(dimensions[1]);
     $("#fancy_outer").css({'width': (fancyWidth + 20) + 'px', 'height': (fancyHeight + 20) + 'px'});
     //Reposition fancybox to be centered
     $("#fancy_outer").css({'left': ((width / 2) - ((fancyWidth + 20) / 2))  + 'px', 'top': ((height / 2) - ((fancyHeight + 20) / 2)) + 'px'});
     $("#fancy_outer iframe").css({'width': fancyWidth + 'px', 'height': fancyHeight + 'px'});
   });
}); 