var pages = Array('gezondheidszorg','BSO','onderwijs','industrie','logistiek','utiliteitsbouw','specials');
var y = Array(0,0,1748,1748,1748,874,874);
var x = Array(0,490,980,0,490,0,490);

var y = Array(0, // gezondheidszorg
				0, // BSO
				874, // Onderwijs				
				1748, // Industrie
				1748, // Logistiek
				1748, // Utiliteitsbouw
				874 // Specials				
				);
var x = Array(0, // gezondheidszorg
				490, // BSO
				490, // Onderwijs				
				0, // Industrie
				490, // Logistiek
				980, // Utiliteitsbouw
				0 // Specials				
				);
$(function(){
   $('#icons ul li a').each(function(){
       $(this).mouseover(function(){
          $(this).parent().find('div.tip').show();
       });

      $(this).mouseleave(function(){
           $(this).parent().find('div.tip').hide();
      });

      $(this).click(function(event){
    	 event.preventDefault();
         goToPage($(this).attr('id'));
      });
   });

   /* Scroll to defenitions */
   $.easing.elasout = function(x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;if ((t/=d)==1) return b+c;if (!p) p=d*.3;
        if (a < Math.abs(c)) {a=c;s=p/4;}
        else s = p/(2*Math.PI) * Math.asin (c/a);
        return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
    };
    
    $('a.slideshow').fancybox();
    
    //$('#text0').parent().parent().addClass('homepage').find('#icon').css('display', 'none');
    reSetSlider();
    
    /* Pagecontent category select */
    $('#selCategory').change(function(){
    	document.location = $(this).val();
    });
    
    startCycle();
});

function reSetSlider(){
	$('#text0').parent().parent().addClass('homepage').find('#icon').css('display', 'none');
}

function goToPage(page){	
  nr = 0;
  for(p in pages){
    if(pages[p] == page){
        nr = p++;
    }
  }

  nr++;

  // hide info panel
  $('#info').animate({width:'0px'}, 600, function(){
	  $('#info').parent().removeClass('homepage').find('#icon').css('display', 'block');
      // change content & icon
      $(this).find('#icon img').attr('src', 'upload/slider/icon_'+nr+'.png'); //icon"><img src="upload/slider/icon_1.png" alt="Gezondheidszorg" title="Gezondheidszorg" /></div>
      $(this).find('.text').hide();
      $(this).find('#text'+nr).show();
      // slide background
      $('#background-img').stop().scrollTo({top:x[(nr-1)], left:y[(nr-1)]}, 800);
      // slide back info panel
      $('#info').animate({width:'325px'}, 600);
  });
}

function goToPageDirect(page){
	  nr = 0;
	  for(p in pages){
	    if(pages[p] == page){
	        nr = p++;
	    }
	  }

	  nr++;

	  $('#background-img').stop().scrollTo({top:x[(nr-1)], left:y[(nr-1)]}, 10);
}

var fields = ['edtUsername', 'pwdPassword', 'geg01', 'geg02', 'geg03', 'geg04', 'text01'];
var values = new Array();
$(function(){
	for(field in fields){
		values[fields[field]] = $('#'+fields[field]).val();
		$('#'+fields[field]).click(function(){ 
			if($(this).val() == values[$(this).attr('id')]){
				$(this).val('');
			}	
		}).blur(function(){
			if($(this).val() === ''){
				$(this).val(values[$(this).attr('id')]);
			}
		});
	}	
});


function startCycle(){
	$('.cycle').css('position','absolute');
	if($('.cycle').length > 1){
		cycleImage();
	}
}

current_img = 0;
function cycleImage(){
	$('.cycle').each(function(i){
		if(i === current_img){
			$(this).fadeOut('slow');
		}
		else if((((current_img+1) <= $('.cycle').length) && i === (current_img+1)) || ((current_img+1) <= $('.cycle').length) && i === 0){
			$(this).fadeIn('fast');
		}
	});

	current_img = (current_img + 1) < $('.cycle').length ? (current_img+1) : 0;
	
	setTimeout('cycleImage()', 5000);
}
