// JavaScript Document

	
$(document).ready(function() {
	
	positionSkyscraper();

	$('#nav li').hover(
		function() {
			jQuery.browser.version = jQuery.browser.msie
			&& parseInt(jQuery.browser.version) == 6
			&& window["XMLHttpRequest"] ? "7.0" : jQuery.browser.version;
						
			if(jQuery.browser.version == '7.0')
				$('#nav li').removeClass('sfhover');

			
			$(this).addClass('sfhover');

		},
		function() {
			$(this).removeClass('sfhover'); 
		}
	);
	
	$(".topics li").append(" &#8226; ");
	
	$("div.scrollable div.col_155").wrapAll('<div class="teasers"></div>');
	
	if($("div.scroller div.col_155").size()>0) {
		$("div.scrollable").scrollable({
			size: 4,
			clickable: true,
			loop: true,
			interval: 5000,
			items: ".teasers",
			prev: ".prevTeaser",
			next: ".nextTeaser"
	 });
	} else {
		$("div.scroller").hide()
	} 
	$("#nav .menu").prev("a").append("<img src='http://"+window.location.hostname+"/static/themis/images/arrow_nav_0.gif' class='off' /><img src='http://"+window.location.hostname+"/static/themis/images/arrow_nav_1.gif' class='on' />");
	
	$("#video.newsItem li:first").addClass("first");
	$("#video.newsItem ul").jcarousel({
		scroll: 1,
		buttonNextHTML: '<div class="next"><a href="javascript:void(0);"><span>volgende</span></a></div>',
		buttonPrevHTML: '<div class="prev"><a href="javascript:void(0);"><span>vorige</span></a></div>'
    });	
	
	$("#galleries .teaser:last").addClass("last");
	$("#weather .weather_day:first").css("float","left");
	$("#weather .weather_day:last").css("float","right");


	
	if(jQuery.browser.version == '6.0')
		try {
			DD_belatedPNG.fix('.prevTeaser, .nextTeaser, .fixpng');
		} catch(exception) {}


	//setColumnHeight();
	
	//$("#articleBody").css("height","100%");
	
	
	$("#reactionsmorelink a").click(function () {
		$(this).toggleClass("hidden");
	 	$("#reactionsmore").slideToggle("slow");
    });
	
	$("#reactions .reaction:even").css({'background' : '#F8F8F8', 'border-top' : '1px solid #D6D6D6', 'border-bottom' : '1px solid #D6D6D6'});
	
	$("#recentArticles li:last").css({'border-bottom' : 'none', 'margin-bottom' : '0', 'padding-bottom' : '0'});
	

	if ($("input[type=file]").length != 0){
		$("input[type=file]").filestyle({ 
			image: "/static/images/button_kies_foto.gif",
			imageheight : 20,
			imagewidth : 87,
			width : 526
		});
	}	
	
	$("#prom input").removeClass("inputfield");
	$("#prom input[type='text']").addClass("promfield");
	$("#prom textarea").addClass("promfield");
	$("#prom input[type='submit']").addClass("prombutton");
	$("#prom input[type='reset']").addClass("prombutton");
	
	
	$("#searchResults li:first").addClass("first");
	
	if($("#LOGOLINK .adheseTxtAdTitle").size() > 1){
		$("#LOGOLINK .adheseTxtAdTitle").css({'border-bottom' : '1px solid #E5E5E5'});
		$("#LOGOLINK .adheseTxtAdTitle:last").css({'border-bottom' : 'none'});
	} 	
	
	$(".teaserButtons .widget:odd").css("margin-left","5px");
	$(".teaserButtons .widget:even").css("margin-right","5px");
	
	$(".teaserButtonsLarge .widget:odd").css("margin-left","5px");
	$(".teaserButtonsLarge .widget:even").css("margin-right","5px");
	
	$("#thumbs img").fadeTo("slow", 0.6); 
	$("#thumbs img").hover(function(){
		$(this).fadeTo("fast", 1.0);
	},function(){
		$(this).fadeTo("fast", 0.6);
	});	

	$("#thumbs td").each(
		function( intIndex ){
			if($(this).find("img").length == 0){
				$(this).css("border","none");
			}
		}  
	);

	$(".teaserButtons").each(
		function( intIndex ){
			if($(this).find(".widget").length == 0){
				$(this).next("div.separator").remove();
				$(this).remove();				
			}
		}  
	);	
	
	$(".teaserButtonsLarge").each(
		function( intIndex ){
			if($(this).find(".widget").length == 0){
				$(this).next("div.separator").remove();
				$(this).remove();				
			}
		}  
	);	
	
	
	$(".dossier .col_320:first").addClass("left");
	$(".dossier .col_320:last").addClass("right");
	$(".dossier .col_320.right .teaser").addClass("clearfix");
	$(".dossier .col_320.right .teaser:last").addClass("last");



	$(".teaserRow2").each(function(i, item){
	
		$(item).find(".col_320:first").addClass("left");
		$(item).find(".col_320:last").addClass("right");
		$(item).find(".col_320.left .teaser:last").css("border-bottom","0");
		$(item).find(".col_320.right .teaser:last").css("border-bottom","0");
		
		$(item).find(".left .teaser")
		.each(function(i, item){
	
				c1 = $(item);
				c2 = $(item).parent().parent().find(".right").find(".teaser:nth-child("+(i+1)+")");
				c1H = $(item).height();	
				c2H = $(item).parent().parent().find(".right").find(".teaser:nth-child("+(i+1)+")").height();
				
				//alert(c1.parent().parent().find(".right"));
				//alert(i+": "+c1H + "=" + c2H);
				
				if(c1H < c2H){
					c1.height(c2H);
				}
				else {
					c2.height(c1H);
				}
				
	
	})});


	$("#stock tr:odd").css("background-color","#f8f8f8");
	
	$(".channels .col_180:first").addClass("left");
	$(".channels").each(
		function( intIndex ){
			$(this).find(".col_180").each(
				function( intIndex2 ) {
					if( (intIndex2 + 1 ) % 5 == 0 ){
						$(this).addClass("right");
						$(this).after('<div class="clear"></div>');
					}
					if( (intIndex2) % 5 == 0 ){
						$(this).addClass("left");
					}
				}
			);
		}  
	);
	
	$(".galleries-listing li:first").addClass("even");
	$(".galleries-listing").each(
		function( intIndex ){
			$(this).find("li").each(
				function( intIndex2 ) {
					if( (intIndex2) % 4 == 0 ){
						$(this).addClass("even");
					}
				}
			);
		}  
	);	
	
	$("#vlanjobs .teaser:last").addClass("last");
	$("#vlan .teaser:last").addClass("last");
	
	    function formatText(index, panel) {
		  return index + " ";
	    }
		
		try{
				$('.slider').anythingSlider({
					easing: "easeOutQuart",        // Anything other than "linear" or "swing" requires the easing plugin
					autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
					delay: 10000,                    // How long between slide transitions in AutoPlay mode
					startStopped: false,            // If autoPlay is on, this can force it to start stopped
					animationTime: 600,             // How long the slide transition takes
					hashTags: true,                 // Should links change the hashtag in the URL?
					buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
					pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
					startText: "Go",             // Start text
					stopText: "Stop",               // Stop text
					navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
				});
			}
			catch(err){};
			
});

