/**
* @projectDescription		flokje.nl - main Javascript file
*
* @author					Wouter Smit
* @version					1.0.4
* @modified					15-08-2011 - 15:43
*/
var flokje={currentPage:null,currentAlbumXML:null,currentBigImage:null,currentBigImageIndex:0,pages:{home:{label:"home",alias:"home"},portfolio:{label:"portfolio",alias:"portfolio"},press:{label:"press",alias:"press"},exhibitions:{label:"exhibitions",alias:"exhibitions"},about:{label:"about",alias:"about"},contact:{label:"contact",alias:"contact"}},loadContent:function(a){flokje.currentPage=a;$("#content").load("/pages/"+flokje.currentPage.alias+".html",flokje.onContentLoad);$(".menubutton").removeClass("active");$("#menubutton_"+a.alias).addClass("active");if(a==flokje.pages.home){$(window).bind("resize",flokje.resizeHome)}},onContentLoad:function(){flokje.fadeImages($(this))},loadAlbumXML:function(a){$.ajax({url:a+"?key="+Math.floor(Math.random()*99999),success:flokje.onAlbumXMLLoad})},onAlbumXMLLoad:function(c){var b=$(c);flokje.currentAlbumXML=b;flokje.currentBigImageIndex=0;var d="";var a="";b.find("photo").each(function(f){var e=$(this);d+='<div class="album_thumbnail'+(f%4==3?" right":"")+'">';d+='<a class="album_thumbnail_link" href="#" onclick="flokje.showBigPhoto('+f+');return false">';d+='<img src="/thumb/thumb.php?w=160&amp;h=160&amp;src='+e.find("src").text()+'" alt="">';d+="</a>";d+="</div>";a+='<a class="album_big_selector_thumbnail" href="#" onclick="flokje.showBigPhoto('+f+');return false">';a+='<img src="/thumb/thumb.php?h=52&amp;src='+e.find("src").text()+'" alt="">';a+="</a>"});d+='<a href="#" onclick="flokje.loadContent(flokje.pages.portfolio);return false" id="album_thumbnails_back">BACK TO PORTFOLIO</a>';$("#album_overview").hide();$("#album_thumbnails").html(d).fadeIn();$("#album_big_selector_thumbnails").html(a);flokje.fadeImages($("#album_thumbnails"))},showBigPhoto:function(a){var b=flokje.currentAlbumXML.find("photo").eq(a);flokje.currentBigImageIndex=a;$("#album_thumbnails").fadeOut("fast",function(){$("#album_big_wrapper").show();var d=$("#album_big_photo");var f=b.find("src").text();var e='<a href="#" onclick="flokje.nextBigPhoto();return false">';e+='<img src="'+f+'" alt="">';e+="</a>";$("#album_big_photo").hide().html(e);$("#album_big_title").html(b.find("title").text());var c=new Image();c.onload=function(){d.fadeIn();flokje.currentBigImage=this;flokje.resizeBig();flokje.currentFooterThumb=a;$("#album_big_selector_thumbnails").find(".album_big_selector_thumbnail").removeClass("active").eq(flokje.currentFooterThumb).addClass("active")};c.src=f});$(window).bind("resize",flokje.resizeBig)},previousBigPhoto:function(){var a=(flokje.currentAlbumXML.find("photo").eq(flokje.currentBigImageIndex-1).length?flokje.currentBigImageIndex-1:0);flokje.showBigPhoto(a)},nextBigPhoto:function(){var a=(flokje.currentAlbumXML.find("photo").eq(flokje.currentBigImageIndex+1).length?flokje.currentBigImageIndex+1:0);flokje.showBigPhoto(a)},hideBigPhoto:function(){$(window).unbind("resize",flokje.resizeBig);$("#album_big_wrapper").fadeOut("fast",function(){$("#album_thumbnails").fadeIn()})},fadeImages:function(a){a.find("img").each(function(){var c=$(this);c.hide();var d=this.src;var b=new Image();b.onload=function(){c.fadeIn();$(window).trigger("resize",this)};b.src=d})},resizeHome:function(j,c){var b=c||$("#home_photo").get(0);if(flokje.currentPage!=flokje.pages.home){return}var g=$("#home_photo");var f=b.width/b.height;var d=Math.max(100,($(window).height()-(164+30)));var a=Math.max(100,d*f);if(a>$(window).width()-20){a=$(window).width()-20;d=a/f}g.css({marginLeft:"-"+(a/2)+"px",width:a,height:d})},resizeBig:function(){var a=$("#album_big_photo").find("img");var d=flokje.currentBigImage.width/flokje.currentBigImage.height;var c=Math.max(100,($(window).height()-(164+130)));var b=Math.max(100,c*d);a.css({marginLeft:"-"+(b/2)+"px",width:b,height:c})}};$(function(){var a="";for(var b in flokje.pages){a+='<a href="?page='+b+'" id="menubutton_'+flokje.pages[b].alias+'" class="menubutton">'+flokje.pages[b].label.toUpperCase()+"</a>"}$("#menu").html(a);var c=(location.href.indexOf("?page=")!=-1)?location.href.split("?page=").pop():flokje.pages.home;flokje.loadContent(flokje.pages[c]||flokje.pages.home)});$(document).bind("mousedown mouseup contextmenu dragstart",function(a){if(a.which==3||a.type=="contextmenu"||a.type=="dragstart"){a.preventDefault&&a.preventDefault();return false}});


