/*globals*/
var headerBannerArray = []
var headerBannerId = 0;
var bannerHeaderTimer;
var bannerHeaderTimerTime = 5000;


/*main*/
function loadReady(){
	
	if($.cookie('font_size') != null){setFont($.cookie('font_size'));}
	else{setFont('small');}
	
	if(Number($.cookie('scroll_media_y')) > 0){
		
		$(document).scrollTop($.cookie('scroll_media_y'))
		$(document).scrollLeft($.cookie('scroll_media_x'))
	}
	
}

$(window).bind("beforeunload",function(){
			
	if(pageName == "media"){$.cookie('scroll_media_y',$(document).scrollTop());$.cookie('scroll_media_x',$(document).scrollLeft());}
	else{$.cookie('scroll_media_x',-1);$.cookie('scroll_media_y',-1)}
});

$(window).load(function () {
 	 
	loadHeaderBannerImage();
	//alert($(document).scrollTop());
	//this. > ".header_menu_menu_hover").hide()
	$(".header_menu_menu_item").hover(function(){$("#" + this.id + " .header_menu_menu_hover").show()},function(){$("#" + this.id + " .header_menu_menu_hover").hide()})
	
	//$(".header_menu_menu_item_active").hover(function(){$(this).css("background-image","url(/static/images/style/header_menu_menu_item_active.png)")},function(){$(this).css("background-image","url(/static/images/style/header_menu_menu_item_active.png)")})
});


//



/*home*/
var currentSpotlightItemID = 0;
function showSpotlightItem(itemID){
	
	if(currentSpotlightItemID != itemID){
		
		//$(".home_spotlight_item_cnt:not('#home_spotlight_item_cnt_"+itemID+"')").slideUp("fast");
		//$("#home_spotlight_item_cnt_"+itemID).slideDown("fast");
		$(".home_spotlight_item_cnt:not('#home_spotlight_item_cnt_"+itemID+"')").hide();
		$("#home_spotlight_item_cnt_"+itemID).show();
	}
	currentSpotlightItemID = itemID;
}

/*header*/
function loadHeaderBannerImage(){
	

	
	var xmlUrl="/page/xml_header_quote_image";
	//$.ajax({type: "GET",url: xmlUrl,dataType: "xml",success: loadHeaderBannerImageReady})
	$.get(xmlUrl,{},loadHeaderBannerImageReady,"xml");
}


function loadHeaderBannerImageReady(xml,success){
	
	
	
	$(xml).find("item").each(function(){
		
		var itemObject = {};
		itemObject.link = $(this).find("url").text();
  		itemObject.description = $(this).find("description").text();
		itemObject.location = $(this).find("location").text();
		
		headerBannerArray.push(itemObject);
	});
	
	
	var randId = Math.ceil(Math.random()*headerBannerArray.length) -1;
	headerBannerId  = randId;
	
	
	
	var imgDiv = $(document.createElement("div")).attr('id','header_image_banner_image_'+headerBannerId ).appendTo("#header_image_banner_image");
	var img = new Image();		
	//$(img).load(function(){$(this).fadeIn('slow');}).attr('src',headerBannerArray[headerBannerId].location).appendTo(imgDiv);

	$(img).attr('src',headerBannerArray[headerBannerId].location).appendTo(imgDiv);
	$("#header_image_banner_menu_item_"+headerBannerId).attr("class","header_image_banner_menu_item_active").fadeIn("fast");
	$('#header_image_banner_text_'+headerBannerId +' a').attr('href',headerBannerArray[headerBannerId].link).html(headerBannerArray[headerBannerId].description);
	
	$(img).fadeIn('fast');

  
	for(var i=0;i<headerBannerArray.length;i++){
		
		if(i != headerBannerId){
			
			var imgDiv = $(document.createElement("div")).attr('id','header_image_banner_image_'+i).appendTo("#header_image_banner_image");
			var img = new Image();	
			$(img).attr('src',headerBannerArray[i].location).appendTo(imgDiv);
			
			//$("#header_image_banner_menu_item_"+i).attr("class","header_image_banner_menu_item").show();

			$("#header_image_banner_menu_item_"+i).attr("class","header_image_banner_menu_item").fadeIn("fast");
			$('#header_image_banner_text_'+i +' a').attr('href',headerBannerArray[i].link).html(headerBannerArray[i].description);
			$('#header_image_banner_text_'+i).hide();
			//$("#header_image_banner_background").mousedown(function(){alert("klik")})
		}
	}
	
	
	sIFR.replace(omroep_bold, {selector: "#header_image_banner_text_"+headerBannerId+"",css: ['.sIFR-root { background-color: #FFFFFF; color: #ffa31a; }','a{color: #ffa31a;text-decoration:none}','a:hover{color: #ffa31a}'],wmode:'transparent'});

	//Animatie staat uit
	//bannerHeaderTimer = setTimeout("bannerHeaderTimerEvent()",bannerHeaderTimerTime);
	
}

