$(function(){
// embed flash
	$('#flash_wrapper').flash({
		src: 'swf/intro.swf',
		width: 1095,
		height: 560,
		wmode: 'transparent'
	});

	$('.history_flash').flash({
		src: 'swf/route1-loader.swf',
		width: 1000,
		height: 540,
		menu: 'false',
		bgcolor: '#FFFFFF',
		wmode: 'transparent'
	});

// cufon
	Cufon.replace('.tl_replaced', {
		fontFamily: 'United Serif',
		hover: true
	});
	Cufon.replace('h1:not(".no_replace")', { fontFamily: 'United Sans' });
	Cufon.replace('.tagline', { fontFamily: 'United Sans RM' });
	Cufon.replace('.point', { fontFamily: 'United Italic Rg Hv' });
	Cufon.replace('.lc_inner .se', { fontFamily: 'United Italic Rg Hv' });
	Cufon.replace('.privacy-policy h2', { fontFamily: 'United Sans' });

// submit hover
	$('.detail_search_f .find_btn')
		.mouseenter(function(){$(this).attr('src', $("#phpRoot").val() + 'images/take_me_there_over.png')})
		.mouseleave(function(){$(this).attr('src', $("#phpRoot").val() + 'images/take_me_there.png')})
	$('.attraction_f .find_btn_2')
		.mouseenter(function(){$(this).attr('src', $("#phpRoot").val() + 'images/find_btn_over.png')})
		.mouseleave(function(){$(this).attr('src', $("#phpRoot").val() + 'images/find_btn.png')})
	$('.support_f .submit_b')
		.mouseenter(function(){$(this).attr('src', $("#phpRoot").val() + 'images/submit_over.png')})
		.mouseleave(function(){$(this).attr('src', $("#phpRoot").val() + 'images/submit.png')})
// preload images
	jQuery.preLoadImages($("#phpRoot").val() + '/images/find_btn_over.png', $("#phpRoot").val() + '/images/take_me_there_over.png', $("#phpRoot").val() + 'images/submit_over.png');

// fancyBox
	$(".gallery a").fancybox({
		'transitionIn'       : 'elastic',
		'transitionOut'	     : 'elastic',
		'speedIn'            : 600,
		'speedOut'           : 200,
		'overlayShow'        : true,
		'padding'            : 0,
		'scrolling'          : 'no',
		'autoDimensions'     : false,
		'width'              : 784,
		'height'             : 396,
		'hideOnOverlayClick' : true,
		'overlayOpacity'     : 0.4,
		'type'               : 'iframe'
	});

// support form
	// input default values
	$('.name').defaultValue('Name');
	$('.city').defaultValue('City');
	$('.email').defaultValue('Email Address');

// custom checkboxes
	$('.attraction_f .checkboxes label')
		.prepend('<div class="faux_cbox"></div>');
	$('.attraction_f .check:checked').next().addClass('checked');
	$('.cbox').click(function(e){
		e.preventDefault()
		$(this).children('label').toggleClass('checked')
		$(this).children('input').attr('checked', !$(this).children('input').attr('checked'))
	})
// external links
	$("a[href^='http:']:not([href*='" + window.location.host + "'][target='_blank'])")
		.live('click', function(){
			$(this).attr('target','_blank');
		});


// print
	$('a.print').click(function(){
		window.print();
	});


//validation functionality
	if ($(".support_f").length > 0) {
		validation();
	}

});

//preload images
(function($) {
	var cache = [];
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
})(jQuery)



function validation(){
	//add class "required" to the required inputs ,selects and textareas, and class "email" to the email field
	input_val = new Array();
	select_val = new Array();
	$("input.required").each(function(){
		input_val.push($(this).val());
	});
	$("select.required").each(function(){
		select_val.push($(this).val());
	});
	$(".support_f").submit(function(){
		var input_index = 0;
		var select_index = 0;
		var errors = 0;
		$("input.required").each(function(){
			var current_val = $(this).val();
			if (current_val == '' || current_val == input_val[input_index]) {
				$(this).val(input_val[input_index]);
				$(this).addClass("error");
				errors++;
			} else {
				$(this).removeClass("error");
			}
			//required email
			if ($(this).hasClass("email")) {
				var email_value = $(this).val();
				if (email_value.indexOf("@") < 0 || email_value.indexOf(".") < 0) {
					$(this).addClass("error");
					errors++;
				}else {
					$(this).removeClass("error");
				}
			}
			input_index++;
		});
		$("select.required").each(function(){
			var current_val = $(this).val();
			if (current_val == '' || current_val == select_val[select_index]) {
				$(this).val(select_val[select_index]);
				$(this).addClass("error");
				errors++;
			} else {
				$(this).removeClass("error");
			}
			select_index++;
		});
		$("textarea.required").each(function(){
			var current_val = $(this).val();
			if (current_val == '') {
				$(this).addClass("error");
				errors++;
			} else {
				$(this).removeClass("error");
			}
		});

		if (errors > 0) return false;
	});
}


