$(document).ready(function() {
	if($("h2#page-head").length > 0){
		$("h2#page-head").hide();
	}	
	
	if($(".content_image").length > 0){
		$(".content_image").fancybox();
	}
	
	if($(".fancybox_gallery").length > 0){
		$(".fancybox_gallery").fancybox();
	}
	
	if($(".course-image").length > 0){
		$(".course-image").fancybox();
	}
	
	if($(".course-gallery").length > 0){
		$(".course-gallery a").fancybox();
	}
	
	if($("ul#headnav").length > 0){
		$('ul#headnav').superfish();
	}
	
	if($(".groupli").length > 0){
		$(".groupli").each(function() {
			var id = $(this).attr('id');
			if ($(this).attr('id') != "color-") {
				var color = $(this).attr('id').replace('color-','#');
				$("#" + id + " a").css('background-color', color);
				if (jQuery.browser.msie) {
					if (parseInt(jQuery.browser.version) == 6) {
						$("#" + id + " a").css('background-color', '#f8f8f8');
						$("#" + id + " a").css('color', color);
					}
					else {
						$("#" + id + " ul.stage2").css({ 'border-left' : '2px solid ' + color, 'border-right' : '2px solid ' + color, 'border-bottom' : '2px solid ' + color });
						$("#" + id + " ul.stage2 li a").mouseover(function(){ $(this).css('color', color); });
						$("#" + id + " ul.stage2 li a").mouseout(function(){ $(this).css('color', '#666'); });
						$("#" + id + " ul.stage2 li ul.stage3 li a").mouseover(function(){ $(this).css('color', color); });
						$("#" + id + " ul.stage2 li ul.stage3 li a").mouseout(function(){ $(this).css('color', '#666'); });
					}
				}
				else {
			 		$("#" + id + " ul.stage2").css({ 'border-left' : '2px solid ' + color, 'border-right' : '2px solid ' + color, 'border-bottom' : '2px solid ' + color });
			 		$("#" + id + " ul.stage2 li a").mouseover(function(){ $(this).css('color', color); });
			 		$("#" + id + " ul.stage2 li a").mouseout(function(){ $(this).css('color', '#666'); });
			 		$("#" + id + " ul.stage2 li ul.stage3 li a").mouseover(function(){ $(this).css('color', color); });
			 		$("#" + id + " ul.stage2 li ul.stage3 li a").mouseout(function(){ $(this).css('color', '#666'); });
		 		}
		 		$("ul.stage1 .group-info").each(function() {
		 			var groupid = $(this).attr('id');
		 			var backcolor = $("#" + groupid).parents().get(1).id.replace('color-','#');
		 			var groupdescid = $(this).attr('id').replace('-','desc-');
		 			var groupdesc = $("#" + groupdescid).html();
		 			$("#" + groupid).qtip({
		 				content: groupdesc,
		 				position: {
		 						corner: {
		 						target: 'topLeft',
		 						tooltip: 'bottomRight'
		 					}
		 				},
		 				style: { 
		 					width: 450,
		 				    padding: 10,
		 				    background: backcolor,
		 				    color: 'white',
		 				    textAlign: 'left',
		 				    border: {
		 				    	width: 5,
		 				        radius: 3,
		 				        color: '#ccc'
		 				    },
		 				    tip: 'bottomRight'
		 				},
		 				show: 'mouseover',
		 				hide: 'mouseout'
		 			});
		 		});	
		 		$("ul.stage2 .group-info").hide();
		 	}	
		 	else {}
		});
	}
	
	if($("#home-slider").length > 0){
		$('#home-slider').cycle({
			fx: 'scrollHorz',
			timeout:  6000,
			random: true,
			prev: '.prev-home',
			next: '.next-home'
		});
	}
	
	if($("#content-slider-wide").length > 0){
		$('#content-slider-wide').cycle({
			fx: 'scrollHorz',
			timeout:  6000,
			random: true,
			prev: '.prev-content-wide',
			next: '.next-content-wide'
		});
	}
	
	if($(".news-items").length > 0){
		$('.news-items').cycle({
			fx: 'scrollHorz',
			timeout:  6000,
			random: true,
			prev: '.prev-news',
			next: '.next-news'
		});
	}
	
	if($(".newsteaser").length > 0){
		$('.newsteaser').eq(0).css('border', '0');
	}
	
	var default_values = new Array();	
	$('#topsearch').focus(function() {
		if (!default_values[this.id]) {
			default_values[this.id] = this.value;
		}
		if (this.value == default_values[this.id]) {
			this.value = '';
		}
		$(this).blur(function() {
			if (this.value == '') {
				this.value = default_values[this.id];
			}
		});
	});
	$('#search').focus(function() {
		if (!default_values[this.id]) {
			default_values[this.id] = this.value;
		}
		if (this.value == default_values[this.id]) {
			this.value = '';
		}
		$(this).blur(function() {
			if (this.value == '') {
				this.value = default_values[this.id];
			}
		});
	});
	
	if($(".accordion").length > 0){
		$(".accordion").accordion({
			active: true,
			collapsible: true,
			autoheight: false,
			clearStyle: true,
			animated: 'slide'
		});
	}
	
	if($("#copy-data").length > 0){
		$("#copy-data").click(function(){ 
			$("input#machtiging_csurname").val($("input#csurname").val()); 
			$("input#machtiging_cinit").val($("input#cinit").val()); 
			$("input#machtiging_caddress").val($("input#caddress").val()); 
			$("input#machtiging_cpc2").val($("input#cpc2").val());
			$("input#machtiging_cplace2").val($("input#cplace2").val());  
		});
	}
});