function changeHeaderBannerImage(id,actionType){
	
	clearTimeout(bannerHeaderTimer)
	
	if(headerBannerId != id){
		$("#header_image_banner_image_"+headerBannerId+" img").fadeOut('slow');
		$("#header_image_banner_image_"+id+" img").fadeIn('slow');
		//$("#header_image_banner_text_"+headerBannerId).fadeOut("fast",function(){$("#header_image_banner_text_"+id).fadeIn("fast")});
		$("#header_image_banner_text_"+headerBannerId).hide()
		$("#header_image_banner_text_"+id).show();
	
		sIFR.replace(omroep_bold, {selector: "#header_image_banner_text_"+id+"",css: ['.sIFR-root { background-color: #FFFFFF; color: #ffa31a; }','a{color: #ffa31a;text-decoration:none}','a:hover{color: #ffa31a}'],wmode:'transparent'});

	
		$("#header_image_banner_menu_item_"+headerBannerId).fadeOut("fast",function(){$(this).attr("class","header_image_banner_menu_item").fadeIn("fast")});
		$("#header_image_banner_menu_item_"+id).fadeOut("fast",function(){$(this).attr("class","header_image_banner_menu_item_active").fadeIn("fast")});	
		headerBannerId = id;
		
		//Animatie staat uit
		//if(actionType == "timer"){bannerHeaderTimer = setTimeout("bannerHeaderTimerEvent()",bannerHeaderTimerTime);}
		//else{bannerHeaderTimer = setTimeout("bannerHeaderTimerEvent()",bannerHeaderTimerTime * 2);}
	}
}

var currentMenuMouseOverId = -1;

function headerBannerImageMouseOver(id){
	
	clearTimeout(bannerHeaderTimer);
	//alert(bannerHeaderTimer);
	//$("#header_image_banner_text a").html(headerBannerArray[id].description);
	
	//uitschakelen mouseover
	//$("#header_image_banner_text_"+currentMenuMouseOverId ).hide()
	//$("#header_image_banner_text_"+headerBannerId).hide()
	//$("#header_image_banner_text_"+id).show();
	//sIFR.replace(omroep_bold, {selector: "#header_image_banner_text_"+id+ "",css: ['.sIFR-root { background-color: #FFFFFF; color: #ffa31a; }','a{color: #ffa31a;text-decoration:none}','a:hover{color: #ffa31a}'],wmode:'transparent'});
	
	//currentMenuMouseOverId = id;
}

function headerBannerImageMouseOut(){
	
	//uitschakelen mouseover
	bannerHeaderTimer = setTimeout("bannerHeaderTimerEvent()",bannerHeaderTimerTime);
	
	//$("#header_image_banner_text a").html(headerBannerArray[headerBannerId].description);
	
	//$("#header_image_banner_text_"+currentMenuMouseOverId).hide()
	//$("#header_image_banner_text_"+headerBannerId).show();
	//sIFR.replace(omroep_bold, {selector: "#header_image_banner_text_"+headerBannerId+ "",css: ['.sIFR-root { background-color: #FFFFFF; color: #ffa31a; }','a{color: #ffa31a;text-decoration:none}','a:hover{color: #ffa31a}'],wmode:'transparent'});

}

function bannerHeaderTimerEvent(){
	
	
	if(headerBannerId < headerBannerArray.length -1){changeHeaderBannerImage(headerBannerId + 1);}
	else{changeHeaderBannerImage(0,"timer");}
}

function headerBannerLink(){
	
	
	if(headerBannerArray[headerBannerId].link != ""){
		
		
		window.location.href = headerBannerArray[headerBannerId].link;
	}
}


/* media model */
function mediaModelChange(mediaName){
	

	//$('#media_model_projecten_cnt').fadeOut('fast');
	
	//var url = "/page/xml_projecten";
	
	//var itemArray = mediaName.split(":");
	
	///for(var i = 0;i<itemArray.length;i++){
	
		//url = url + "/" + itemArray[i];
	//}
	
	//jQuery.get( url,null, loadModelChangeReady, 'html' )
	
	return("");
}

function mediaModelAnimation(){
	
	$("#media_block").hide();
}

function scrollMediaModel(){}


	


function loadModelChangeReady(data){
	
	//$('#media_model_projecten_cnt').html(data).fadeIn('fast');
}

/*block persinformatie*/
function showDownloadCat(id){
	
	$(id).slideToggle("fast"); //show all
}

/*contact*/
function selectWho(val){
	
	
	if(val != ""){
	
		
		$(".contact_block_mail_select:not('#contact_block_mail_"+val+"')").hide();
		$("#contact_block_mail_"+val).show();
		//$("#contact_block_mail_corperate").style.display = "block";
	}
}

