$(document).ready(function(){
	//Processing contact form, only for contact.php
	if ($("#requestcopy").length){
		$("#requestcopy").submit(function(){
				var str = $(this).serialize();
				$.ajax({
					type: "POST",
					url: "../inc/contact.php",
					data: str,
					success: function(msg){
						$("#note").ajaxComplete(function(event, request, settings){
							if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
							{
								result = '<div class="notification_ok">Your message has been sent. We will try to give the reply as soon as possible. Thank you!</div>';
								$("#fields").hide();
							}else{
								result = msg;
							}
				
							$(this).html(result);
				
						});
					}
				});
				return false;
			});
	}
	
		//Processing contact form, only for contact.php
	if ($("#contact-us").length){
		$("#contact-us").submit(function(){
				var str = $(this).serialize();
				$.ajax({
					type: "POST",
					url: "inc/contact.php",
					data: str,
					success: function(msg){
						$("#note").ajaxComplete(function(event, request, settings){
							if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
							{
								result = '<div class="notification_ok">Your message has been sent. We will try to give the reply as soon as possible. Thank you!</div>';
								$("#fields").hide();
							}else{
								result = msg;
							}
				
							$(this).html(result);
				
						});
					}
				});
				return false;
			});
	}
	
	$("a[rel=screenshots]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			
	var imgs=document.getElementsByTagName("img");
	for(i=0;i<imgs.length;i++)
	{
		imgs[i].onerror=function(){
			imgs[i].src="images/image-missing.png";
		}
	}
});
