// Custom Javascript for Hartmark.com
// Copyright 2009 Matthew Baker, http://www.mjbaker.com

// Begin hoverIntent code, thank you for this!
// <http://cherne.net/brian/resources/jquery.hoverIntent.html>

(function($) {
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
})(jQuery);

//End hoverIntent code, thanks again!

/* Copyright (c) 2006-2007 Mathias Bank (http://www.mathias-bank.de)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * 
 * Version 2.1
 * 
 * Thanks to 
 * Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.
 * Tom Leonard for some improvements
 * 
 */
jQuery.fn.extend({
/**
* Returns get parameters.
*
* If the desired param does not exist, null will be returned
*
* To get the document params:
* @example value = $(document).getUrlParam("paramName");
* 
* To get the params of a html-attribut (uses src attribute)
* @example value = $('#imgLink').getUrlParam("paramName");
*/ 
 getUrlParam: function(strParamName){
	  strParamName = escape(unescape(strParamName));
	  
	  var returnVal = new Array();
	  var qString = null;
	  
	  if ($(this).attr("nodeName")=="#document") {
	  	//document-handler
		
		if (window.location.search.search(strParamName) > -1 ){
			
			qString = window.location.search.substr(1,window.location.search.length).split("&");
		}
			
	  } else if ($(this).attr("src")!="undefined") {
	  	
	  	var strHref = $(this).attr("src")
	  	if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	  		qString = strQueryString.split("&");
	  	}
	  } else if ($(this).attr("href")!="undefined") {
	  	
	  	var strHref = $(this).attr("href")
	  	if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	  		qString = strQueryString.split("&");
	  	}
	  } else {
	  	return null;
	  }
	  	
	  
	  if (qString==null) return null;
	  
	  
	  for (var i=0;i<qString.length; i++){
			if (escape(unescape(qString[i].split("=")[0])) == strParamName){
				returnVal.push(qString[i].split("=")[1]);
			}
			
	  }
	  
	  
	  if (returnVal.length==0) return null;
	  else if (returnVal.length==1) return returnVal[0];
	  else return returnVal;
	}
});

//Random Number Function

jQuery.extend({
	random: function(X) {
	    return Math.floor(X * (Math.random() % 1));
	},
	randomBetween: function(MinV, MaxV) {
	  return MinV + jQuery.random(MaxV - MinV + 1);
	}
});

//End Random Number Function

$(document).ready(function() {
					   		
							$('.footerLink a').hover(function() {
															  $(this).stop();
															  $(this).animate({'color' : '#999', 'fontSize' : '14px'}, 250);
															  }, 
															  function () {
																  $(this).stop();
																$(this).animate({'color' : '#333', 'fontSize' : '12px'}, 250);  
															   });
							$('#rHomepage').click(function() {
														   window.opener='x';
														   window.close();
														   });
						 
						  $('#helomatt').click(function() {
							
								alert('removed');
								
														});
						   

						   
						 $('#Gtrad').animate({opacity: '.50'}, 200);
						 $('#Gcont').animate({opacity: '.50'}, 200);
 						

						 $('#Gcont').click(function() {
															
																													
																															   void(0);
																															   window.open('contemporary/gallery.php', '', 'fullscreen=yes, scrollbars=auto');																															
																															   return false;
																														
																
																															  
													});
						 $('#Gtrad').click(function() {
																															   void(0);
																															   window.open('traditional/gallery.php', '', 'fullscreen=yes, scrollbars=auto');																															
																															   return false;
													});
						 
						 $('#Gtrad').hoverIntent(function() {
														  	$('#Gcont').animate({width: '267px',opacity: '.25'}, 'fast');
															$(this).animate({width: '676px',opacity: '1.0'}, 'fast');
															$('#gatewayText1').css({visibility: 'visible'});
															$('#gatewayText1').animate({opacity: '1.0'}, 'fast');
															}, function() {
															$('#Gcont').animate({width: '471px',opacity: '.50'}, 'slow');
															$(this).animate({width: '471px',opacity: '.50'}, 'slow');
															$('#gatewayText1').animate({opacity: '0.0'}, 'slow');
															});
						 $('#Gcont').hoverIntent(function() {
														  	$('#Gtrad').animate({width: '263px',opacity: '.25'}, 'fast');
															$(this).animate({width: '680px',opacity: '1.0'}, 'fast');
															$('#gatewayText2').css({visibility: 'visible'});
															$('#gatewayText2').animate({opacity: '1.0'}, 'fast');
															
															$('#logo').css({backgroundPosition: '-178px 0px'});
															$('#logo').fadeIn('slow');
															
													
															
															}, function() {
															$('#Gtrad').animate({width: '471px',opacity: '.50'}, 'slow');
															$(this).animate({width: '471px',opacity: '.50'}, 'slow');
															$('#gatewayText2').animate({opacity: '0.0'}, 'fast');
															$('#logo').css({backgroundPosition: '0px 0px'});
															$('#logo').fadeIn('fast');
															});
						 
						 //Begin form handling
						 
						 $("#submit").click(function(){					   				   

		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var name = $("#Fname").val();
		if(name == '') {
			$('.conForm span:eq(0)').animate({color : '#700000'}, 500, function() { $('.conForm span:eq(0)').animate({color : '#f4f1f1'}, 500); });
			hasError = true;
		}
		
		var company = $("#Fcompany").val();
		if(company == '') {
$('.conForm span:eq(1)').animate({color : '#700000'}, 500, function() { $('.conForm span:eq(1)').animate({color : '#f4f1f1'}, 500); });
			hasError = true;
		}
		
		var email = $("#Femail").val();
		if(email == '') {
$('.conForm span:eq(2)').animate({color : '#700000'}, 500, function() { $('.conForm span:eq(2)').animate({color : '#f4f1f1'}, 500); });
			hasError = true;
		} 
		
		var phone = $("#Fphone").val();
		if(phone == '') {
			$('.conForm span:eq(3)').animate({color : '#700000'}, 500, function() { $('.conForm span:eq(3)').animate({color : '#f4f1f1'}, 500); });

			hasError = true;
		}
		
		var message = $("#Fmessage").val();
		if(message == '') {
			$('.conForm span:eq(4)').animate({color : '#700000'}, 500, function() { $('.conForm span:eq(4)').animate({color : '#f4f1f1'}, 500); });

			hasError = true;
		}
		
		
		
		if(hasError == false) {
			$("#Fname").attr("value","");
			$("#Fcompany").attr("value","");
			$("#Femail").attr("value","");
			$("#Fphone").attr("value","");
			$("#Fmessage").attr("value","");

			
			$.post("../sendemail.php",
   				{ name: name, company: company, email: email, phone: phone, message: message },
   					function(data){
								   
							$('#success').remove();
							$("#submit").after('<br /><br /><span id="success">Your message was sent successfully.</span>');											

   					}
				 );
		
		}
		
		return false;

	});	
						 
						 //End form handling
						 
						 });