/*campop*/
$jq(function () {
  if(readCookie("campopup")==null)
		SetupCamPop();
	
	$jq(window).resize(function(){
		if(checkCloseCamPopup == 0)
			Resize("#campopup");
	});
});

function SetupCamPop(){
	if(cammers!=null&&cammers.length>0){
		//.close -> onclick="CloseCamPopup();"

		$jq("#campopup").mouseover(function() {
			stopInterval();
			return false;
		});
		$jq("#campopup").mouseout(function() {
			if(checkCloseCamPopup == 0)
				redoInterval();
		});
		$jq("#campopup .close").click(function() {
			CloseCamPopup();
		});
		doInterval();
		// call it onload
		Place("#campopup");
		// assure that it gets called when the page resizes
  }
}

var repeatTimeout = null;
var theTimeout = null;
var checkCloseCamPopup = 0;

var upTime = 10000; //tijd dat de popup verschijnt
var downTime = 10000; //tijd dat de popup verdwijnt

var counter = 0;

doInterval = function(){
  if(counter>=cammers.length)
    counter = 0;
  $jq("#campopup a").each(function(e){
		$jq(this).attr("href",cammers[counter].link);
  });
  $jq("#campopup a.img").each(function(e){
		$jq(this).attr("title",cammers[counter].nick);
  });
	$jq("#campopup a.img img").each(function(e){
		$jq(this).attr("src",cammers[counter].img);
		$jq(this).attr("alt",cammers[counter].nick);
  });
	$jq("#campopup a.text").each(function(e){
		$jq(this).html(cammers[counter].text);
  });
  clearTimeout(theTimeout);
  theTimeout = setTimeout(function(){HideCamPopup();}, upTime);
  counter++;
};

redoInterval = function(){
  clearTimeout(theTimeout);
  theTimeout = setTimeout(function(){HideCamPopup();}, upTime);
};

stopInterval = function(){
  clearTimeout(theTimeout);
};

function Place(selector) {
  var newTop =   $jq(window).height() - $jq(selector).height();
  var newLeft =  $jq(window).width()  - $jq(selector).width();
  $jq(selector).css({
		'position': 'absolute',
		'left': newLeft,
		'top': $jq(window).height()
  });
  $jq(selector).animate({opacity: "show", top: newTop}, "slow");
}

function Resize(selector) {
  var newTop =   $jq(window).height() - $jq(selector).height();
  var newLeft =  $jq(window).width()  - $jq(selector).width();
  
  $jq(selector).css({
    'position': 'absolute',
    'left': newLeft,
    'top': newTop
  });
  
  $jq(selector).animate({opacity: "show", top: newTop}, "fast");
}

function HideCamPopup() {
  $jq("#campopup").animate({opacity: "hide", top: $jq(window).height()}, "slow");
  repeatTimeout = setTimeout("Repeat()", downTime);
}

function CloseCamPopup() {
  $jq("#campopup").animate({opacity: "hide", top: $jq(window).height()}, "fast");
  clearTimeout(repeatTimeout);
  clearTimeout(theTimeout);
  checkCloseCamPopup = 1;
  createCookie("campopup","closed",1);
}

function Repeat() {
  doInterval();
  Place("#campopup");
}

/*Cookies*/

function createCookie(name, value, days) {
  if(days==null||days==undefined)
		days = 365 * 50;
  var date = new Date();
  date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  var expires = "; expires=" + date.toGMTString();
  document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') c = c.substring(1, c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  }
  return null;
}

/*level 2 cookies*/

function eraseCookie(name){
	createCookie(name,null,-1);
}

function addCookie(name,value){
  var c=readCookie(name);
  if(c==null){
		createCookie(name,(value+","));
		return true;
	}
  else if(c.indexOf(",")>=0){
    var p = c.split(',');
    for(var i=0;i<p.length;i++){
      if(p[i]!=null && p[i] == value)
				return false;
    }
    c+=value+",";
    createCookie(name,c);
    return true;
  }
  else{
		c = value + ",";
    createCookie(name,c);
		return true;
	}
	return false;
}

