
function show(url,label) {
	Shadowbox.open(
		{
			title: label,
			player: 'img',
			content: url
		});
}


$(document).ready(function(){
	$('a.light').lightBox({
		fixedNavigation : true
	}); // Select all links with lightbox class


	$('.equalBox').boxify();
	
	//LIGHTBOX
	
});

$(document).ready(function(){
	$('.nav').superfish();
});


$(document).ready(function() {

	$(".flowToggle").flowToggle(
		{
			//	DEFAULTS
			// showHideSelector : ".flowShowHide",
			// toggleText : "",
			// toggleTextAfter : "",
			// hideToggle : false

			showHideSelector : ".flowShowHide",
			toggleTextAfter : "Close this",
			hideToggle : true
		}
	);

});




$(document).ready(function() {

	//$('#promoSlide').children().hide();
	

	// FEATURE IMAGES DROP SHADOWS
	//******************

	$("img.shadow").wrap("<div class='shadow-outer'>" + "</div>");
	$("img.shadow").addClass("shadow-adjust");
	$("img.shadow.feature").parent().addClass('feature');

	// AWESOME FORMS
	//******************

	$('.im-an-awesomeform').removeClass('im-an-awesomeform').addClass('awesomeForm');
	
	// Select all textboxes and assign them to an array
	var textboxes = $('.awesomeForm .input-text');

	// Iterate through all textboxes in the form
	textboxes.each(function(index, input){

		var label = $(input).siblings('.overlay');

		$(label).wrapInner("<span></span>");
		
		
		$(label).children("span").css({'color':'#7D7D7D'});

		// check for autocomplete by browser
		if( index == 0 ){
		  setInterval(function(){
		     textboxes.each(function(index,inputX){
		      if( inputX.value!="" ) {
		        $(inputX).prev().children("span").css({'color':'#fff'});
		      }
		    });
		 }, 100);
		}

		// Fade the label back when a field gains focus     
		input.onfocus = function(){
		  if(input.value==""){
		    label.children("span").css({'color':'#BABABA'});     
		  }
		};

		// Check if a field is empty when the user switches out
		input.onblur = function(){
		  if(input.value==""){
		    label.children("span").css({'color':'#7D7D7D'});      
		  };
		};

		// Fade the label back if a field has text      
		if(input.value!="") {
		  label.addClass('hastext');
		};

		// Fade the label back when the user starts to type     
		input.onkeypress = function(){
		  label.children("span").css({'color':'#BABABA'});	
		};

		input.onkeyup = function(){
		  if(input.value==""){
		    label.children("span").css({'color':'#BABABA'});        
		  }
		};
	
	});


	/*-- JUST ANOTHE SLIDESHOW ----------------------*/
	//SLIDESHOWS
	var promoSlide = $('#promoSlide');
	var promoSlideImg = promoSlide.find('img');
	var h = $(promoSlideImg).height();
	var w = $(promoSlideImg).width();
	promoSlide.height(h);
	promoSlide.width(w);
	
	promoSlideCSS =	{
						'overflow': 'hidden',
						'background' : '#000 url(/theme/images/loaders/loader_1_black48.gif) center center no-repeat'
					};

	promoSlide.css(promoSlideCSS);	
	
	$('#promoSlide .slideItem').height(h).width(w);
	
	SlideCaptionCSS =	{
							'bottom': -1*$(this).height(),
							'opacity' : '0.7',
							'width' : '100%',
							'position' : 'absolute'
						};
						
	$('#promoSlide .slideCaption').each(function(){
		$(this).css(SlideCaptionCSS);
	});
	
	function onBefore() {
	}

	function onAfter() {
		sCaption = $(this).find('.slideCaption');
		sCaptionH = -1*sCaption.height();
		sCaption.show().animate({opacity: 0.7}, 500).animate({bottom: "0px"}, { queue:false, duration: 500 }).animate({opacity: 0.7}, 2000).animate({opacity: 0.0, bottom: sCaptionH}, 500);
	}

	function initSlideshowB(slideShow)
	{
		slideShow.find('img').fadeIn();
		promoSlide.css({'background' : 'none'});
		
		slideShow.cycle({
		    timeout: 5000, 
			fx: 'fade',
			speed: 1000,
			before: onBefore,
			after: onAfter,
			pause:   1
		});
	}
	
	function is_image_loaded(image) {
	    if(!image.complete) {
	        return false;
	    }
	    if(typeof image.naturalWidth != "undefined" && image.naturalWidth == 0) {
	        return false;
	    }
	    return true;
	};

	var first_slide = $('#promoSlide img:first');
	
	if(first_slide.length > 0){
		if(is_image_loaded(first_slide.get(0))){
			initSlideshowB($('#promoSlide'));
		} else {
		    first_slide.load(function(e) {
		        $('#loading').hide();
				initSlideshowB($('#promoSlide'));
		    });
		}
	}
	



});


function mapsLoaded() {
	//console.log('mapsLoaded');

	var iconRed = new google.maps.Icon(); 
	iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
	iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
	iconRed.iconSize = new google.maps.Size(12, 20);
	iconRed.shadowSize = new google.maps.Size(22, 20);
	iconRed.iconAnchor = new google.maps.Point(6, 20);
	iconRed.infoWindowAnchor = new google.maps.Point(5, 1);

	var customIcons = [];
	customIcons["broker"] = iconRed;

	if (google.maps.BrowserIsCompatible()) {
		//console.log('BrowserIsCompatible');

		var map = new google.maps.Map2(document.getElementById("map_canvas"));
		map.addControl(new google.maps.SmallMapControl());
		map.addControl(new google.maps.MapTypeControl());

		function createMarker(point, name, address, type, href) {
			//console.log(name);

			var marker = new google.maps.Marker(point, customIcons[type]);
			var html = "<b><a href='"+href+"'>" + name + "</a></b> <br/>" + address;
			google.maps.Event.addListener(marker, 'click', function() {
				marker.openInfoWindowHtml(html);
			});
			return marker;
		}


		google.maps.DownloadUrl(xmlPath, function(data) {
			//console.log('DownloadUrl');

			var xml = google.maps.Xml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("marker");
			var bounds = new google.maps.LatLngBounds();

			for (var i = 0; i < markers.length; i++) {
				var href = markers[i].getAttribute("href");

				var name = markers[i].getAttribute("name");
				var address = markers[i].getAttribute("address");
				var type = markers[i].getAttribute("type");
				var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
				var marker = createMarker(point, name, address, type, href);

				map.addOverlay(marker);
				bounds.extend(point);
				map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));

			}
		});
	}
}
