﻿var fadeSpeed=650;var firstLoad=true;$(document).ready(function(){subheader();$("a.transition").click(function(event){event.preventDefault();var linkLocation=$(this).attr('href');var linkHash=linkLocation.substr(0,linkLocation.length-5);var pageTitle=$(this).attr('title');_gaq.push(['_trackPageview',linkLocation]);if($("#textWrapper").css("opacity")>0)
fadeContent(fadeSpeed,0);$("#loader").load(linkLocation+' #text',function success(response,status,xhr){loadContent(response,status,xhr,pageTitle,linkHash);});$.address.value(linkHash);});});$(window).resize(subheader);$.address.init().externalChange(function(event){checkPage();});function checkPage(){var hash=window.location.hash.substr(1);var sPath=window.location.pathname;var sPage=sPath.substring(sPath.lastIndexOf('/')+1);if(!firstLoad){if(hash.length==0&&sPage.length==0)
hash="/default";else if(hash.length==0)
hash=sPage.substr(0,sPage.length-5);}
if(!firstLoad||hash.length>0){$('.transition').each(function(){var href=$(this).attr('href');if(hash==href.substr(0,href.length-5)){fadeContent(0,0);$(this).click();return false;}});}
else{if(sPage=="web.aspx"||sPage=="game.aspx")
loadViewer();$("#textWrapper").fadeTo(0,0,function(){$("#textWrapper").fadeTo(fadeSpeed,1);});$("#pageTitle").fadeTo(0,0,function(){$("#pageTitle").fadeTo(fadeSpeed,1);});firstLoad=false;}}
function subheader(){var height=$(window).height()-520;height=height<185?185:height>393?393:height;$('.subheader .wrapper').height(height);}
function loadContent(response,status,xhr,pageTitle,hash){if(status=="error"){var msg="Sorry but there was an error: ";$("#error").html(msg+xhr.status+" "+xhr.statusText);alert(msg+xhr.status+" "+xhr.statusText);}
else{var wait=setInterval(function(){if(!$("#textWrapper").is(":animated")){clearInterval(wait);document.title=pageTitle+" - Danny Miller";$("#textWrapper").animate({height:$("#loader").height()});$("#textWrapper").html($("#loader").html());$("#pageTitle").html(pageTitle);fadeContent(650,1);if(hash=="/game"||hash=="/web")
loadViewer();else if(hash=="/contact")
$("#aspnetform").attr("action","/contact.aspx?sendMail=true");}},200);}}
function fadeContent(fadeSpeed,fadeValue){$("#textWrapper").fadeTo(fadeSpeed,fadeValue);$("#pageTitle").fadeTo(fadeSpeed,fadeValue);}
function loadViewer(){$(".main_image .desc").show();$(".main_image .block").animate({opacity:0.85},1);$(".image_thumb ul li:first").addClass('active');$(".image_thumb ul li").click(function(){var imgAlt=$(this).find('img').attr("alt");var imgTitle=$(this).find('a').attr("href");var imgDesc=$(this).find('.block').html();var imgDescHeight=$(".main_image").find('.block').height();if($(this).is(".active")){return false;}else{$(".main_image .block").animate({opacity:0,marginBottom:-imgDescHeight},250,function(){$(".main_image img").attr({src:imgTitle,alt:imgAlt});$(".main_image .block").html(imgDesc).animate({opacity:0.85,marginBottom:"0"},250);});}
$(".image_thumb ul li").removeClass('active');$(this).addClass('active');return false;}).hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});$("a.collapse").click(function(){$(".main_image .block").slideToggle();$("a.collapse").toggleClass("show");});}
