var ie=function(){for(var a=3,b=document.createElement("div"),d=b.getElementsByTagName("i");b.innerHTML="<\!--[if gt IE "+ ++a+"]><i></i><![endif]--\>",d[0];);return 4<a?a:void 0}(),previous_page_id=null,start_page=!1,photos=[],dark_colour=null,light_colour=null,content_copy=null,content_title=null,content_header=null,light_colour=null,app_data={},items=items,current_item=null,total_items=null,loaded_items=[],req_item=null,view_state=null,previous_view_state=null,window_height=$(window).height(),
window_width=$(window).width(),page_ids_with_no_text=[],thumbnails_load_position=null,thumbnails_load_start=null,thumbnails_load_max=30;if("undefined"==typeof console)this.console={log:function(){}};$(document).ready(function(){$.getJSON(base_url+"content",function(a){app_data.content=a.content;app_data.files=a.files;app_data.custom_fields=a.custom_fields;init()}).error(function(){})});
function init(){update_classnames_to_match_page_ids();pages_with_no_text();lis=$(".tnv").html();$("#tnvdp").empty().append(lis);$("#tnvdp li, #tnvdp li a").css("float","left");navigation_listeners();$.address.init(function(){if(null==current_item||NaN==current_item)current_item=0}).change(function(){do_state_change();"Share"==view_state&&update_share_location()});ti=app_data.content.length;for(i=0;i<ti;i++)if(9==app_data.content[i].page_id)contact_content=app_data.content[i].page_content,contact_content=
entities_to_characters(contact_content);$("#cnct").html(contact_content);do_state_change();update_share_location()}
function navigation_listeners(){$(".lt").click(function(a){("Photographs"==view_state||"Fullscreen"==view_state||"Share"==view_state)&&set_photo_array_position("l");a.preventDefault()});$(".rt").click(function(a){("Photographs"==view_state||"Fullscreen"==view_state||"Share"==view_state)&&set_photo_array_position("r");a.preventDefault()});$(".ths").click(function(a){$.address.path("thumbnails/"+page_id+"/"+current_item);a.preventDefault()});$(".txt").click(function(a){$.address.path("text/"+page_id+
"/"+current_item);a.preventDefault()});$(".phts").click(function(a){$.address.path("photographs/"+page_id+"/"+current_item);a.preventDefault()});$(".fs").click(function(a){"Fullscreen"==view_state?$.address.path("photographs/"+page_id+"/"+current_item):$.address.path("fullscreen/"+page_id+"/"+current_item);a.preventDefault()});$(".shar").click(function(a){"Share"==view_state?$.address.path("photographs/"+page_id+"/"+current_item):$.address.path("share/"+page_id+"/"+current_item);a.preventDefault()});
$(".nv a").click(function(a){id_from_class=$(this).parent().attr("class");id_from_class=id_from_class.replace("pid_","");previous_page_id=page_id;page_id=id_from_class;items=$.address.pathNames(1);1<=items.length&&(current_item=parseInt(items[2]));vs=view_state.toLowerCase();9==page_id&&(vs="photographs");nu=vs+"/"+page_id+"/0";$.address.path(nu);a.preventDefault()});$(".hlnk").click(function(a){nu="photographs/"+page_id+"/0";$.address.path(nu);a.preventDefault()});$(".stxt").click(function(a){nu=
"text/"+page_id+"/0";$.address.path(nu);a.preventDefault()});$(".sph").click(function(a){nu="photographs/"+page_id+"/0";$.address.path(nu);a.preventDefault()});$(document).keydown(function(a){if(("Photographs"==view_state||"Fullscreen"==view_state||"Share"==view_state)&&9!=page_id)37==a.keyCode&&set_photo_array_position("l"),39==a.keyCode&&set_photo_array_position("r")})}
function do_state_change(){previous_view_state=view_state;url_path=$.address.path();-1<url_path.search(/thumbnails/i)&&(view_state="Thumbnails");-1<url_path.search(/text/i)&&(view_state="Text");-1<url_path.search(/photographs/i)&&(view_state="Photographs");-1<url_path.search(/fullscreen/i)&&(view_state="Fullscreen");-1<url_path.search(/share/i)&&(view_state="Share");null==view_state&&(view_state="Photographs");items=$.address.pathNames(1);1<=items.length&&(current_item=parseInt(items[2]));1<=items.length&&
(page_id=parseInt(items[1]));page_id!=previous_page_id&&update_content_vars();switch_view();("Photographs"==view_state||"Fullscreen"==view_state||"Share"==view_state)&&9!=page_id&&update_photo()}function update_classnames_to_match_page_ids(){ti=app_data.content.length;c=0;$(".nv li").each(function(){$(this).removeClass();short_title=$(this).children(0).html();for(i=0;i<ti;i++)short_title==app_data.content[i].page_short_title&&(ncn="pid_"+app_data.content[i].page_id,$(this).addClass(ncn))})}
function update_content_vars(){$(".photos").empty();loaded_items.length=0;null==previous_page_id&&(previous_page_id=page_id);ti=app_data.content.length;for(i=0;i<ti;i++)if(app_data.content[i].page_id==page_id)start_page=0==app_data.content[i].page_order?!0:!1,content_copy=app_data.content[i].page_content,content_title=app_data.content[i].page_short_title,content_header=app_data.content[i].page_title,template=app_data.content[i].page_template;photos.length=0;ti=app_data.files.length;for(i=c=0;i<ti;i++)app_data.files[i].page_id==
page_id&&(photos[c]=[app_data.files[i].file_label,app_data.files[i].file_url,app_data.files[i].file_width,app_data.files[i].file_height],c++);ti=app_data.custom_fields.length;for(i=0;i<ti;i++)app_data.custom_fields[i].page_id==page_id&&"Dark Colour"==app_data.custom_fields[i].cf_label&&(dark_colour="#"+app_data.custom_fields[i].cr_value),app_data.custom_fields[i].page_id==page_id&&"Light Colour"==app_data.custom_fields[i].cf_label&&(light_colour="#"+app_data.custom_fields[i].cr_value);if(!0==start_page)rn=
Math.floor(Math.random()*c),ri=photos[rn],photos.length=0,photos[0]=ri,dark_colour="#"+photos[0][0],$("h1").css("color",dark_colour);total_items=photos.length;if(10!=page_id){content=entities_to_characters(content_copy);paragraphs=content.split("</p>");ti=paragraphs.length;col_one_limit=ti/2-1;col_two=col_one="";for(i=0;i<ti;i++)i<col_one_limit?col_one+=paragraphs[i]+"</p>":col_two+=paragraphs[i]+"</p>";$("#cl1").html(col_one);$("#cl2").html(col_two)}colour="Text"==view_state?"#F8F1E9":dark_colour;
$(".br").stop().animate({backgroundColor:light_colour},1E3);$.address.title(content_header);$("h1").html(content_title).css("color",colour);"Text"==view_state&&($("#ct a").css("color",colour),$("body").stop().animate({backgroundColor:dark_colour},1E3));$("#sharing .hlnk").html("David Harriman <br />"+content_title)}
function update_selected(a){current_selected_item=$(".ds .s").text();current_selected_item!=a&&($(".ds .s").removeClass("s"),$(".ds").find('a:contains("'+a+'")').addClass("s"));colour="Text"==view_state?"#F8F1E9":"#676767";$(".nv li .s").css("color",colour);$(".nv li a").removeClass("s");$(".pid_"+page_id+" a").addClass("s");colour="Text"==view_state?"#F8F1E9":dark_colour;$(".nv .s, .ds .s").css("color",colour)}
function switch_view(){update_selected(view_state);"Text"==view_state&&view_state!=previous_view_state&&(show_text_view(),hide_previous_state());"Photographs"==view_state&&view_state!=previous_view_state&&(show_photographs_view(),hide_previous_state());"Fullscreen"==view_state&&view_state!=previous_view_state&&(show_fullscreen_view(),hide_previous_state());"Share"==view_state&&view_state!=previous_view_state&&(show_share_view(),hide_previous_state());"Thumbnails"==view_state&&view_state!=previous_view_state?
(load_thumbnails(),show_thumbnails_view(),hide_previous_state()):"Thumbnails"==view_state&&previous_page_id!=page_id&&load_thumbnails();update_icons();update_template();check_header_display()}function pages_with_no_text(){ti=app_data.content.length;for(i=c=0;i<ti;i++)if(""==app_data.content[i].page_content)page_ids_with_no_text[c]=app_data.content[i].page_id,c++}
function hide_pages_with_no_text(){ti=page_ids_with_no_text.length;$(".nv li").each(function(){class_name=$(this).attr("class");id_from_classname=class_name.replace("pid_","");for(i=0;i<ti;i++)id_from_classname==page_ids_with_no_text[i]&&$(this).css("visibility","hidden")})}
function show_pages_with_no_text(){ti=page_ids_with_no_text.length;$(".nv li").each(function(){class_name=$(this).attr("class");id_from_classname=class_name.replace("pid_","");for(i=0;i<ti;i++)id_from_classname==page_ids_with_no_text[i]&&$(this).css("visibility","visible")})}
function update_share_location(){$("#share").empty();items=$.address.pathNames(1);1<=items.length&&(current_item=parseInt(items[2]));url_loc=$.address.baseURL()+"/#share/"+page_id+"/"+current_item;share_options='<div style="margin-top: 5px"><a href="https://twitter.com/share" class="twitter-share-button" data-url="'+url_loc+'" data-text="David Harriman,  '+content_title+' Photographs" data-count="horizontal">Tweet</a><script type="text/javascript" src="//platform.twitter.com/widgets.js"><\/script></div>';
share_options+='<div style="margin-top: 5px"><iframe src="//www.facebook.com/plugins/like.php?href='+url_loc+'&amp;send=false&amp;layout=button_count&amp;width=250&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=26" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:26px;" allowTransparency="true"></iframe></div>';$("#share").html(share_options)}
function update_icons(){"Fullscreen"==view_state?$(".fs").css("backgroundPosition","-70px -46px"):$(".fs").css("backgroundPosition","-70px -10px");"Share"==view_state?$(".shar").css("backgroundPosition","-141px -46px"):$(".shar").css("backgroundPosition","-141px -10px");"Thumbnails"!=view_state?($(".lt").fadeIn(),$(".rt").fadeIn()):($(".lt").fadeOut(),$(".rt").fadeOut())}
function position_photo(){percentage_of_original=80;offset_x=0;"Share"==view_state&&(percentage_of_original=50,offset_x=100);array_id=$("#photosdp .selected").attr("class");void 0!=array_id&&(array_id=array_id.replace("photo hd p",""),array_id=array_id.replace(" selected",""),photo_original_w=photos[array_id][2],photo_original_h=photos[array_id][3],max_width=photo_original_w,max_height=photo_original_h,min_width=percentage_resize(photo_original_w,50),min_height=percentage_resize(photo_original_h,
50),photo_height=Math.round(window_height/100*percentage_of_original),photo_height<min_height&&(photo_height=min_height),photo_height>max_height&&(photo_height=max_height),percentage_of_orginal=Math.round(100*(photo_height/photo_original_h)),photo_width=percentage_resize(photo_original_w,percentage_of_orginal),photo_width<min_width&&(photo_width=min_width),photo_width>max_width&&(photo_width=max_width),$("#photosdp").width(photo_width),$("#photosdp").height(photo_height),$("#photosdp .selected img").width(photo_width),
$("#photosdp .selected img").height(photo_height),$(".photos").width(photo_width),$(".photos").height(photo_height),photo_y=window_height/2-photo_height/2,photo_x=window_width/2-photo_width/2-offset_x,50>photo_y&&(photo_y=50),$("#photosdp").css("position","absolute"),$("#photosdp").css("top",photo_y),$("#photosdp").css("left",photo_x),ny=Math.round(photo_y-23),nx=Math.round(photo_x-35),"Fullscreen"==view_state&&"Fullscreen"==previous_view_state||"Share"==view_state&&"Share"==previous_view_state?$("#tnvdp").stop().animate({top:ny,
left:nx},500):($("#tnvdp").css("top",ny),$("#tnvdp").css("left",nx)),ny=Math.round(photo_y+20),nx=Math.round(photo_x+photo_width+10),"Share"==view_state&&"Share"==previous_view_state?$("#sharing").stop().animate({top:ny,left:nx},500):($("#sharing").css("top",ny),$("#sharing").css("left",nx)))}$(window).resize(function(){if("Share"==view_state||"Fullscreen"==view_state)window_height=$(window).height(),window_width=$(window).width(),position_photo()});
function check_header_display(){show_header=!1;0==current_item&&(show_header=!0);"Thumbnails"==view_state&&(show_header=!1);"Text"==view_state&&(show_header=!0);null==current_item&&(show_header=!0);!0==show_header?"Text"==view_state?$("h1").show():$("h1").fadeIn():$("h1").hide()}
function preload_photos(){null==current_item&&(current_item=0);load_current=load_previous=load_next=!0;target_class=null;prev_item=current_item-1;next_item=current_item+1;0>prev_item&&(prev_item=total_items-1);next_item>total_items-1&&(next_item=0);total_items_loaded=loaded_items.length;for(i=0;i<total_items_loaded;i++)loaded_items[i]==next_item&&(load_next=!1),loaded_items[i]==prev_item&&(load_previous=!1),loaded_items[i]==current_item&&(load_current=!1);!0==load_next&&(target_class="p"+next_item,
$(".photos").append('<a href="#" class="photo hd '+target_class+'"><img alt="'+photos[next_item][0]+'" /></a>'),array_id=next_item,ajax_photo(photos[next_item][1],target_class,85,1,array_id),loaded_items.push(next_item),add_photo_click_listener(target_class));!0==load_previous&&(target_class="p"+prev_item,$(".photos").append('<a href="#" class="photo hd '+target_class+'"><img alt="'+photos[prev_item][0]+'" /></a>'),array_id=prev_item,ajax_photo(photos[prev_item][1],target_class,85,1,array_id),loaded_items.push(prev_item),
add_photo_click_listener(target_class));!0==load_current&&(target_class="p"+current_item,$(".photos").append('<a href="#" class="photo hd '+target_class+'"><img alt="'+photos[current_item][0]+'" /></a>'),array_id=current_item,ajax_photo(photos[current_item][1],target_class,85,1,array_id),loaded_items.push(current_item),add_photo_click_listener(target_class))}
function add_photo_click_listener(a){$("."+a).click(function(a){1==total_items?(page_id_for_this_photo=page_id_for_photo(),$.address.path("photographs/"+page_id_for_this_photo+"/0")):("Photographs"==view_state||"Fullscreen"==view_state||"Share"==view_state)&&set_photo_array_position("r");a.preventDefault();return!1})}
function page_id_for_photo(){photo_url=photos[0][1];ti=app_data.files.length;for(i=0;i<ti;i++)photo_url==app_data.files[i].file_url&&10!=app_data.files[i].page_id&&(page_id_for_this_photo=app_data.files[i].page_id);return page_id_for_this_photo}function load_thumbnails(){$("#thumbnails").empty();thumbnails_load_position=0;load_thumbnail()}
function load_thumbnail(){null==thumbnails_load_position&&(thumbnails_load_position=0);thumbnails_load_position<total_items&&($("#thumbnails").append('<div class="thumbnail-wrap"><a href="#" class="thumbnail t'+thumbnails_load_position+'" style="opacity: 0"><img alt="'+photos[thumbnails_load_position][0]+'" /></a></div>'),ajax_photo(photos[thumbnails_load_position][1],"t"+thumbnails_load_position,14,0.5,thumbnails_load_position,!0),$("#thumbnails .thumbnail").hover(function(){$(this).stop().animate({opacity:"1"},
500)},function(){$(this).stop().animate({opacity:".6"},500)}),$("#thumbnails a").click(function(a){next_item=$(this).attr("class");current_item=next_item=next_item.replace("thumbnail t","");$.address.path("photographs/"+page_id+"/"+current_item);a.preventDefault()}))}
function ajax_photo(a,b,d,f,e,g){target="."+b+" img";9>ie&&(unique=(new Date).getTime(),a=a+"?random="+unique);$(target).attr("src",a).css("visibility","hidden").load(function(){w=photos[e][2];h=photos[e][3];"Photographs"==view_state&&(w>h?orientation="landscape":(orientation="portait",d=89.5));$("."+b+" img").width(percentage_resize(w,d));$("."+b+" img").height(percentage_resize(h,d));$("."+b).animate({opacity:f},500);e==current_item&&position_photo();$(this).hide().css("visibility","visible").fadeIn();
!0==g&&"Thumbnails"==view_state&&(thumbnails_load_position++,thumbnails_load_position<total_items&&load_thumbnail())})}function percentage_resize(a,b){return a=Math.round(a/100*b)}function resize_photo(a,b){p=100*((a-b)/a);p=100-p;return b}function update_photo(){preload_photos();$(".photos .selected").hide();$(".photos .selected").removeClass("selected");$(".p"+current_item).addClass("selected");$(".p"+current_item).fadeIn();position_photo()}
function set_photo_array_position(a){items=$.address.pathNames(1);1<=items.length&&(current_item=parseInt(items[2]));next_item=null;next_item=requested_array_position(a);nu=view_state.toLowerCase()+"/"+page_id+"/"+next_item;$.address.path(nu)}function requested_array_position(a){"l"==a&&(req_item=current_item-1);"r"==a&&(req_item=current_item+1);0>req_item&&(req_item=total_items-1);req_item>total_items-1&&(req_item=0);return req_item}
function update_template(){"template_photos_text"==template&&template_photos_text();"template_photos"==template&&template_photos();"template_homepage"==template&&template_homepage();"template_contact"==template&&template_contact()}function template_photos_text(){items="Text"==view_state?".txt, .ths, .phts":".txt, .ths, .phts, .nvs, .tnv";$(items).fadeIn();$("#cnct").hide();$(".stxt").show()}function template_photos(){$(".ths, .phts, .tnv").fadeIn();$("#cnct, .stxt").hide();$(".txt").fadeOut()}
function template_homepage(){$(".txt, .ths, .phts, .tnv").fadeOut();$("#cnct").hide()}function template_contact(){$(".txt, .ths, .phts, .tnv").hide();$("#cnct").fadeIn()}
function show_photographs_view(){$(".photos").css("z-index",103);$(".ui, .br, .tnv").fadeIn();$(".fsp").hide();$("body").stop().animate({backgroundColor:"#fff"},1E3);$("a:not(.s), p, span").stop().animate({color:"#676767"},500);0==current_item&&$("h1").stop().animate({color:dark_colour},500);$(".s").css("color",dark_colour);show_pages_with_no_text()}function show_fullscreen_view(){$("#sharing").hide();$(".fsp").fadeIn();$(".ui").hide()}
function show_share_view(){$("#tnvdp").fadeIn();$("#sharing").fadeIn();$(".fsp").fadeIn();$(".ui").hide();$("a, p, span").stop().animate({color:"#676767"},500);$("body").stop().animate({backgroundColor:"#fff"},1E3)}function hide_previous_state(){"Text"==previous_view_state&&hide_text_view();"Thumbnails"==previous_view_state&&hide_thumbnails_view()}function hide_thumbnails_view(){"Text"==view_state?$(".tnv, .br, #thumbnails").hide():$("#thumbnails").hide()}
function show_thumbnails_view(){$(".photos").css("z-index",103);$(".ui").fadeIn();$(".fsp").hide();$(".photos .selected").hide();$("body").stop().animate({backgroundColor:"#fff"},1E3);$("a, p, span").stop().animate({color:"#676767"},500);$(".tnv, .br, #thumbnails").fadeIn();$(".s").stop().animate({color:dark_colour},500);show_pages_with_no_text()}function hide_text_view(){$("#ct").hide()}
function show_text_view(){$(".ui, #ct").fadeIn();$(".fsp").hide();$(".br, .tnv, .photos .selected").hide();$("body").stop().animate({backgroundColor:dark_colour},1E3);$("h1, a, p, span").stop().animate({color:light_colour},500);hide_pages_with_no_text()}function entities_to_characters(a){a=a.replace(/&lt;/gi,"<");a=a.replace(/&gt;/gi,">");a=a.replace(/&quot;/gi,'"');a=a.replace(/&amp;/gi,"&");return a=a.replace(/&ordm;/gi,"&#186;")};
