jQuery.noConflict();
var $j = jQuery;
$j(function() {
	ui.init();
	map.init();
	contactForm.init();
	gallery.init();
	Cufon.replace("#NavigationPrimary ul li a", { fontSize: "42px", fontFamily: "JamesFajardo", forceHitArea: true });
	Cufon.replace(".cufon-james", { fontFamily: "JamesFajardo" });
	Cufon.replace(".cufon-metric", { fontFamily: "GetmetricSlab" });
	Cufon.replace(".c-2 h3.replace", { fontFamily: "GetmetricSlab" });
	Cufon.replace("#Footer h4", { fontSize: "20px", fontFamily: "GetmetricSlab" });
	// Asked to loose this for readabilty ----> Cufon.replace("#Footer .address", { fontFamily: "JamesFajardo", fontSize: "30px" });
	Cufon.replace("#Footer .footer-email", { fontFamily: "GetmetricSlab", fontSize: "14px" });
	$j('#BackToTop').click(function(){
		$j.scrollTo('#Container',900);
		return false;
	});
	//Fancybox
	$j('a#single_image').fancybox(); 
	$j('a.group').fancybox(); 
	footer.init();
});
valueReplace = function(){
	var o = {};
	function init(){
		o.fields = $j('.value-replace');
		o.values = {};
		o.fields.each(function(){
			if($j(this).is("INPUT")) { $j(this).attr("title",$j(this)[0].value); textinputReplace($j(this)); }
			if($j(this).is("TEXTAREA")) { $j(this).attr("title",$j(this)[0].value); textareaReplace($j(this)); }
		});
	}
	function textinputReplace($e){
		$e.focus(function(){
			if($e[0].value == $e.attr("title") ){ 
				$e[0].value = "";
			}
		});
		$e.blur(function(){
			if($e[0].value == "" || $e[0].value === undefined) {
				$e[0].value = $e.attr("title");
			}
		});
	}
	function textareaReplace($e){
		$e.focus(function(){
			if($e[0].value == $e.attr("title") ){
				$e[0].value = '';
			}
		});
		$e.blur(function(){
			console.log($e.html());
			if($e[0].value == "" || $e[0].value === undefined || $e[0].value === null) {
				$e[0].value = $e.attr("title");
			}
		});
	}
	return { init:init };
}();
ui = function(){
	var config = {};
	var o = {};
	function init(){
		navigation();
		viewingForm();
		expanders();
	}
	function expanders(){
		$j('.show-more').click(function(){
			if ($j(this).hasClass('open') === false){
				$j($j(this).attr('href')).slideDown("slow");
				$j(this).addClass('open');
				$j(this).html('Show less');
			} else {
				$j($j(this).attr('href')).slideUp("fast");
				$j(this).removeClass('open');
				$j(this).html('Show more');
			}
			return false;
		});
	}
	function navigation(){
		o.navItems = $j('#NavigationPrimary ul li a');
		o.navItems.hover(
			function(){
				$j(this).parent().addClass('hover');
			},
			function(){
				$j(this).parent().removeClass('hover');
			}
		);
	}
	function viewingForm(){
		o.detailsForm = $j('#BookAViewing form');
		o.detailsForm.validate();
	 	$j('input', o.detailsForm).focus(function(){
			$j(this).parent().addClass('field-hover');
			$j(this).attr('value','');
		});
		$j('input', o.detailsForm).blur(function(){
			$j(this).parent().removeClass('field-hover');
		});
		$j('textarea', o.detailsForm).focus(function(){
			$j(this).parent().addClass('field-hover');
			$j(this).html('');
		});
		$j('textarea', o.detailsForm).blur(function(){
			$j(this).parent().removeClass('field-hover');
		});
		var buttonSrc = '_client/images/global/submit-button-single.gif'
		var buttonSrcHover = '_client/images/global/submit-button-single-hover.gif'
		$j('#SubmitButton', o.detailsForm).hover(
			function(){
				$j(this).attr('src',buttonSrcHover);
			},
			function(){
				$j(this).attr('src',buttonSrc);
			}
		);
	}
	return { init: init };
}();
map = function(){
	var o = { details : {} };
	function init(){
		o.foundMap = $j('#Map');
		if(o.foundMap.size() > 0) { render(); }
	}
	function render(){
		o.centreLatLong = new google.maps.LatLng(51.746421,-0.47516);
		o.myOptions = {
		   zoom: 14,
			 center: o.centreLatLong,
		   mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		o.map = new google.maps.Map(document.getElementById("Map"), o.myOptions);
		generateMarker();
	}
	function generateMarker() {
		o.venueLatLong = new google.maps.LatLng(51.746421,-0.47516);
	  o.marker = new google.maps.Marker({
	  	position: o.venueLatLong,
	  	map: o.map,
			icon: '/_client/images/global/custom-marker.png'
	  });
		//o.map.panTo(o.marker.position);
	}
	return { init:init }
}();
contactForm = function(){
	var o = {};
	function init(){
		o.detailsForm = $j('#ContactForm form');
		if (o.detailsForm.size() > 0) {
			events();
			o.detailsForm.validate();
		}
	}
	function events(){
		$j('input', o.detailsForm).focus(function(){
			$j(this).parent().addClass('field-focus');
		});
		$j('input', o.detailsForm).blur(function(){
			$j(this).parent().removeClass('field-focus');
		});
		$j('.frow-text-full input', o.detailsForm).focus(function(){
			$j(this).parent().addClass('field-text-full-focus');
		});
		$j('.frow-text-full input', o.detailsForm).blur(function(){
			$j(this).parent().removeClass('field-text-full-focus');
		});
		$j('textarea', o.detailsForm).focus(function(){
			$j(this).parent().addClass('field-textarea-focus');
		});
		$j('textarea', o.detailsForm).blur(function(){
			$j(this).parent().removeClass('field-textarea-focus');
		});
		var buttonSrc = '_client/images/global/contact-form-submit.gif'
		var buttonSrcHover = '_client/images/global/contact-form-submit-hover.gif'
		$j('#SubmitButton', o.detailsForm).hover(
			function(){
				$j(this).attr('src',buttonSrcHover);
			},
			function(){
				$j(this).attr('src',buttonSrc);
			}
		);
	}
return { init: init };
}();
gallery = function(){
	var o = {};
	function init(){
		o.widget = $j('.gallery-grid');
		if(o.widget.size() > 0){
			render();
			events();
		}
	}
	function render(){
		o.items = $j('.row ul li',o.widget);
		o.itemsLinks = $j('.row ul li a',o.widget);
		
	}
	function events(){
		o.items.hover(
			function(){
				o.items.removeClass('selected');
				$j(this).addClass('hover');
			},
			function(){
				o.items.removeClass('hover');
			}
		);
		o.itemsLinks.click(function(){
			o.items.removeClass('selected');
			$j(this).parent().addClass('selected');
			startTimer();
		});
	}
	function startTimer(){
		if (o.timer) { window.clearTimeout(o.timer); }
		o.timer = window.setTimeout(function(){
			$j('.selected').animate({backgroundColor:'#312e2e'},800,function(){ $j(this).removeAttr('style'); o.items.removeClass('selected'); });
			
		},3000);
	}
	return { init:init }
}();
footer = function(){
	var o = {};
	function init(){
		o.widget = $j('#GallerySnap');
		o.image = $j('.gallery-snap',o.widget);
		o._link = $j('a',o.widget);
		events();
	}
	function events(){
		o._link.hover(
			function(){ o.image.addClass('gallery-snap-hover'); },
			function(){ o.image.removeClass('gallery-snap-hover'); }
		)
	}
	return { init:init }
}();
