$(document).ready(function(){
	
	
	
	$("a.modal[rel]").overlay({
		
		// custom top position
			top: 260,
		
			// some mask tweaks suitable for facebox-looking dialogs
			mask: {
		
				// you might also consider a "transparent" color for the mask
				color: '#c6c6c6',
		
				// load mask a little faster
				loadSpeed: 200,
		
				// very transparent
				opacity: 0.4
			},
		
			// disable this for modal dialog-type of overlays
			closeOnClick: false
	
	
	});
 
	lightBox();
		
	//----------------------------------------------------------------------------
	
	clickPlayer();

	//----------------------------------------------------------------------------
	
	$('li.page-item-9 > a, li.page-item-11 > a, li.page-item-13 > a').click(function(){
	
		return false;
	});
	
	
	poll();
	
	//----------------------------------------------------------------------------

	hoverClubs();

	
	//----------------------------------------------------------------------------
	
	roundCorners();
	
	
	//----------------------------------------------------------------------------
	
	// Open het eerste wedstrijd verslag
	$('.main-column .custom-reports .overview.list .item:first').addClass('selected');
	
	//----------------------------------------------------------------------------

	// tabs settingds
	//$("div.tabs-nav ul").tabs("div.tabs > div.box");
	
	tabs();
		
	//----------------------------------------------------------------------------
		
	// Open item
	open_list_item();

	//----------------------------------------------------------------------------
	
	
	click_switch();		

	

});

function poll()
{
	
	$('.box.poll a.show-results').click(function(){
		
		$('.box.poll ul.results').addClass('selected');
		
	});
	
}


function tabs()
{

	// Hide all boxes, execpt the first one.
	$(".box.tabs").each(function(){
		
		$(".tabs > div",this).not(":eq(0)").hide();
		
	});
	
	// When a link is clicked
	$("div.tabs-nav ul li a").click(function () {
		
		var tabs = $(this).parent().parent().parent().parent().children('.tabs');
		
		 
		/*
			$("div.tabs >").not(this).each(function()
				{
					$(this).parent().addClass('not-hovered');
					 
				});
		*/
		
		// switch all tabs off
		$(".current", $(this).parent().parent() ).removeClass("current");

		// switch this tab on
		$(this).addClass("current");

		// slide all elements with the class 'content' up
		$("> div", tabs).hide();
		
		
		var index = $(this).parent().index();
		
		$("> div:eq("+index+")", tabs).show();

	});


}

function lightBox()
{
	$('.custom-pictures a').lightBox({fixedNavigation:true});

}

function roundCorners()
{	
	var ie = false;
	
	jQuery.each(jQuery.browser, function(i, val)
	{		
		if(i == 'msie' && val)
		{
			ie = jQuery.browser.version;
		}
	});
	
	// Ronde hoekjes
	if(ie >= 6)
	{	
		$('body').addClass('ie');
	
		$(".header-middle, .main-column, .side-column, .footer-top, #navigation")
			.css('position','relative')
			.append('<span class="rc-ltop"></span><span class="rc-rtop"></span><span class="rc-lbottom"></span><span class="rc-rbottom"></span>');
	}
	
}

//----------------------------------------------------------------------------




		
		
function clickPlayer()
{
	
	$(".player").click(function(e) {
	
		var href_player = $(this).children().children('a').attr('href');
		 window.location = href_player;
	});
	/*
		$(".player").overlay({
					
			mask: {
				color: '#c6c6c6',
				loadSpeed: 200,
				opacity: 0.4
			},
			fixed: false,
			//load: true,
			target: "#player"
		});
		
		$(".player").click(function(e) {
			
		
			
			 
		
				$('#player').children('.inner-box').empty();
					
					if($(this).children().children('a').length > 0)
					{
						
						var href_player = $(this).children().children('a').attr('href');
			
						jQuery.ajax({
							type: 'GET',
							url: href_player,
							async: true,
							success: function(result)
							{
								
								$(".inner-box", $('#player') ).html(result);
								
								
								clickPlayer();
							}
					
						});
													
			
					}
					
			
			
			
			
			return false;
			
		});
	*/

	
}


//----------------------------------------------------------------------------


function open_list_item()
{
	
	$('.main-column .overview.list .item:not(.sticky) ul.icons li a.icon.arrow').click(function(){
	
		
		var item = $(this).parent().parent().parent().parent();
		
		if($(item).hasClass('selected'))
		{
			$('ul.icons li a.arrow',item).removeClass('open');
			$(item).removeClass('selected');
		}
		else
		{
			if(!$(item).hasClass('clicked'))
			{
				$(item).addClass('clicked')
			}
			
			$('ul.icons li a.arrow',item).addClass('open');
			
			$(item).addClass('selected');
		}
		
		return false;
	});
	

}

//----------------------------------------------------------------------------

function hoverClubs()
{

	// Hover Club logos effect
	$('#header .clubs li a').stop().hover(function(){
		
	
		if($(this).parent().hasClass('not-selected') || $(this).parent().hasClass('selected'))
		{
			$(this).parent().addClass('selected');
			
		}
		else
		{
				
			$("#header .clubs li a").not(this).each(function()
			{
				$(this).parent().addClass('not-hovered');
				 
			});
		}
	
	},function(){
	
		if($(this).parent().hasClass('not-selected'))
		{
			$(this).parent().removeClass('selected');
		}
		else
		{
	
			$("#header .clubs li:not(.not-selected) a").not(this).each(function(){
				
				 $(this).parent().removeClass('not-hovered');
								
			});
		}
		
	});
	
}

//----------------------------------------------------------------------------


function click_switch()
{
	
	$("form#switch-category .switch-button").click(function(){
	
		//input:checkbox
		var finished;
		
		
		if($(this).hasClass('selected'))
		{
			$(this).removeClass('selected');
			$('input:checkbox', this).attr('checked', false);
			finished = true;
		}
		else
		{
			
			
			$(this).addClass('selected');
			$('input:checkbox', this).attr('checked', 'checked');
			
			finished = true;
			
		}
		
		
		if(finished)
		{
		//var href = base_url + '/competities/hoofdklasse/?league_id=1';
		var href = location.href ;
		var targets = [ '.main-column', '.side-column'];

		var box_news = loadXHR(href, targets);
		
		}
		
	});

}
//----------------------------------------------------------------------------

function loadXHR( href, target )
{
		
	jQuery.ajax({
		type: 'POST',
		url: href,
		data: $("form#switch-category").serialize(),
		async: true,
		success: function(post_data)
		{
						
			if(jQuery.isArray(target))
			{
				$.each(target, function(index, value) { 
				
					var html = $(value, post_data).html();
					$(value).html(html);
				
				});
				
			}
			else
			{	
				var html = $(target, post_data).html();
				$(target).html(html);
			}
			
			tabs();
			
			lightBox();
			
			clickPlayer();
			
			open_list_item();
			
			click_switch();
			
			//$(".tabs-nav ul").tabs("div.tabs > div");
			
			roundCorners();
			
			return post_data;
			
								
		}

	});//.responseText
		
	

}

//----------------------------------------------------------------------------


function wc()
{
	if(window.console)
	{
		for(var i = 0; i < arguments.length; i++)
		{
			window.console.log(arguments[i]);
		}
	}
}

