jQuery(document).ready(function($) {

	var hash;
		
	if ( window.location.hash ) {
		hash = window.location.hash;
	}

	if($.cookie('TEXT_SIZE')) {
		$('body').addClass($.cookie('TEXT_SIZE'));	
	}
	
	$('.controls .text a').click(function() {
		var textSize = $(this).attr('class');
		$('body').removeClass('small large').addClass(textSize);
		$.cookie('TEXT_SIZE',textSize, { path: '/', expires: 10000 });
		return false;
	});
	
	$('.controls .print a').click(function() {
		window.print();
		return false;
	});
	
	$('.external').attr('target','_blank');

	if ($("#feature-carousel").length != 0) {

		var n = parseInt($("#feature-carousel li").length) - 1;
		var c = $("#feature-carousel").carouFredSel({
			auto		: {
				delay			: 3000,
				pauseDuration	: 5000
			},
			items       : 1,
			direction   : "left",
			scroll		: {
				items			: 1,
				onBefore		: function(oldItems, newItems) {
					$("#feature-carousel-pagination li:lt(" +  c.current_position()  + ")").addClass("passed");
					$("#feature-carousel-pagination li:gt(" +  c.current_position()  + ")").removeClass("passed");
					$('.progress .status').animate({
						width: (( c.current_position() / n ) * 100 ) + "%"
					}, 250, function() {
					});
				},
				pauseOnHover 	: "resume"
			},
			pagination : {
				container       : "#feature-carousel-pagination div ul",
				anchorBuilder   : function(nr) {
					return "<li><a href=\"#\">"+nr+"</a></li>";
				}
				
			}
		});
		
	}
	
	if ($("#gallery").length != 0) {

		$('#gallery').carouFredSel({
			auto		: true,
			circular	: true,
			infinite	: true,
			items		: {
				height			: 115,
				visible			: 5,
				width			: 160,
				minimum			: 1
			},
			padding		: [0, 40],
			prev		: "#gallery-carousel-previous",
			next		: "#gallery-carousel-next",
			scroll 		: {
				items			: 1,
				pauseOnHover	: true
			},
			width		: 620
		});
		
		$('#gallery a').each(function(index,element) {
			
			$(this).fancybox({
				cyclic			: true,
				href			: this.href,
				titlePosition	: 'over',
				titleFormat		: function(title, currentArray, currentIndex, currentOpts) {
					var title = title.split(' - ', 2);
					return '<div id="fancybox-title-over"><strong style="font-weight: bold;">' + title[0] + '</strong><br />' + title[1] + '</div>';
				},
				onStart: function() {
					$('#gallery a').removeClass('active');
					$(element).addClass('active');
					setTimeout(function() {
						$('#gallery').trigger('pause');
					}, 100);
				},
				onClosed: function() {
					setTimeout(function() {
						$('#gallery').trigger('slideTo', [index, 0, true]);
					}, 100);
				}
			});
		});
		
	}

	if ($("#map").length != 0) {
		var latLng = new google.maps.LatLng(-27.486154,152.990552);
		var options = {
			zoom: 16,
			center: latLng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		var map = new google.maps.Map(document.getElementById("map-inner"), options);
		var image = '/assets/marker.png';
		var marker = new google.maps.Marker({
			position: latLng,
			map: map,
			icon: image
		});
	}
	
	if ($("#contact").length != 0) {
		
		if ( hash == "#contact-error" ) {
			$("#security-check").addClass("error").focus();
		}
		
		$("#contact").validate({ 
			rules: { 
				contactName: {
					required: true	
				}, 
				contactEmail: { 
					required: true, 
					email: true 
				},
				contactPhone: {
					required: true
				},
				contactMessage: {
					required: true
				},
				"security_code" : {
					required: true
				}
			}, 
			errorPlacement: function(error, element) { 
			   error.appendTo( element.parent() ); 
			}, 
			success: function(label) { 
				label.html(" ").addClass("checked"); 
			} 
		}); 	
	}

});