/*nieuwsarchief*/
function selectNieuwsArchief(jaar){
	
	if(jaar != ""){
		
		window.location.href = "/page/nieuws/archief/" + jaar;	
	}
	
}

/*mediagallery*/
var currentMediaGalleryId = 0;
function mediaChangeGallery(id,type){
	
	if(currentMediaGalleryId != id){
		$("#media_block_image_btn_"+currentMediaGalleryId).addClass("media_block_image_btn");
		$("#media_block_image_btn_"+currentMediaGalleryId).removeClass("media_block_image_btn_active");
		$("#media_block_image_btn_"+id).addClass("media_block_image_btn_active");
		$("#media_block_image_btn_"+id).removeClass("media_block_image_btn");
		$("#media_block_image_cnt_"+id).fadeIn('fast');
		$("#media_block_image_cnt_"+currentMediaGalleryId).fadeOut('fast');
	
		currentMediaGalleryId = id;
	}
}

/*rss*/
function loadHomeRSS(){
	
	
	var omroepRssURL1 = "/xml/omroep.php";
	$.ajax({type: "GET",url: omroepRssURL1,dataType: "xml",success: loadOmroepRSSReady});
	
	var omroepRssURL2 = "/xml/spreekbuis.php";
	
	//$.ajax({type: "GET",url: omroepRssURL2,dataType: "xml",success: loadRadiocastRSSReady});
	$.get(omroepRssURL2,{},loadRadiocastRSSReady,"xml");
}

function loadOmroepRSSReady(xml){

	parseHomeRSS(xml,"#block_rss_1");	
}

function loadRadiocastRSSReady(xml,success){
	
	//$.log("xmlstart");
	parseHomeRSS(xml,"#block_rss_2");	
}

function parseHomeRSS(xml,id){
	
	var i = 0;
	
	$(id +" ul").html("");
	
	
	
	$(xml).find("item").each(function(){
  		
  		
  		
  		if(i<5){
  			var link = $(this).find("link").text();
  			var title = $(this).find("title").text();
  			link = "javascript:newWindow('" + link + "')";
  		
  			
  		
  			var li = $(document.createElement("li"))
  			var a = $(document.createElement("a")).attr("href",link).text(title).appendTo(li);
 
  			li.appendTo(id +" ul");
  			i++;
  		}
	});
}

function newWindow(val){

	this.window.open(val);
}

function resetForm(val){
	
	val.reset();
}

function openPrint(id,page){
	
	window.open('/page/print/artikel/'+id+'/' + page,'Print','width=680,height=768,scrollbars=yes,toolbar=no,location=no');
}

function openSendTo(id){
	
	window.open('/page/sendto/'+id,'Stuur door','width=610,height=540,scrollbars=no,toolbar=no,location=no');
}
function openEmbed(id){
	
	$("#nieuws_embed_code").slideToggle("fast");
}

/*zoeken*/
function clearSearch(val){
	
	if(val.value == "search"){
		
		val.value = "";
	}
	
}



/*css*/
function setFont(size){
	
	switch(size){
		
		case "small":	
			$("#font_zoom_small").css("color", "#ffa31a");
			$("#font_zoom_middle").css("color", "#b0b0b0");
			$("#font_zoom_large").css("color", "#b0b0b0");
			$("body").css("font-size","12px");
			if(vIE() == 6){
		

					
				$(".nieuws_item_comment_tag").css("margin-bottom","-18px");

				if($(".nieuws_item_small .nieuws_read_more").height() == 37){
				
					$(".nieuws_item_small .nieuws_read_more").css("background-position-y","26px");
				}
				else{
					
					$(".nieuws_item_small .nieuws_read_more").css("background-position-y","37px")
				}
			}
			$.cookie('font_size', 'small');
		break;
		case "middle":	
			$("#font_zoom_small").css("color", "#b0b0b0");
			$("#font_zoom_middle").css("color", "#ffa31a");
			$("#font_zoom_large").css("color", "#b0b0b0");
			$("body").css("font-size","14px");
			if(vIE() == 6){
				$(".nieuws_item_comment_tag").css("margin-bottom","-22px");
				
				
				if($(".nieuws_item_small .nieuws_read_more").height() == 37){
				
					$(".nieuws_item_small .nieuws_read_more").css("background-position-y","25px");
				}
				else{
				
					$(".nieuws_item_small .nieuws_read_more").css("background-position-y","36px");
				}
			}
			$.cookie('font_size', 'middle');
		break;
		case "large":	
			$("#font_zoom_small").css("color", "#b0b0b0");
			$("#font_zoom_middle").css("color", "#b0b0b0");
			$("#font_zoom_large").css("color", "#ffa31a");
			$("body").css("font-size","16px");
			if(vIE() == 6){
				$(".nieuws_item_comment_tag").css("margin-bottom","-26px");
				
				
				if($(".nieuws_item_small .nieuws_read_more").height() == 39){
					
					$(".nieuws_item_small .nieuws_read_more").css("background-position-y","25px");
				}
				else{
					
					$(".nieuws_item_small .nieuws_read_more").css("background-position-y","36px");
				}
			}
			$.cookie('font_size', 'large');
		break;
	}
}

