$.fn.frontend = function($options) {
	
	setLayout();
	
	//Timeout
	setTimeout(function(){
		setLayout();
	},900);

	
	//Resize-actions
	$(window).resize(function() {
  		setLayout();
	});

	
	//Set Layout
	function setLayout (){
		if($options.page_id == 'index'){
			//$('div#twitter_bg_middle').height($('div#home_left').height() - 125);
			//$('div#twitter_content').height($('div#home_left').height() - 23);
		}
	}; 
	
	
	//ImgHover
	$('.hover').imghover({suffix: '-hover', fade: true, fadeSpeed: 300});
	
	
	//--Mailbots--//
	var email = ['info','snelned','nl'];
	$('span.liambot_avoider').html('<a href="mailto:'+email[0]+'@'+email[1]+'.'+email[2]+'" class="footer">'+email[0]+'@'+email[1]+'.'+email[2]+'</a>');
	$('span.liambot_avoider_contact').html('<a href="mailto:'+email[0]+'@'+email[1]+'.'+email[2]+'" class="contact">'+email[0]+'@'+email[1]+'.'+email[2]+'</a>');
	
	
	//Menu
	$('img.bt_menu').hover(
		function () {$('img#hover_' + $(this).attr('id')).animate({left: "0px"}, 220, 'easeOutExpo');},
		function () {$('img#hover_' + $(this).attr('id')).animate({left: "-32px"}, 220, 'easeOutExpo');}
	);
	
	$("div#logo_holder").click(function(){
	    window.location = $(this).attr("title");
	    return false;
	});
	
	$("div#logo_holder").hover(
		function () {$('img#logo_animation').animate({top: "38px"}, 400, 'easeOutExpo');},
		function () {$('img#logo_animation').animate({top: "43px"}, 400, 'easeOutExpo');}
	);
	
	
	//Slider
	$('div#slider').nivoSlider({
        effect: 'fold',
        slices: 15,
        boxCols: 15,
        boxRows: 5,
        animSpeed: 800,
        pauseTime: 5000,
        directionNav: false,
        directionNavHide: false,
        controlNav: false,
        keyboardNav: false,
        pauseOnHover: false
    });
	
	//Footer
	$('img.footer_bt').hover(
		function () {$(this).animate({marginTop: "8px"}, 250, 'easeOutExpo');},
		function () {$(this).animate({marginTop: "13px"}, 250, 'easeOutExpo');}
	);
	
	
	if($options.page_id == 'index'){
		//Twitterfeed
		$("div#twitter_api").tweet({
            username: "SnelNed",
            intro_text: "",
            count: 5,
            loading_text: "loading tweets..." //wordt een afbeelding: img/twitter/loading.jpg
        });
		$('span.postcode_list').hover(
			function () {$('span.postcodegebied_' + $(this).attr('id')).fadeIn(250);},
			function () {$('span.postcodegebied_' + $(this).attr('id')).fadeOut(350);}
		);
		setTimeout(function(){
			$('img#twitter_load').fadeOut(300);
		}, 1000);
	} else if($options.page_id == 'partners'){
		//Fill Tables
		var a_h_count = $('table#data_a_h tr').length;
		var i_q_count = $('table#data_i_q tr').length;
		var r_z_count = $('table#data_r_z tr').length;

		$('div#summary_content').height(282);
		
		for(var i = 1; i < (a_h_count + 1); i++) {
            $('td#a_h_td_' + i).html(
           	'<div class="td_holder">' +
					'<div class="table_text_holder">' +
						'<h1>' + $('table#data_a_h tr:nth-child(' + i + ') td:nth-child(1)').html() + '</h1>' +
					'</div>' +
					'<div class="mini_map_holder"><img src="img/minimaps/' + $('table#data_a_h tr:nth-child(' + i + ') td:nth-child(1)').html() + '.png" class="mini_map_img" /></div>' +
				'</div>'
            );
		};
		for(var i = 1; i < (i_q_count + 1); i++) {
           $('td#i_q_td_' + i).html(
          	'<div class="td_holder">' +
					'<div class="table_text_holder">' +
						'<h1>' + $('table#data_i_q tr:nth-child(' + i + ') td:nth-child(1)').html() + '</h1>' +
					'</div>' +
					'<div class="mini_map_holder"><img src="img/minimaps/' + $('table#data_i_q tr:nth-child(' + i + ') td:nth-child(1)').html() + '.png" class="mini_map_img" /></div>' +
				'</div>'
           );
		};
		for(var i = 1; i < (r_z_count + 1); i++) {
           $('td#r_z_td_' + i).html(
          	'<div class="td_holder">' +
					'<div class="table_text_holder">' +
						'<h1>' + $('table#data_r_z tr:nth-child(' + i + ') td:nth-child(1)').html() + '</h1>' +
					'</div>' +
					'<div class="mini_map_holder"><img src="img/minimaps/' + $('table#data_r_z tr:nth-child(' + i + ') td:nth-child(1)').html() + '.png" class="mini_map_img" /></div>' +
				'</div>'
           );
		};
		
		setTimeout(function(){
			$('div#parnters_loading_animation').fadeOut(350, function(){
				$('div#summary_content').animate({height: ($('div.active_summary').height())}, 1000, 'easeOutExpo', function(){
					$('div.active_summary').fadeIn(350);
				});
			});
		},500);
		
//		setTimeout(function(){
//			for(var i = 1; i < (a_h_count + 1); i++) {
//	             $('td#a_h_td_' + i).html(
//	            	'<div class="td_holder">' +
//						'<div class="table_text_holder">' +
//							'<h1>' + $('table#data_a_h tr:nth-child(' + i + ') td:nth-child(1)').html() + '</h1>' +
//							'<p>' + 
//							$('table#data_a_h tr:nth-child(' + i + ') td:nth-child(2)').html() + '<br />' + 
//							$('table#data_a_h tr:nth-child(' + i + ') td:nth-child(3)').html() + '<br />' + 
//							$('table#data_a_h tr:nth-child(' + i + ') td:nth-child(4)').html() + '<br />' + 
//							'<a href="mailto:' + $('table#data_a_h tr:nth-child(' + i + ') td:nth-child(6)').html() + '">' + $('table#data_a_h tr:nth-child(' + i + ') td:nth-child(5)').html() + '</a></p>' +
//						'</div>' +
//						'<div class="mini_map_holder"><a href="http://maps.google.com/maps?q=Nederland%2C%20' + $('table#data_a_h tr:nth-child(' + i + ') td:nth-child(2)').html() + '%2C%20' + $('table#data_a_h tr:nth-child(' + i + ') td:nth-child(1)').html() + '" target="_blank"><img src="img/minimaps/' + $('table#data_a_h tr:nth-child(' + i + ') td:nth-child(1)').html() + '.png" class="mini_map_img" /></a></div>' +
//					'</div>'
//	             );
//			};
//			for(var i = 1; i < (i_q_count + 1); i++) {
//	            $('td#i_q_td_' + i).html(
//	           	'<div class="td_holder">' +
//						'<div class="table_text_holder">' +
//							'<h1>' + $('table#data_i_q tr:nth-child(' + i + ') td:nth-child(1)').html() + '</h1>' +
//							'<p>' + 
//							$('table#data_i_q tr:nth-child(' + i + ') td:nth-child(2)').html() + '<br />' + 
//							$('table#data_i_q tr:nth-child(' + i + ') td:nth-child(3)').html() + '<br />' + 
//							$('table#data_i_q tr:nth-child(' + i + ') td:nth-child(4)').html() + '<br />' + 
//							'<a href="mailto:' + $('table#data_i_q tr:nth-child(' + i + ') td:nth-child(6)').html() + '">' + $('table#data_i_q tr:nth-child(' + i + ') td:nth-child(5)').html() + '</a></p>' +
//						'</div>' +
//						'<div class="mini_map_holder"><a href="http://maps.google.com/maps?q=Nederland%2C%20' + $('table#data_i_q tr:nth-child(' + i + ') td:nth-child(2)').html() + '%2C%20' + $('table#data_i_q tr:nth-child(' + i + ') td:nth-child(1)').html() + '" target="_blank"><img src="img/minimaps/' + $('table#data_i_q tr:nth-child(' + i + ') td:nth-child(1)').html() + '.png" class="mini_map_img" /></a></div>' +
//					'</div>'
//	            );
//			};
//			for(var i = 1; i < (r_z_count + 1); i++) {
//	            $('td#r_z_td_' + i).html(
//	           	'<div class="td_holder">' +
//						'<div class="table_text_holder">' +
//							'<h1>' + $('table#data_r_z tr:nth-child(' + i + ') td:nth-child(1)').html() + '</h1>' +
//							'<p>' + 
//							$('table#data_r_z tr:nth-child(' + i + ') td:nth-child(2)').html() + '<br />' + 
//							$('table#data_r_z tr:nth-child(' + i + ') td:nth-child(3)').html() + '<br />' + 
//							$('table#data_r_z tr:nth-child(' + i + ') td:nth-child(4)').html() + '<br />' + 
//							'<a href="mailto:' + $('table#data_r_z tr:nth-child(' + i + ') td:nth-child(6)').html() + '">' + $('table#data_r_z tr:nth-child(' + i + ') td:nth-child(5)').html() + '</a></p>' +
//						'</div>' +
//						'<div class="mini_map_holder"><a href="http://maps.google.com/maps?q=Nederland%2C%20' + $('table#data_r_z tr:nth-child(' + i + ') td:nth-child(2)').html() + '%2C%20' + $('table#data_r_z tr:nth-child(' + i + ') td:nth-child(1)').html() + '" target="_blank"><img src="img/minimaps/' + $('table#data_r_z tr:nth-child(' + i + ') td:nth-child(1)').html() + '.png" class="mini_map_img" /></a></div>' +
//					'</div>'
//	            );
//			};
//			$('div#parnters_loading_animation').fadeOut(350, function(){
//				$('div#summary_content').animate({height: ($('div.active_summary').height())}, 1000, 'easeOutExpo', function(){
//					$('div.active_summary').fadeIn(350);
//				});
//			});
//		},1000);
		
		//A-Z Menu
		$('img.bt_az_menu').hover(function(){
			if(!$(this).hasClass('bt_az_menu_active')){
				$(this).addClass('bt_az_menu_hover_active');
				$(this).attr('src', $(this).attr('src').replace(/\.(.+)$/i, '-hover.$1'));
			}
		}, function() {
			if(!$(this).hasClass('bt_az_menu_active')){
				$(this).removeClass('bt_az_menu_hover_active');
				$(this).attr('src', $(this).attr('src').replace(/-hover\.(.+)$/i, '.$1'));	
			}
		});
		
		
		
		$('img.bt_az_menu').click(function(){
			if(!$(this).hasClass('bt_az_menu_active')){
				var picked_item = $(this);
				$('img.bt_az_menu_active').attr('src', $('img.bt_az_menu_active').attr('src').replace(/-active\.(.+)$/i, '.$1'));
				$('img.bt_az_menu_active').removeClass('bt_az_menu_active');
				$(this).attr('src', $(this).attr('src').replace(/-hover\.(.+)$/i, '-active.$1'));
				$(this).addClass('bt_az_menu_active');
				$('div.active_summary').fadeOut(350, function(){
					$('div.active_summary').removeClass('active_summary').addClass('inactive_summary');
					$('div.'+picked_item.attr('id')).addClass('active_summary');
					$('div#summary_content').animate({height: ($('div.active_summary').height())}, 1000, 'easeOutExpo', function(){
						$('div.active_summary').fadeIn(350);
						$('div.active_summary').removeClass('inactive_summary');
					});
				});
			}
		});
	} else if($options.page_id == 'contact'){
		//Social Btns
		$('img.contact_social_btn').hover(
			function () {$(this).animate({marginRight: "7px"}, 150, 'easeOutExpo');},
			function () {$(this).animate({marginRight: "0px"}, 150, 'easeOutExpo');}
		);
		//--CONTACTFORM--//
		var form_options = {
			beforeSubmit : function(formData, jqForm, options) {
				$('img#uw_bericht_is_verzonden').fadeOut(300);
				$('img#uw_bericht_is_verzonden_c').fadeOut(300);
				var submit = true;
				var form = jqForm[0];
				if (form.contact_naam.value.length > 100 || form.contact_naam.value.length < 3) {
					submit = false;
					$('img#error_name').fadeIn(300);
					} else {
						$('img#error_name').fadeOut(300);
					}
				var pattern_email = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/;
				if (!pattern_email.test(form.contact_email.value)) {
					submit = false;
					$('img#error_email').fadeIn(300);
				} else {
					$('img#error_email').fadeOut(300);
				}
				if (form.contact_bericht.value.length < 10 || form.contact_bericht.value.length > 1000) {
					submit = false;
					$('img#error_message').fadeIn(300);
				} else {
					$('img#error_message').fadeOut(300);
				}
				return submit;
			},
			success : function(responseText, statusText, xhr, $form) {
				switch (responseText) {
					case 'succes' :
						$('img#uw_bericht_is_verstuurd').fadeIn(300);
					break;
					
					case 'no_data' :
						alert('Ongeldige invoer');
					break;
				}
			},
			url : 'php/form_contact.php',
			type : 'post',
			clearForm: true
		};
		$('#contact_form').ajaxForm(form_options);
	}
};
