/* Contents ***

	0. FLIR
	1. Banner Cycle
	2. Navigation Lava
	3. Mission Cycle
	4. Case Study Cycle
	5. Magnifier Colorobx
	6. Bulletin Coloroboxes
	7. Contact
	8. Magnifier Animation
	9. Google Maps API
	
***/


$(document).ready(function(){

/* 0. FLIR ***
***/
	
//	FLIR.init({ path: '/facelift/' });
	
//	FLIR.auto(); 
		
//	FLIR.replace(
//		'h3', new FLIRStyle({ 
//			cFont: 'dinmedium' 
//		}) 
//	);

//	FLIR.replace(
//		'h5', new FLIRStyle({ 
//			cFont: 'dinmedium' 
//		}) 
//	);
//
	
/* 1. Banner Cycle ***
***/
	
	$(function() {
	    $(".mood").cycle({
			fx:     'fade', 
		    timeout: 7000
	    });
	});

	$(function() {
	    $(".food").cycle({
			fx:     'fade', 
			timeout: 0, 
			pager: '#pager', 
			pagerEvent: 'click', 
			pagerAnchorBuilder: function(idx, slide) {
				return '#pager li:eq(' + idx + ') a'; 
			}
	    });
	});
	

/* 2. Navigation Lava ***
***/

	$(function() {
	    $(".lava").lavaLamp({
	        fx: "easeOutBack",
	        speed: 1000
	    });
	});
	

/* 3. Feature/Mission Cycle ***
***/
	
	$(function() {
	    $(".testimonials").cycle({
			fx:     'fade', 
		    timeout: 21000,
		    delay: -2000
	    });
	});


/* 4. Case Study Cycle ***
***/
	
	$(function() {
	    $(".casestudy_images").cycle({
			fx:     'fade', 
			pause: 1, 
		    timeout: 7000
	    });
	});
	
	
/* 5. Magnifier Colorobox ***
***/

	$(".colorbox").colorbox({
		opacity: .5,
		transition: "elastic",
		slideshow: true,
		slideshowAuto: false,
		slideshowSpeed: 5000
	});
	
	
/* 6. Bulletin Coloroboxes ***
***/

	$(".news1").colorbox({
		opacity: .5, 
		width: "50%", 
		maxWidth: "600px", 
		inline: true, 
		href: "#news1" 
	});
	
	$(".news2").colorbox({
		opacity: .5, 
		width: "50%", 
		maxWidth: "600px", 
		inline: true, 
		href: "#news2"
	});

	$(".news3").colorbox({
		opacity: .5, 
		width: "50%", 
		maxWidth: "600px", 
		inline: true, 
		href: "#news3" 
	});
	
	$(".news4").colorbox({
		opacity: .5, 
		width: "50%", 
		maxWidth: "600px", 
		inline: true, 
		href: "#news4" 
	});

	$(".news5").colorbox({
		opacity: .5, 
		width: "50%", 
		maxWidth: "600px", 
		inline: true, 
		href: "#news5" 
	});

	$(".news6").colorbox({
		opacity: .5, 
		width: "50%", 
		maxWidth: "600px", 
		inline: true, 
		href: "#news6" 
	});


/* 7. Contact ***
***/
	
	// set options
	var contact_options = {
		beforeSubmit: function() {
		}, 
		success: function(response) {
			if(response == "success") {
				$("#contact_form").resetForm();
				$("#contact_response").html("Thank you. Your message has been successfully sent. You will also receive a copy of the message in your inbox. We will contact you promptly.");
			}
		}
	};
	
	// fire jquery.form.js 
	$('#contact_form').ajaxForm(contact_options); 
	

/* 8. Magnifier Animation ***
***/
	
	// add .hover to folio mags on :hover
	$(".folio li").hover(
		function(){
			$(this).addClass("hover");
		},
		function(){
			$(this).removeClass("hover");
		}
	);

	// animate folio magnifier
	if (jQuery.browser.safarid){
		$("body").addClass("safari");
	} else {
		var speed = 500;
		var animating = false;
		var ulhovered = false;
		var entered = null;
		var moved = false;
		
		var still = function(li){
			var li = li;
			window.setTimeout(
				function() {
					// still hovering this element?
					if (li && $(li).hasClass("hover")){
						return;
					}
					var hovered = $(".folio li.hover");
					// hovering another element?
					if (hovered.length){
						hovered.trigger("mouseenter");
					}
					// not hovering anything?
					else if (ulhovered){
						$(".folio ul").trigger("mouseleave");
					}
				},
				10
			);
		}
		
		$(".folio li").bind(
			"mousemove",
			function(){
				moved = true;
			}
		).bind(
			"mouseenter",
			function(){
				var that = this;
				entered = this;
				var interval = window.setInterval(
					function() {
						if (!moved && entered == that){
							window.clearInterval(interval);
							$(that).trigger("mouseenterstill");
						} else if ( entered != that ){
							window.clearInterval(interval);
						}
						moved = false;
					},
					60
				);
			}
		).bind(
			"mouseenterstill",
			function() {
				if (animating){
					return;
				}
				animating = true;
				var that = this;
				$(this).animate(
					{
						width: 453
					},
					speed,
					function(){
						animating = false;
						still(that);
					}
				);
				$(".folio li:not(.hover) img").animate(
					{
						marginLeft: -150
					},
					speed
				);
				$(".folio li.hover img").animate(
					{
						marginLeft: 7
					},
					speed
				);
				$(".folio ul").animate(
					{
						paddingLeft: 0
					},
					speed
				);
				$(".folio li:not(:animated)").each(
					function() {
						$(this).animate(
							{
								width: 100
							},
							speed
						);
					}
				);
			}
		);
		
		$(".folio ul").bind(
			"mouseenter",
			function(){
				ulhovered = true;
			}
		).bind(
			"mouseleave",
			function(){
				if (animating) {
					return;
				}
				animating = true;
				ulhovered = false;
				$("li", this).animate(
					{
						width: 100
					},
					speed
				);
				window.setTimeout(
					function() {
						animating = false;
						still();
					},
					speed
				);
				$(".folio li img").animate(
					{
						marginLeft: -150
					},
					speed
				);
				$(this).animate(
					{
						paddingLeft: 176
					},
					speed
				);
			}
		);
	}
	
/* 9. Google Maps API ***
***/
		    
	if (GBrowserIsCompatible()) { 
		
		// Marker Function & Listener
		function createMarker(point, html) {
			var marker = new GMarker(point);
			GEvent.addListener(marker, "click", function() {
				marker.showMapBlowup({zoomLevel: 17});
			});
			GEvent.addListener(marker, "dblclick", function() {
				marker.hide();
			});
			return marker;
		}
		
		// Map & Controls & Location
		var map = new GMap2(document.getElementById("map_canvas"));
		map.addControl(new GSmallZoomControl3D());
		map.addControl(new GMenuMapTypeControl());
		map.setCenter(new GLatLng(-33.885861,151.172347), 12);
		
		// Create Marker 
		var point = new GLatLng(-33.885861,151.172347);
		var marker = createMarker(point,'Tiller Location')
		map.addOverlay(marker);
		
	}
		
});
