$(window).load(function() {   
	/*
	$('ul.lft_menu > li > a').bind('click', function() {
		if (this.nextSibling.nextSibling) {
			$('ul.lft_menu li ul').each(function() {
				this.parentNode.className = 'in_active';
				$(this).hide('fast');
			});
			if (!this.nextSibling.nextSibling.style.display || this.nextSibling.nextSibling.style.display != 'block') { 
				$(this.nextSibling.nextSibling).show('fast');
				this.parentNode.className = 'active';
				$(this).css({'paddingBottom':'7px'});
				
				$('#middle').html('<img src="/img/ajax_loader.gif" />');
				// start ajax call for fill the content
				$.get("/ajax_server.php", 
					{ 
						'action' 	: 'getPageInfo',
						pageId 		: this.id.replace('f_id_', '')
					},
				  	function(data){
				  		if (data) {
							var objectData = eval('(' + data + ')');
							$('#middle').html(objectData.data);
							$('#breadcrumb').html(objectData.breadcrumb);    
						}
				  	}
				);
			} else {
				this.parentNode.className = 'in_active';
				$(this.nextSibling.nextSibling).hide('fast');
				$(this).css({'paddingBottom':'0px'});
			}
		}
		return false;	
	});    
	*/           
	$('ul.menu li').each(function() {
		$(this).bind('mouseover', function() {
			jQuery(this).addClass('hover');
		});
		$(this).bind('mouseout', function() {
			jQuery(this).removeClass('hover');
		});
		$(this).bind('click', function(e) { 
			location.href = this.firstChild.href;
		});
	});
	
	Layout.resize();
});

$(window).resize(function(){
  	Layout.resize();
});


var Layout = {

	resize						:  function() {
		if ($('div#container_div_id').height() < $(window).height())
			$('div#container_div_id').css({'height':$(window).height()+'px'})
	},
	
	fixHeightAfterMenuSwitch 	: function() {
		var maxHeight = $(window).height();
		if (($('div#lft').height()+250) > maxHeight)
			maxHeight = $('div#lft').height()+250;
		if (($('div#content_wrapper').height()+250) > maxHeight)
			maxHeight = $('div#content_wrapper').height()+250;
		return $('div#container_div_id').css({'height':(maxHeight+75)+'px'})
	}
};

var Navigation = {
	
	init : function(target, keywords)  {
		$(target).each(function() {
			$(this).bind('click', function() {
				$('#search_results_container').html('<img src="/img/ajax_loader.gif" />');
				$.get("/ajax_server.php", 
					{ 
						'action' 	: 'search',
						'start'		: this.id.replace('f_id_', ''),
						'keywords' 	: Url.decode(keywords)
					},
				  	function(data){
				  		if (data) {
							 $('#search_results_container').html(data);
						}
				  	}
				);
				return false;
			});
		});
	}
};

function getAndFillFloorTypes(woodId)
{
	jQuery.getJSON("/ajax_server.php", 
		{ 
			'action' 	: 'getWoodType',
			'woodId'	: woodId
		},
	  	function(data){
	  		if (data) {
	  			jQuery('select#vloersoort').children().remove();
				jQuery.each(data, function(i,item){
				    var t = '<option value="'+ this.name +'">'+ this.name +'</option>';
				    jQuery('select#vloersoort').append(t);
				 });
			}
	  	}
	);
	return false;	
}

/* from quirksmode */
var Cookie = {

	createCookie	: function(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		} else {
			var expires = "";
		};
		document.cookie = name+"="+value+expires+"; path=/;"
	},
	
	readCookie : function(name)
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		};
		return null;
	},
	
	eraseCookie	: function(name) 
	{
		Cookie.createCookie(name,"",-1);
	}
};

var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

function sendToFriend(formObj)
{
	$.post("/ajax_server.php?action=sendToFriend", 
		{ 
			'data'		: jQuery(formObj).serialize(),
			'url'		: location.href
		},
	  	function(data){
	  		if (data) {
				var parent = formObj.parentNode;
				jQuery(formObj).remove();
				jQuery(parent).append('<p>Uw bericht is succesvol verstuurd.</p>');	 
			}
	  	}
	);	
}