function delCookie(name,value){
	var c = readCookie(name);
  if(c!=null){
    var p = c.split(',');
    var r = "";
    for(var i=0;i<p.length;i++){
      if(p[i]!=null && p[i] != '' && p[i]!=value)
				r+=p[i]+",";
    }
    if(r==c)
			return false;
    if(r.length>0)
			createCookie(name,r);
    else
			eraseCookie(name);
		return true;
  }
  return false;
}

function existsCookie(name,value){
	var c = readCookie(name);
  if(c==null)
		return false;
	else if(value==null || value == undefined)
		return true;
	else{
    var p = c.split(',');
    var r = "";
    for(var i=0;i<p.length;i++){
      if(p[i]!=null && p[i] == value)
				return true;
    }
  }
  return false;
}

var cookieEnabled = false;

function supportsCookie(){
	if(!cookieEnabled){
		createCookie("test", "test", 1);
		if(readCookie("test")=="test")
			cookieEnabled = true;
	}
	return cookieEnabled;
}


/*
var repeatTimeout = null;
var theTimeout = null;
var checkDefHide = 0;

var upTime = 6000; //tijd dat de popup verschijnt
var downTime = 12000; //tijd dat de popup verdwijnt

var counter = 0;

doInterval = function(){
  if(counter>=cammers.length)
    counter = 0;
  var img = document.getElementById(linkfoto);
  img.href = cammers[counter].link;
  img.title = cammers[counter].nick;
  img.firstChild.src = cammers[counter].img;
  img.firstChild.alt = cammers[counter].nick;
  var text = document.getElementById(linktext);
  text.innerHTML = cammers[counter].text;
  text.href = cammers[counter].link;

  var link = document.getElementById(linkknop);
  link.href = cammers[counter].link;

  clearTimeout(theTimeout);
  theTimeout = setTimeout(function(){Hide();}, upTime);
  counter++;
};

redoInterval = function(){
      clearTimeout(theTimeout);
      theTimeout = setTimeout(function(){Hide();}, upTime);
};

stopInterval = function(){
      clearTimeout(theTimeout);
};

$jq(document).ready(function()
{
    $jq("#popup").mouseover(function() {
          stopInterval();
          return false;
    });
    $jq("#popup").mouseout(function() {
          if(checkDefHide == 0)
            {
              redoInterval();
              //return false;
            }
          
    });
    
    doInterval();

  // call it onload
  Place("#popup");

  // assure that it gets called when the page resizes
  $jq(window).resize(function(){
      if(checkDefHide == 0)
        {
          Resize("#popup");
        }
  }); 
});

function Place(selector) {
    var newTop =   $jq(window).height() - $jq(selector).height();
    var newLeft =  $jq(window).width()  - $jq(selector).width();
    
    $jq(selector).css({
        'position': 'absolute',
        'left': newLeft,
        'top': $jq(window).height()
    });
    
    $jq("#popup").animate({opacity: "show", top: newTop}, "slow");
}

function Hide() {
  $jq("#popup").animate({opacity: "hide", top: $jq(window).height()}, "slow");
  
  repeatTimeout = setTimeout("Repeat()", downTime);
}

function HideDef() {
  $jq("#popup").animate({opacity: "hide", top: $jq(window).height()}, "fast");
  clearTimeout(repeatTimeout);
  clearTimeout(theTimeout);
  checkDefHide = 1;
}

function Repeat() {
  doInterval();
  Place("#popup");
}

function Resize(selector) {
    var newTop =   $jq(window).height() - $jq(selector).height();
    var newLeft =  $jq(window).width()  - $jq(selector).width();
    
    $jq(selector).css({
        'position': 'absolute',
        'left': newLeft,
        'top': newTop
    });
    
    $jq("#popup").animate({opacity: "show", top: newTop}, "fast");
}
*/