jQuery(function($)
{
	Cufon.replace('', {fontFamily: 'ITC Novarese', textShadow: '2px 2px rgba(0, 0, 0, 0.5)'});				
	Cufon.replace('#menu li a, h2, .login a.button, .login1 div.title, .login2 div.title, #content_close', {fontFamily: 'Franklin Gothic'});
	
	var self = this;
	
	$("#select_klant").change(function(){
		jQuery.post("/cmsfiles/components/finance/getfinance.php", {id : $(this).val()}, function(html){
			$("#finance_table").html(html);
			self.setFinanceTableOdd();
		});
	});
	
	$('#menu ul li').each(function(){
		if($(this).html() == ''){
			$(this).hide();
		}
	});
	
	$('#menu ul li a, #content_holder a').click(function()
	{
		var $page = $('#page_'+ $(this).attr('id'));
		var $link = $(this).attr('href');
		
		if($page.length < 1 || $link != '#')
		{
			document.location = $link;
		}
		else
		{
			$('#content_wrapper').show();
			$('#content_overlay').show();
			//$('#content').css('height', parseInt($page.height()));
			$('#logo_overlay').css('z-index', 4);
			
			$('.content_page').hide();
			$page.show();
		}
		return false;
	});
	
	if(!BUURFASHION_IS_DIGITAL_INVOICE_FORM)
	{
		$('#content_close, #content_close_top').click(function()
		{
			$('#content_wrapper').hide();
			$('#content_overlay').hide();
			$('#logo_overlay').css('z-index', 'auto');
			
			return false;
		});
	}
	
	$('#header .login1 a.button').click(function()
	{
		var $login2 = $(this)
			.parent().hide()
			.parent().children('.login2').show().children('.login-center');
		
		$login2.css('width', (parseInt($login2.children('div.title').width()) + 206));
		return false;
	});
	
	$('#header .login2 a.button').click(function()
	{
		var $this = $(this);
		var $id = $this.attr('id');
		
		var $login3 = $this
			.parent().parent().hide()
			.parent().children('.login3').show().children('.login-center');
		
		$login3.children('div.title').text($this.attr('title'));
		$login3.children('a.button').click(function()
		{
			var $parent = $(this).parent();
			var $user = $parent.children('#username');
			var $pass = $parent.children('#password');
			
			if($user.val() == $user.attr('id'))
			{
				$user.val('');
				$user[0].select();
			}
			else if($pass.val() == $pass.attr('id'))
			{
				$pass.val('');
				$pass[0].select();
			}
			else
			{
				($this.attr("id") == "button-finance")
					? login($user.val(), $pass.val())
					: window.open('http://webshop.softwear.nl/scripts/FoxIsapi.dll/sww1.wreq1.mpx?login&'+ $user.val() +'&'+ $pass.val() +'&'+ $id, '_blank');
			}
			return false;
		});
		
		Cufon.replace('.login3 div.title', {fontFamily: 'Franklin Gothic'});
		
		$login3.css('width', (parseInt($login3.children('div.title').width()) + 274));
		return false;
	});
	
	$('#header .login3 input')
		.focusin(function()
		{
			var $this = $(this);
			if($this.attr('id') == $this.val()) $this.val('');
		})
		.focusout(function()
		{
			var $this = $(this);
			if($this.val() == '') $this.val($this.attr('id'));
		});

	var login = function(user, pass)
	{
		var parameters = {extranet_user : user, extranet_password : pass};
		
		$.post("/cmsfiles/components/finance/login.php", parameters, function(json)
		{
			if(json.loggedIn){
				location.href = json.url;
			} else {
				alert(json.message);
			}
		},"json");
	}
	
	this.setFinanceTableOdd = function()
	{
		$("#finance_table tr").removeClass("odd");
		$("#finance_table tr:odd").addClass("odd");
	}
	
	this.setFinanceTableOdd();
});