function hideChildren(ul){
	if(	$(ul).find("li").size()>4){
		$(ul).find("li:gt(3)").hide();
		$(ul).find("li.less").remove();
		$(ul).append("<li class='more'><a href='javascript:void(0)'>&raquo; Toon alles</a></li>");
		$(ul).find("li.more a").click(function(){
				var parentUl = $(this).parent().parent();
				showChildren(parentUl);
		});
	}
}
	
function showChildren(ul){
	$(ul).find("li:gt(3)").show();
	$(ul).find("li.more").remove();
	$(ul).append("<li class='less'><a href='javascript:void(0)'>Verberg alles &laquo;</a></li>");
	$(ul).find("li.less a").click(function(){
			var parentUl = $(this).parent().parent();
				hideChildren(parentUl);
	});	
}

setColumnHeight = function(){
		
	if($(".channels").length == 0){
		columns = $(".col_140,.col_300,.col_500,.col_600,.col_650");
		height = 0;
		for( i=0; i<columns.length; i++){
			$(columns[i]).css('height','100%');
			if(height<$(columns[i]).outerHeight()){
				height = $(columns[i]).outerHeight();
			}
			}

		for( j=0; j<columns.length; j++){
			if(!$(columns[j]).hasClass("noResize")) {
				$(columns[j]).height(height);
			}
		}

	}
}
setHoverTeasers = function(){
	$("#sectionTeasers .teaser").hover(
  		function () {
    		$(this).css("background","#f8f8f8");
  		},
  		function () {
    		$(this).css("background","#ffffff");
  		}
	);
}

/**
 * Browser Detection by QuirksMode.org (http://www.quirksmode.org/js/detect.html)
 * 
 * Browser name: BrowserDetect.browser
 * Browser version: BrowserDetect.version
 * OS name: BrowserDetect.OS
 */

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function openSlideshow(url) {
    
    if (BrowserDetect.browser == "Explorer" && BrowserDetect.version == "6")
    {
        var slideShowWindow = window.open(url,'slideshow','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,width=987,height=655'); 
	}
    else if (BrowserDetect.browser == "Firefox")
    {
        var slideShowWindow = window.open(url,'slideshow','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,width=971,height=655');
    }
    else if (BrowserDetect.browser == "Safari")
    {
        var slideShowWindow = window.open(url,'slideshow','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,width=986,height=655');
    }
    else 
    {
        var slideShowWindow = window.open(url,'slideshow','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,width=976,height=655');
    } 
}

function positionSkyscraper() {
	var bw = $("#bodyWrapper");
	var tb = $("#topBanner");
	var bc = $("#breadcrumb");

	var bwOffset = bw.offset();
	var bwWidth = bw.width();
	var tbHeight = tb.outerHeight();
	var bcHeight = bc.outerHeight();
	
	//alert( "left: " + bwOffset.left + ", top: " + bwOffset.top + ", width: " + bwWidth );
	
	var skyLeft = bwOffset.left + bwWidth;
	var skyTop = bwOffset.top + tbHeight + bcHeight + 10;
	
	$("#skyscraper").css({'left' : skyLeft, 'top' : skyTop});
}
