/* Author: Dave Mellett */

/* Google Web Fonts */
/* http://sixrevisions.com/css/font-face-web-fonts-issues/ */
/* Local fonts created using: http://www.fontsquirrel.com/fontface/generator */

WebFontConfig = {
	google: { families: [ 'UnifrakturMaguntia::latin', 'Sorts+Mill+Goudy::latin' ] },
    fontinactive: function (fontFamily, fontDescription) {
   //Something went wrong! Let's load our local fonts.
		WebFontConfig = {
			custom: { families: ['UnifrakturMaguntiaBook', 'SortsMillGoudyRegular'],
			urls: ['fonts/stylesheet-unifracktur.css', 'fonts/stylesheet-goudy.css']
			}
		};
		loadFonts();
	}
};

function loadFonts() {
	var wf = document.createElement('script');
	wf.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
	wf.type = 'text/javascript';
	wf.async = 'true';
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(wf, s);
}
(function() {
	//Once document is ready, load the fonts.
	loadFonts();

})();


/* hover 4 ie6 */
$("li, a").hover(
  function () {
    $(this).addClass("hover");
  },
  function () {
    $(this).removeClass("hover");
  }
);


/* hover 4 ipad */
$(".dropdown").toggle(
  function (e) {
    $(this).addClass("hover");
	e.preventDefault();
  },
  function (e) {
    $(this).removeClass("hover");
	e.preventDefault();
  }
);


/* Ajax loading of page content files */
/* Only for iTouch */

$("#nav li a:[href]").click(function(e) {

	if (false && Modernizr.touch) {	// DISABLED - BEHAVIOUR NOT SUITABLE
									// Url does not change in iPad safari window

		var file = $(this).html().toLowerCase();
		var name = file.split(" ",1);
	
		if (name == "directions" || name == "fair") {
			return;
		}
		
		if ($(this).hasClass("dropdown")) {
			return;
		}

		file = "" + name + ".html";

		e.preventDefault();
		
		$('#content').load(file, function(response, status, xhr) {
			if (status == "error") {
				var msg = "Sorry but there was an error: ";
				$('#content').html(msg + xhr.status + " " + xhr.statusText);
			} else {
				$(".shadow").addClass("ipadfix");
				$("#more").hide();
				$("#morepics").hide();
				$("#readmore").show();
			}
		});
	}
});

$(document).ready(function(){

	/* Tabs on History Fair page */

	
	$("body").delegate("#tabs-titles li", "click", function(){
		$('#tabs-contents li').hide(); 						//hide all contents
		$('#tabs-titles li').removeClass('current'); 		//remove 'current' classes
		$($('#tabs-contents li')[$(this).index()]).show();	//show tab content that matches tab title index
		$(this).addClass('current'); 						//add current class on clicked tab title
	});
	
	$($('#tabs-contents li')[0]).show();					//show first tab content by default
	
	
	/* Read more on Behind the Scenes page */

	$("#more").hide();
	$("#morepics").hide();
	$("#readmore").show();
	$("body").delegate("#readmore", 'click', function(){
		$("#more").show();
		$("#morepics").show();
		$("#readmore").hide();
	});
	
	/* Fix iPad jagged edges on rotated images */
	if (Modernizr.touch) {
		$(".shadow").addClass("ipadfix");
	}
	
});

