/**
 * @author reinderdevries
 */

var replaceJSEducatieMenu = function()
{
	if($('#educatie').length > 0)
	{
		// Build titles
		var html = '<div class="item" id="educatie_menu">';
		$('#educatie .header').each(function(index) {
			if ($(this).hasClass('header_ext')){
				html += $(this).html();
			}else{
				html += '<a href="javascript:;" class="title pink ' + (index == 0 ? 'active' : '') + '">' + $(this).text() + '</a>';
			}
		});
		
		// Replace the script
		$('#replace_js_educatie_menu').replaceWith(html + '</div>');
		
		// Attach handlers to the educatie headers
		$('#educatie .header').click(function() {
			$('#educatie_menu .title').removeClass('active');
			$('#educatie_menu .title').eq($(this).index()/2).addClass('active');
		});
		
		// Attach handlers to the menu titles
		$('#educatie_menu .title').click(function() {
			//alert($('#educatie .header').eq().html());
			$('#educatie').accordion('activate', $('#educatie .header').eq($(this).index()));
			$('#educatie_menu .title').removeClass('active');
			$(this).addClass('active');
			parent.scrollTo(0,0);
		});	
	}
};

var replaceJSAccordionMenu = function()
{
	if($('#accordion').length > 0)
	{
		// Build titles
		var html = '<div class="item" id="accordion_menu">';
		$('#accordion .header').each(function(index) {
			html += '<a href="javascript:;" class="title pink ' + (index == 0 ? 'active' : '') + '">' + $(this).text() + '</a>';
		});
		
		// Replace the script
		$('#replace_js_accordion_menu').replaceWith(html + '</div>');
		
		// Attach handlers to the accordion headers
		$('#accordion .header').click(function() {
			$('#accordion_menu .title').removeClass('active');
			$('#accordion_menu .title').eq($(this).index()/2).addClass('active');
		});
		
		// Attach handlers to the menu titles
		$('#accordion_menu .title').click(function() {
			//alert($('#accordion .header').eq().html());
			$('#accordion').accordion('activate', $('#accordion .header').eq($(this).index()));
			$('#accordion_menu .title').removeClass('active');
			$(this).addClass('active');
			parent.scrollTo(0,0);
		});	
	}
};

var replaceTwitter = function()
{
	var user = 'hetlabutrecht';
	$.ajax({
	  url: 'http://twitter.com/status/user_timeline/' + user + '.json?count=10&callback=?',
	  dataType: 'json',
	  //data: data,
	  success: jsonTwitterHandler
	});
};

var jsonTwitterHandler = function(result)
{
	var num = result.length;
	for(var i = 0; i < num; i++)
	{
		alert(i.text);
	}
};

window.onload = function()
{
	if($('#accordion').length > 0)
	{
		$('#accordion').accordion({header: 'div.header', clearStyle: true});
	}
	if($('#educatie').length > 0)
	{
		$('#educatie').accordion({header: 'div.header', clearStyle: true});
	}
	
	if($('#slider').length > 0) {
		$("body").BgResize({});	
		$('#slider').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			speed: '1000',
			timeout: '10000'
		});
	}
	
	
	if($.browser.msie == true && $.browser.version == "7.0")
	{
		// Do IE7 height of slider thingie
		//$('#slider').css('height', ($(window).height() - 121) + 'px');
		
		$('.producties a').each(function() {
			var href = $(this).attr('href');
			$('.producties a.productie[href=' + href + ']').click(function() {
				//alert('url' + window.location.hostname + href);
				window.location = 'http://' + window.location.hostname + href;
			})
		});
		
		
	}
	
	// Slider image
	//$('#slider img').attr('width', '100%');
	//$('#slider img').attr('height', '100%');
	
	if($('#accordion').length > 0)
	{
		var t = setTimeout(function() {
			$('#accordion .producties').css('height', 'auto');
		}, 100);
	}
	
	if($('#educatie').length > 0)
	{
		var t = setTimeout(function() {
			$('#educatie .producties').css('height', 'auto');
			$('#educatie').accordion( "activate" , Drupal.settings.current_ac);
		}, 100);
	}
	
	
};