function vIE(){return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;}

/*block jaarverslag*/
function showMoreBeleid(){

	$(".block_jaarverslag_hide_item").show();
	$("#block_jaarverslag_more").hide();
	$("#block_jaarverslag_less").show();
}

function showLessBeleid(){
	
	$(".block_jaarverslag_hide_item").hide();
	$("#block_jaarverslag_more").show();
	$("#block_jaarverslag_less").hide();
}



/*Organogram*/


var currentTab = "radio";
$(document).ready(function(){



$(".items").each(function(i){
	
//	alert(i);
//	$(this).css("display","none");
});

$(".items").append("<div class='clear'></div>");


$(".tabs").append("<div class='clear'></div>");


setSameHeight($("#beleidsstaf .function"))
setSameHeight($("#beleidsstaf .item"))
setSameHeight($(".tab .header"))
setSameHeight($(".tab"))
$(".items").each(function(){setSameHeight($(this).children())});
jQuery.each(jQuery.browser, function(i) {
  if($.browser.version.substr(0,1) == 6){

		
		$(".tab").height(155);
		$("#beleidsstaf .item").height(155);
		$("#raad_van_toezicht .item").height(60);
  }
});



$(".email").each(function(){
	
	var mail = $(this).html();
	mail = mail.replace(/\[atsign\]/gi,'@');
	
	$(this).html('');
	
	var link = $(document.createElement('a'));
	link.html("e-mail");
	link.attr("href","mailto:"+mail)
	//link.href = "test";
	
	$(this).append(link);
});



$("#organogram_tab_content").html('test');

$(".tab").prepend("<div class='tab_border_line'></div>");



$(".tab").mousedown(function(i){ 
	
	currentTab = $(this).attr("id");
	
	setTabNormal(".tab");
	setTabHover(this);
	$("#organogram_tab_content").html("test");
	
	var html = $("#"+$(this).attr("id")+" .items").html()
	
	$("#organogram_tab_content").html(html);
	$("#organogram_tab_content .item .function").css({"font-weight":"bold"})
	$("#organogram_tab_content .item div").css({"display":"inline","margin-left":"0px"})
	$("#organogram_tab_content .item").css({"height":"auto"});
	$("#organogram_tab_content .item:odd").css("background-color","#e7eaea");
	$("#organogram_tab_content .item").each(function(i){$(this).children().each(function(j){if(j > 0){$(this).prepend(" - ");}})});
	
})

$(".tab").hover(function(){setTabHover(this);},function(){setTabNormal(this);})
	

	$(".tab:first").each(function(i){
	
		currentTab = $(this).attr("id");
		setTabHover(this);
		//$("#organogram_tab_content").html($(this).html());	
		var html = $("#"+$(this).attr("id")+" .items").html()
		$("#organogram_tab_content").html(html);
		$("#organogram_tab_content .item .function").css({"font-weight":"bold"})
		$("#organogram_tab_content .item div").css({"display":"inline","margin-left":"0px"})
		$("#organogram_tab_content .item").css("height","auto");
		$("#organogram_tab_content .item:odd").css("background-color","#e7eaea");
		$("#organogram_tab_content .item").each(function(i){$(this).children().each(function(j){if(j > 0){$(this).prepend(" - ");}})});
	});
});


function setTabHover(selector){
	
	
	$(selector).css({'background-image':"url(/static/images/style/organogram_tab_background_hover.png)","background-color":"#c2c2c2","border-color":"#97c6c0"} );	
	$("#" + $(selector).attr("id") + " > .tab_border_line").css({'background-image':"url(/static/images/style/organogram_tab_border_hover.png)"});	
}


function setTabNormal(selector){
	
	$(selector).each(function(){
		
		if($(this).attr("id") != currentTab){
			$(this).css({'background-image':"url(/static/images/style/organogram_tab_background.png)","background-color":"#cbd1d1","border-color":"transparent"});
			$("#" + $(this).attr("id") + " > .tab_border_line").css({'background-image':"url(/static/images/style/organogram_tab_border.png)"});
		
	
		
		}	
	
	})
}


function setSameHeight(selector){
	
	var currentHeight = 0;
	$(selector).each(function(){
		if(currentHeight<$(this).height()){
			
			currentHeight = $(this).height();	
		}
	});
	
	$(selector).height(currentHeight);
	$(".clear").height(0);
	$.log(currentHeight);
}
