// JavaScript Document


Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		
		if (this[i] === value) {
			
			return true;
		}
	}
	return false;
};


function pageNameIsUnique(pageName){
	
	if(pageNames.inArray(pageName)){
		return false;
	}
	return true;
	
	
}


/* -------------- PROMO BOX MOUSE OVER ACTIONS ------------------ */

$(document).ready(function() {
 //promoboxes mouseover
	$('#promoBoxes li a').hover( 
		function() { 
			$(this).stop()
		 	.animate({
				'backgroundColor':'#e5ecf3'
				//'opacity' :'1'	
				},200);
		}, 
 
		function() {			
			$(this).stop()
		 	.animate({
				'backgroundColor' :'#fff'	
				//'opacity' :'0.5'					
			},1000);						
	});
});





/*---------------------------------------------- ABOUT IMAGES HOVER ACTIONS -----------------------------------*/

$(document).ready(function(){
	
	//$("img", this).stop().css({top:"-380px"});
	
	
	$(".about a").hover(function(){
		
		$("img", this).stop().animate({top:"-380px"},{queue:false,duration:200});
	}, function() {
		$("img", this).stop().animate({top:"0px"},{queue:false,duration:200});
	});
	
	
	/*	$("img", this).stop().animate({top:"0px"},{queue:false,duration:200});
	}, function() {
		$("img", this).stop().animate({top:"-380px"},{queue:false,duration:200});
	});*/
});



/* --------------------------------- ROTATOR --------------------------- */

function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
	
}


function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 2000);

	//Hide the current image
	current.animate({opacity: 0.0}, 2000)
	.removeClass('show');
	
};

$(document).ready(function() {		
	//Load the slideshow
	theRotator();
});

/* ------------------------------ SNOW ---------------------------------- */


function r(n) { return Math.round(n*Math.random()); }
function fr(n) { return n*Math.random(); }
function sn(a) { return Math.sin(a); }








 
function createSnowCanvas(id) {

//apply snow onto any html element like this: createSnowCanvas('elementId');	
	
	//global vars for the snow	
	var c = null; // canvas
	var b = null; // buffer
	var pi2 = Math.PI*2; 
	var size = 2; // particle size
	var g=1; //gravity
	var wind=20; // vindhastighed
	var shift = 0.01; // hvor hurtigt skifter vindretningen
	var mp = 150; // maxparticles
	var p = new Array(mp); // particles


	//get properties of target div
	myDiv=document.getElementById(id);
	var w = myDiv.clientWidth;
	var h =myDiv.clientHeight; 
	//var zindex = parseFloat(myDiv.currentStyle['zIndex']);//måske for andre end moz???
	//var zindex = parseFloat(document.defaultView.getComputedStyle(myDiv,null).getPropertyValue('z-index'));
	//zindex=1000;
	//set target position to relative in order to place the canvas
	//myDiv.style.position="relative";

	//create new canvas
	var canvasElm = document.createElement("canvas");
	var snowId = canvasElm.id = "snow_"+id;               
	canvasElm.style.position = "absolute";               
	//canvasTag.style.border = "1px solid #0f0";   
	canvasElm.width = w;
	canvasElm.height = h;	   
	//document.body.appendChild(canvasTag);
	myDiv.appendChild(canvasElm);
	
	//move on top of the div	
	//myDiv.style.zIndex=1000;
	snow=document.getElementById(snowId);	
	snow.style.top=0;
	snow.style.left=0;
	//snow.style.zIndex=zindex+10;
	//snow.style.zIndex=zindex-1;

	c = document.getElementById(snowId).getContext('2d');
	for (var i=0; i<mp; i++) {
		p[i]=new Array(fr(w),fr(h),0.5+fr(size));
	}
 
	//start drawing
	setInterval(function(){
		draw(w,h,c,mp,p,pi2,g,wind);
	},30);
}
 
 
 

var a = 0;
function update(w,h,c,mp,p,pi2,g,wind) {
  //a+=shift;
  a+=0.01;
  var s=sn(a);
  for (var i=0; i<mp; i++) {
    var pn=p[i];
    var s2 = sn(4*a+i);
    pn[1]+=(pn[2]/2+(1+s2))*g;
    pn[0]+=wind*(s+(s2/2))/(10/pn[2]);
    if ((pn[1]>h+10)||(pn[0]>w+10)||(pn[0]<-10)) {
      p[i]=(i%3>0)?(Array(fr(w),-10,pn[2])):((s>0)?(Array(-5,fr(h),pn[2])):(Array(w+5,fr(h),pn[2])));
    }
  }  
}
 
function draw(w,h,c,mp,p,pi2,g,wind) {  
//resize
  c.width = w;
  c.height = h;
  //clear
  c.fillStyle = "#434343";
  //c.fillRect(0,0,w,h);//paints black  
  c.clearRect ( 0 , 0 , w , h );//really clears
  
  //draw snow
  c.fillStyle = "rgba(255,255,255,0.6)";  
  //c.strokeStyle="none";
  c.strokeStyle="rgba(255,255,255,0.2)";
  c.beginPath();
  for (var i=0; i<mp; i++) {
    c.moveTo(p[i][0],p[i][1]);
    c.arc(p[i][0],p[i][1],p[i][2],0,pi2,true);
	
  }
  c.fill();
  update(w,h,c,mp,p,pi2,g,wind);
}
 