// Open External Links as Blank Targets via Unobtrusive JavaScript
// http://perishablepress.com/press/2007/11/20/open-external-links-as-blank-targets-via-unobtrusive-javascript/

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && ( 
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" || 
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}
window.onload = function() {
	externalLinks();
}

function changeCourse(optionid){
	$('#ccoursename').val('');
	$('#ccourseoptionname').val('');
	var ccoursename = $("#ccourse option[value='" + optionid + "']").text();
	$('#ccoursename').val(ccoursename);
	$.ajax({
		url: '/codeblue/inc_courses.php',
		data: ({'action' : 'getCourseOptions', 'course' : optionid}),
		success: function(data) {
			$('#ccourseoption').empty();
			var first = unescape(data);
			var second = str_replace('euro', '\u20AC', first);
			$('#ccourseoption').append(second);
		}
	});
	changePrice(optionid);
}

function changeOption(optionid){
	var ccourseoptionname = $("#ccourseoption option[value='" + optionid + "']").text();
	$('#ccourseoptionname').val(ccourseoptionname);
}

function changePrice(optionid){
	$.ajax({
		url: '/codeblue/inc_courses.php',
		data: ({'action' : 'getCoursePrice', 'course' : optionid}),
		success: function(data) {
			var first = unescape(data);
			var second = str_replace('euro', '\u20AC', first);
			$('#machtiging_cmoney').val(second);
		}
	});
}

function str_replace (search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

jQuery.extend({
	getUrlVars: function(){
		var vars = [], hash;
	    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	    for(var i = 0; i < hashes.length; i++) {
	    	hash = hashes[i].split('=');
	      	vars.push(hash[0]);
	      	vars[hash[0]] = hash[1];
	    }
	    return vars;
	},
  	getUrlVar: function(name){
    	return jQuery.getUrlVars()[name];
	},
	random: function(X) {
		return Math.floor(X * (Math.random() % 1));
  	},
  	randomBetween: function(MinV, MaxV) {
		return MinV + jQuery.random(MaxV - MinV + 1);
  	}
});





function ie_function() {
/*@cc_on @*/
/*@if (@_jscript_version < 5.7)
// JavaScript Document
/*

 

Correctly handle PNG transparency in Win IE 5.5 & 6.

http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.



Use in <HEAD> with DEFER keyword wrapped in conditional comments:

<!--[if lt IE 7]>

<script defer type="text/javascript" src="/js/pngfix.js"></script>

<![endif]-->



*/



var arVersion = navigator.appVersion.split("MSIE")

var version = parseFloat(arVersion[1])



if ((version >= 5.5) && (document.body.filters)) 

{

   for(var i=0; i<document.images.length; i++)

   {

      var img = document.images[i]

      var imgName = img.src.toUpperCase()

      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")

      {

         var imgID = (img.id) ? "id='" + img.id + "' " : ""

         var imgClass = (img.className) ? "class='" + img.className + "' " : ""

         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "

         var imgStyle = "display:inline-block;" + img.style.cssText

         if (img.align == "left") imgStyle = "float:left;" + imgStyle

         if (img.align == "right") imgStyle = "float:right;" + imgStyle

         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle

         var strNewHTML = "<span " + imgID + imgClass + imgTitle

         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"

         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"

         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 

         img.outerHTML = strNewHTML

         i = i-1

      }

   }

}
/*@end @*/
}