// JavaScript Document
$(document).ready(function() {
  
  /* RANDOM BG IMAGE */
  var randomImages = ['technolab-1','technolab-2'];
  var rndNum = Math.floor(Math.random() * randomImages.length);
  $("body").css({ background: "url('http://www.technolab.nl/uploads/technolab/img/bg/" + randomImages[rndNum] + ".jpg') center no-repeat fixed" }); /* BODY */

  /* RANDOM SIDE IMAGE */
  var randomImages = ['sideimg1','sideimg2','sideimg3'];
  var rndNum = Math.floor(Math.random() * randomImages.length);
  $("div#sideimg").css({ background: "url('http://www.technolab.nl/uploads/technolab/img/" + randomImages[rndNum] + ".jpg') right top no-repeat" }); /* SIDEIMG */
   
   
  /* ADD TEXT-SHADOW FOR IE */
  var myShadow = {
    x:      1, 
    y:      2, 
    radius: 3,
    color:  "#000"
  }
  $("div#pictureFrame h2").textShadow(myShadow);
  
  /* FLAG BUTTONS */
  $('img#dutchflag').hover(function() {
                $(this).stop().animate({ opacity: 1.0 }, 300);
            },
           function() {
               $(this).stop().animate({ opacity: 0.5 }, 500);
           });
  $('img#englishflag').hover(function() {
                $(this).stop().animate({ opacity: 1.0 }, 300);
            },
           function() {
               $(this).stop().animate({ opacity: 0.5 }, 500);
           });
  
  /* ANIMATE BACK TO TOP LINK */
  $('a.top').click(function(){
       $('html, body').animate({scrollTop: '0px'}, 600, 'swing');
       return false;
  });
  $('a.divtop').click(function(){
       $('#ct').animate({scrollTop: '0px'}, 600, 'swing');
       return false;
  });
  /* STYLE BLOG SUMMARY LINKS */
   $('div.CGBlogSummary').mouseover(function(){
		$(this).css("background-color","#efefef");
  });
  $("div.CGBlogSummary").mouseout(function(){
		$(this).css("background","transparent");
	});
	
 	//LOADING POPUP  
//Click the button event!  
	$("#button").click(function(){  
//centering with css  
		centerPopup();  
//load popup  
		loadPopup();  
	});  

//CLOSING POPUP  
//Click the x event!  
	$("#popupTableClose").click(function(){  
		disablePopup();  
	});  
//Click out event!  
	$("#backgroundPopup").click(function(){  
		disablePopup();  
	});  
//Press Escape event!  
	$(document).keypress(function(e){  
		if(e.keyCode==27 && popupStatus==1){  
		disablePopup();  
		}  
	}); 
	
});

//SETTING UP OUR POPUP  
//0 means disabled; 1 means enabled;  
var popupStatus = 0;  

//loading popup with jQuery magic!  
function loadPopup(){  
//loads popup only if it is disabled  
	if(popupStatus==0){  
		$("#backgroundPopup").css({  
			"opacity": "0.7"  
		});  
	$("#backgroundPopup").fadeIn("slow");  
	$("#popupTable").fadeIn("slow");  
		popupStatus = 1;  
	}  
}  

//disabling popup with jQuery magic!  
function disablePopup(){  
//disables popup only if it is enabled  
	if(popupStatus==1){  
		$("#backgroundPopup").fadeOut("slow");  
		$("#popupTable").fadeOut("slow");  
		popupStatus = 0;  
	}  
}  

//centering popup  
function centerPopup(){  
//request data for centering  
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = 620; 
	var popupWidth = 860;  
//centering  
	$("#popupTable").css({  
		"position": "absolute",  
		"top": 0,  
		"left": 0  
	});  
//only need force for IE6   
	$("#backgroundPopup").css({  
		"height": windowHeight  
	});  
  
}  
