//var sDomain	= 'http://www.thinco.nl/';

var sDomain	= 'http://localhost/stinstruments2010/';


function initialize() {
	var myLatlng = new google.maps.LatLng(51.935647,4.849004);
	var myOptions = {
	  zoom: 13,
	  center: myLatlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP,	  
	  mapTypeControl: false
	}
	var map = new google.maps.Map(document.getElementById('map'), myOptions);
	
	var image = new google.maps.MarkerImage(sDomain+'images/google.png',
		new google.maps.Size(225, 121),
		// The origin for this image is 0,0.
		new google.maps.Point(0,0),
		// The anchor for this image is the base of the flagpole at 0,32.
		new google.maps.Point(100, 75)
	);
	var marker = new google.maps.Marker({
		position: myLatlng, 
		map: map,
		icon: image
	}); 
}


//http://maps.google.nl/maps?f=q&source=s_q&hl=nl&geocode=&q=Energieweg+20b,+Groot-Ammers&sll=52.469397,5.509644&sspn=5.087614,14.227295&ie=UTF8&hq=&hnear=Energieweg+20A,+Groot-Ammers,+Liesveld,+Zuid-Holland&z=16

function scrolltotop() {
	$('html, body').animate({
		scrollTop:0
	}, 'slow');	
}


function slideCycle(){
	$('#items')
	.after('<div id="nav">')
	.cycle({
		fx:     'fade',
		timeout: 4500,
		speed:	 600,
		pager: '#nav'
	});
}

function remove_form()
{
		$('div.trigger').removeClass('close');
		$('div.trigger').addClass('open');
		$('div.trigger').next().slideUp(100);
}

function contactform () {
	$('#send_message').click(function(e){
		
		//stop the form from being submitted
		e.preventDefault();
		
		/* declare the variables, var error is the variable that we use on the end
		to determine if there was an error or not */
		var error = false;
		var email = $('#email').val();
		var firstname = $('#firstname').val();
		var lastname = $('#lastname').val();
	

		if(firstname.length == 0 || firstname == 'voornaam'){
		var error = true;
			$('#firstname_error').fadeIn(500);
		}else{
			$('#firstname_error').fadeOut(500);
		}

		if(lastname.length == 0|| lastname == 'achternaam'){
		var error = true;
			$('#lastname_error').fadeIn(500);
		}else{
			$('#lastname_error').fadeOut(500);
		}
					
		if(email.length == 0 || email.indexOf('@') == '-1'){
			var error = true;
			$('#email_error').fadeIn(500);
		}else{
			$('#email_error').fadeOut(500);
		}
		
		
		//now when the validation is done we check if the error variable is false (no errors)
		if(error == false){
			
			


		
			//disable the submit button to avoid spamming
			//and change the button text to Sending...
			$('#send_message').attr({'disabled' : 'true', 'value' : '' });
			
			/* using the jquery's post(ajax) function and a lifesaver
			function serialize() which gets all the data from the form
			we submit it to send_email.php */

			
			$.post(sDomain+"send_email.php", $("#contact_form").serialize(),function(result){
				//and after the ajax request ends we check the text returned
				if(result == 'sent'){
					
					setTimeout('remove_form()', 5000);

					$('.inputfield').remove();

					//if the mail is sent remove the submit paragraph
					 $('#cf_submit_p').remove();
					//and show the mail success div with fadeIn
					$('#mail_success').fadeIn(500);
				}else{
					//show the mail failed div
					$('#mail_fail').fadeIn(500);
					//reenable the submit button by removing attribute disabled and change the text back to Send The Message
					$('#send_message').removeAttr('disabled').attr('value', '');
				}
			});
		}
	});    			
}



function contactform2 () {
	$('#send_message').click(function(e){
		
		//stop the form from being submitted
		e.preventDefault();
		
		/* declare the variables, var error is the variable that we use on the end
		to determine if there was an error or not */
		var error = false;
		var email = $('#email').val();
		var firstname = $('#firstname').val();
		var lastname = $('#lastname').val();
		var companyname = $('#companyname').val();
		var phone = $('#phone').val();
		var message = $('#message').val();
	

		if(firstname.length == 0 || firstname == 'voornaam'){
		var error = true;
			$('#firstname_error').fadeIn(500);
		}else{
			$('#firstname_error').fadeOut(500);
		}

		if(lastname.length == 0|| lastname == 'achternaam'){
		var error = true;
			$('#lastname_error').fadeIn(500);
		}else{
			$('#lastname_error').fadeOut(500);
		}
					
		if(email.length == 0 || email.indexOf('@') == '-1'){
			var error = true;
			$('#email_error').fadeIn(500);
		}else{
			$('#email_error').fadeOut(500);
		}

		if(companyname.length == 0 || companyname == 'bedrijfsnaam'){
			var error = true;
			$('#companyname_error').fadeIn(500);
		}else{
			$('#companyname_error').fadeOut(500);
		}

		if(phone.length == 0 || phone == 'telefoon'){
			var error = true;
			$('#phone_error').fadeIn(500);
		}else{
			$('#phone_error').fadeOut(500);
		}

		if(message.length < 15 || message == 'bericht'){
			var error = true;
			$('#message_error').fadeIn(500);
		}else{
			$('#message_error').fadeOut(500);
		}
		
		//now when the validation is done we check if the error variable is false (no errors)
		if(error == false){

		
			//disable the submit button to avoid spamming
			//and change the button text to Sending...
			$('#send_message').attr({'disabled' : 'true', 'value' : '' });
			
			/* using the jquery's post(ajax) function and a lifesaver
			function serialize() which gets all the data from the form
			we submit it to send_email.php */

			
			$.post(sDomain+"send_form.php", $("#contact_form").serialize(),function(result){
				//and after the ajax request ends we check the text returned
				if(result == 'sent'){
					
					$('.inputfield').remove();


					//if the mail is sent remove the submit paragraph
					 $('#cf_submit_p').remove();
					//and show the mail success div with fadeIn
					$('#mail_success').fadeIn(500);
				}else{
					//show the mail failed div
					$('#mail_fail').fadeIn(500);
					//reenable the submit button by removing attribute disabled and change the text back to Send The Message
					$('#send_message').removeAttr('disabled').attr('value', '');
				}
			});
		}
	});    			
}

function loadFancybox(){				
	$("#fancy").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 880,
			'height'		: 695,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});

};

function loadFancybox2(){				
	$("#fancy2").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 880,
			'height'		: 695,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});

};

function loadFancybox3(){				
	$("#fancy3").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 880,
			'height'		: 695,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});

};


function loadFancybox4(){				
	$("#fancy4").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 880,
			'height'		: 695,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'iframe',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});

};

function sorteerWebsites(value) {
	var opts = value

	if(opts != 0)
	{
		sUrl = "?category_id="+opts;
	}
	else
	{
		sUrl = "";
	}

	$('.selectbox-wrapper ul li').click(function(){
		
		var sSorteer = $(this).attr('id');
		$.ajax({
			type: 'POST',
			url: sDomain+'modules/portfolio-ajax.php'+sUrl,
			data: 'sSorteer='+sSorteer,
			success: function(result){
				$('.cright').html(result);
				$('#sorteren').selectbox();
				sorteerWebsites(opts);
			}
		});
	});	
}


function noError(){return true;}
		window.onerror = noError;

