/*
 *  @Author: Kevin R. Whitley
 *  @Codebase: PHP5.3, JS, jQuery, MySQL
 *
 *  Gallery designed, styled, coded, etc by Kevin R. Whitley.  EXIF scanning included.  For more information, contact Kevin Whitley.
 */

var slider={padding:5,slideWidth:0,width:function(){return $("#filmstrip").width();},offset:function(){return $("#filmstrip").offset().left;},height:400,slide:function(index){var slidePadding=5;var offset=$("#filmstrip div").position().left;var image=this.images[index];var omega=(-image.offset+this.width()/2-image.swidth/2)+"px";$("#filmstrip div").stop().animate({"left":omega},100);return this;},velocity:{current:30,min:30,max:200,},move:function(accel){var v=this.velocity;if(!accel){accel=0;}else{accel*=1.1;}
v.current+=accel;if(v.current<v.min){v.current=v.min;accel=0;}else if(v.current>v.max){window.clearTimeout(this.timer);accel=0;return this;}
$("#filmstrip div").css("left",$("#filmstrip div").position().left-1+"px");this.timer=window.setTimeout(function(accel){slider.move(accel)},v.current,accel);return this;},stop:function(){window.clearTimeout(this.timer);return this;},setSpeed:function(v){this.velocity.current=v;return this;},timer:null}
String.prototype.attr=function(attribute){if(this!==''&&attribute){return attribute+'="'+this+'" ';}}
String.prototype.buildDetail=function(content){if(this&&this!==''&&content){return'<li class="'+this+'">'+content.toString().replace(/\/1$/,'')+'</li>';}}
var contentMap={'details':{'location':'location','date':'date','description':'description',},'exif':{'camera':'model','lens':'lens','focal':'focal','aperture':'aperture','iso':'iso','exposure':'exposure',}}
function preview(index){var image=slider.images[index];var h=image.height;var w=image.width;var isVertical=h>=w;var verticalContentWidth=250;if(isVertical){w*=(700/h);h=700;}else{w*=(500/h);h=500;}
if(w>1200){h*=(1200/w);w=1200;}
w=Math.round(w);h=Math.round(h);$("#img-detail img").attr("src",$("#filmstrip img").eq(index).attr("src")).attr("width",w).attr("height",h);var fullImage=$('<img>').attr("src","/image/"+image.unid+"/h:"+h+",w:"+w);$(fullImage).load(function(){$("#img-detail img").attr("src",$(this).attr("src"));});$("#img-detail").toggleClass("v",isVertical).css("width",isVertical?(w+verticalContentWidth)+"px":w+"px").css("margin-left",-1*0.5*(w+(isVertical?verticalContentWidth:0))+"px").fadeIn(300);$("#modal").fadeIn(300);$.getJSON('/rest/images/'+image.unid,{cols:['title','description','location','make','model','lens','date_format(date_taken,"%e %b %Y") AS date','aperture','exposure','iso','focal'],compress:true,},function(json){$("#img-detail ul").html('');_.each(contentMap,function(group,groupName){_.each(group,function(jsonTarget,className){$("#img-detail ."+groupName).append(className.buildDetail(json[jsonTarget]));});});});}
function close_preview(){$("#modal").fadeOut(600);$("#img-detail").fadeOut(300);}
$(document).ready(function(){$("#filmstrip, #filmstrip div").css("height",slider.height+"px");_.each(slider.images,function(image,index){$("#filmstrip div").append('<img src="/image/'+image.unid+'/h:'+slider.height+'" height="'+slider.height+'" alt="'+index+'" />');$("#thumbs ul").append('<li><a href="#"><img src="/image/'+image.unid+'/h:70,w:70,crop:yes" height="70" width="70" alt="'+index+'" /></a></li>');image.offset=slider.slideWidth;image.swidth=slider.height/image.height*image.width;slider.slideWidth+=image.swidth+slider.padding;});$("#filmstrip").mouseenter(function(){slider.stop().move(5);}).mouseleave(function(){slider.stop().move(-5);});$("#filmstrip img").click(function(e){e.preventDefault();preview($(this).attr("alt"));}).load(function(){$(this).css("opacity",1);});$("#thumbs img").click(function(e){e.preventDefault();var index=$(this).attr("alt");var offset=$(this).offset().left;var omega=slider.width()/2+slider.offset()-$(this).width()/2;var margin=parseInt($("#thumbs ul").css("margin-left").replace(/px/gi,''));$("#thumbs ul").css("margin-left",(margin+omega-offset)+"px");slider.slide(index);});$("#menu-wrapper").css("right",0).css("opacity",1);slider.move();$("#modal, #img-detail").click(function(){close_preview();});var playlist=[{artist:"The Glitch Mob, feat. Swan",title:"Between Two Points",path:"/assets/music/the_glitch_mob-between_two_points.mp3"},];$("#jquery_jplayer_1").jPlayer({ready:function(){var trackNum=Math.floor(Math.random()*playlist.length);var track=playlist[trackNum];$(".songtitle").html("&ldquo;"+track.title+"&rdquo; by "+track.artist);$(this).jPlayer("setMedia",{mp3:track.path}).jPlayer("play");},swfPath:"js",supplied:"mp3"});});
