$(document).ready(function(){$("#selectionPicker").modelSelection();$("#selectionPicker").selectbox();$(window).resize(saveWindowSize);$("input[name=opensearch]").focus(resetQS).click(resetQS);saveWindowSize();$("area[rel=genpdf]").click(function(){alert("Your PDF is being generated. This may take a few seconds. Please click OK to continue");return true});$("area.youtube,a.youtube").click(function(){$.fancybox({titleShow:false,transitionIn:"none",transitionOut:"none",padding:0,autoScale:false,title:this.title,
width:1E3,height:575,href:this.href.replace("watch?v=","v/")+"&autoplay=1&hd=1",type:"swf",swf:{allowfullscreen:"true"}});return false});if($.cookie("h")==null){$("div#help_tooltip").show("fast");$("a#help_hide").click(function(){$("div#help_tooltip").hide();$.cookie("h","1",{expires:365,path:"/"});return false})}del=["save_to_name","save_to_email","save_to_comment"];for(key in del)$.cookie(del[key])!=null&&$.cookie(del[key],null,{path:"/"})});
function url_title(d){d=d.replace(/^s+|s+$/g,"");d=d.replace(/[_\s]+/g,"-");d=d.replace(/[^a-zA-Z0-9-]+/g,"");d=d.replace(/[-]+/g,"-");return d=d.replace(/^-+|-+$/g,"")}function isNumber(d){return/^[[0-9]+$/.test(d)}
jQuery.cookie=function(d,k,e){if(typeof k!="undefined"){e=e||{};if(k===null){k="";e.expires=-1}var a="";if(e.expires&&(typeof e.expires=="number"||e.expires.toUTCString)){if(typeof e.expires=="number"){a=new Date;a.setTime(a.getTime()+e.expires*24*60*60*1E3)}else a=e.expires;a="; expires="+a.toUTCString()}var c=e.path?"; path="+e.path:"",g=e.domain?"; domain="+e.domain:"";e=e.secure?"; secure":"";document.cookie=[d,"=",encodeURIComponent(k),a,c,g,e].join("")}else{k=null;if(document.cookie&&document.cookie!=
""){e=document.cookie.split(";");for(a=0;a<e.length;a++){c=jQuery.trim(e[a]);if(c.substring(0,d.length+1)==d+"="){k=decodeURIComponent(c.substring(d.length+1));break}}}return k}};
(function(d){d.toJSON=function(a){if(typeof JSON=="object"&&JSON.stringify)return JSON.stringify(a);var c=typeof a;if(a===null)return"null";if(c!="undefined"){if(c=="number"||c=="boolean")return a+"";if(c=="string")return d.quoteString(a);if(c=="object"){if(typeof a.toJSON=="function")return d.toJSON(a.toJSON());if(a.constructor===Date){var g=a.getUTCMonth()+1;if(g<10)g="0"+g;var i=a.getUTCDate();if(i<10)i="0"+i;c=a.getUTCFullYear();var f=a.getUTCHours();if(f<10)f="0"+f;var l=a.getUTCMinutes();if(l<
10)l="0"+l;var n=a.getUTCSeconds();if(n<10)n="0"+n;a=a.getUTCMilliseconds();if(a<100)a="0"+a;if(a<10)a="0"+a;return'"'+c+"-"+g+"-"+i+"T"+f+":"+l+":"+n+"."+a+'Z"'}if(a.constructor===Array){g=[];for(i=0;i<a.length;i++)g.push(d.toJSON(a[i])||"null");return"["+g.join(",")+"]"}g=[];for(i in a){c=typeof i;if(c=="number")c='"'+i+'"';else if(c=="string")c=d.quoteString(i);else continue;if(typeof a[i]!="function"){f=d.toJSON(a[i]);g.push(c+":"+f)}}return"{"+g.join(", ")+"}"}}};d.evalJSON=function(a){if(typeof JSON==
"object"&&JSON.parse)return JSON.parse(a);return eval("("+a+")")};d.secureEvalJSON=function(a){if(typeof JSON=="object"&&JSON.parse)return JSON.parse(a);var c=a;c=c.replace(/\\["\\\/bfnrtu]/g,"@");c=c.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]");c=c.replace(/(?:^|:|,)(?:\s*\[)+/g,"");if(/^[\],:{}\s]*$/.test(c))return eval("("+a+")");else throw new SyntaxError("Error parsing JSON, source is not valid.");};d.quoteString=function(a){if(a.match(k))return'"'+a.replace(k,
function(c){var g=e[c];if(typeof g==="string")return g;g=c.charCodeAt();return"\\u00"+Math.floor(g/16).toString(16)+(g%16).toString(16)})+'"';return'"'+a+'"'};var k=/["\\\x00-\x1f\x7f-\x9f]/g,e={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"}})(jQuery);function bounce(d){d.animate({"margin-top":"-=20px"},100).animate({"margin-top":"+=20px"},100).animate({"margin-top":"-=20px"},100).animate({"margin-top":"+=20px"},100)}
function saveWindowSize(){var d=$.cookie("windowsize"),k=$(window).width()+","+$(window).height();d!=k&&$.cookie("windowsize",k,{path:"/"})}function resetQS(){var d=$(this);d.val().indexOf("...")!=-1&&d.val("")}
(function(d){d.fn.modelSelection=function(){function k(){p!=false&&$.cookie("selection_"+p,$.toJSON(o),{expires:w.cookieExpire,path:"/"})}function e(){$.cookie("selections",$.toJSON(j),{expires:365,path:"/"})}function a(){var b=$.cookie("selections");if(b==null)c();else{j=$.evalJSON(b);if(!$.isArray(j)||j.length==0)c()}b=false;for(var h=null,q=0;q<j.length;q+=2){h=$.cookie("selection_"+j[q+1]);if(h==null){b=true;j.splice(q,2);$.cookie("selection_"+j[q+1],null,{path:"/"})}}b&&e();f();i();n();r()}function c(){var b=
g(w.defaultSelectionName);j=b;e();l(b[1]);o=[];k()}function g(b){for(var h=0,q=0;q<=5;q++){h=Math.floor(Math.random()*99999).toString();if($.inArray(h,j)==-1)break}return[b,h]}function i(){var b;t.html("");for(var h=0;h<j.length;h+=2)if(j[h+1]!=undefined){b=$("<option></option>").val(j[h+1]).html(j[h].replace(/\+/g," "));j[h+1]==p&&b.attr("selected","selected");t.append(b)}}function f(){var b=$.cookie("selection_active");if(b!=null&&$.inArray(b,j)!=-1){p=b;return true}l(false)}function l(b){if(b===
false)b=j[1];p=b;$("#"+t.attr("id")+" option[value="+p+"]").attr("selected","selected");$.cookie("selection_active",b,{expires:w.cookieExpire,path:"/"})}function n(){var b=$.cookie("selection_"+p);o=b==null?[]:$.evalJSON(b);if(o.length>0){x.css("background","none");u(true)}x.html("");for(b=0;b<o.length;b+=2)m(o[b],o[b+1].replace(/\+/g," "),false)}function m(b,h,q){b=$("<li></li>").attr("id","selection_m_"+b).attr("rel","overmodel").html("<span>"+h+'</span><a class="del" href="#del_'+b+'" rel="model"><!-- --\></a><a href="/bulletmodels/profile/'+
b+"/"+url_title(h)+'"><img src="http://www.bulletfilms.nl/uploads/models/mini/'+b+'.jpg" alt="" /></a>');x.append(b);q?bounce(b):b.show()}function u(b){var h=$("#dock_buttons");b=b?h.attr("src").replace("dock_buttons.png","dock_buttons2.png"):h.attr("src").replace("dock_buttons2.png","dock_buttons.png");h.attr("src",b)}function v(){return $("#"+t.attr("id")+" :selected").html()}function r(){var b=v();b!=""&&$("#activeSelectionButton span").text(b)}function s(){$("#selectionPicker").trigger("rebuild")}
var w={defaultSelectionName:"My selection1",listObject:"#selectionList",cookieExpire:25},t=$(this),x=$(w.listObject),j=[],o=[],p=false;a();$("#selectionPicker").bind("change",function(){var b=$("#"+t.attr("id")+" :selected").val();if(b!=undefined){l(b);n();r()}});$("a[rel=model]").live("click",function(){var b=this.href.replace(/^.*#/,"").split("_"),h=this.title;if(b.length<2)return false;if(b[0]=="add"&&isNumber(b[1])&&h!=undefined){b=b[1];if(p!=false)if($.inArray(b,o)==-1)if(o.length>=50)alert("You cannot add more then 25 models to one selection. Please create a new selection before adding a new model.");
else{if(o.length==0){x.css("background","none");u(true)}o.push(b,h);k();m(b,h,true)}}else if(b[0]=="del"&&isNumber(b[1])){h=b[1];if(p!=false){b=$.inArray(h,o);if(b!=-1){o.splice(b,2);$("#selection_m_"+h).fadeOut("fast");k();o.length==0&&u(false)}}}return false});$("a[rel=selection],area.selection_btn").bind("click",function(){var b=this.href.replace(/^.*#/,"");if(b=="new")if(j.length>=24)alert("You can not have more than 12 selections. Please delete "+Math.round((j.length-22)/2)+" or more selections.");
else{b=prompt("Enter name for the new selection");if(!(b==null||b=="")){b=g(b);j.push(b[0],b[1]);e();l(b[1]);o=[];k();i();n();s()}}else if(b=="del"){if(p!=false)if(confirm("Are you sure you want to delete the selection?")){b=$.inArray(p,j);if(b!=-1){j.splice(b-1,2);e();$("#"+t.attr("id")+" option[value="+p+"]").remove();$.cookie("selection_"+p,null,{path:"/"});$.cookie("selection_active",null,{path:"/"});if(j.length<=1){$.cookie("selections",null,{path:"/"});a()}f();n();s()}}}else if(b=="rename"){b=
prompt("Enter the new selection name",v());if(!(b==null||b=="")){var h=$.inArray(p,j);if(h>0){j[h-1]=b;e();i();s()}}}return false});return this}})(jQuery);
(function(d){d.fn.centerLayer=function(k){function e(){if(c.top!=false){var g=$(window).height()/2-a.height()/2+c.topOffset;if(c.minY!=false&&g<c.minY)g=c.minY;a.css("top",g)}c.left!=false&&a.css("left",$(window).width()/2-a.width()/2)}var a=this,c=k||{};c.top=c.top||false;c.topOffset=c.topOffset||0;c.left=c.left||true;c.minY=c.minY||false;$(window).resize(e);e();return this}})(jQuery);jQuery.fn.extend({selectbox:function(d){return this.each(function(){new jQuery.SelectBox(this,d)})}});
jQuery.SelectBox=function(d,k){function e(n){var m=[],u=$("<ul></ul>");m=i.children("option");m.each(function(){var v=$("<li></li>").attr("id",n+"_"+$(this).val()).text($(this).html());if($(this).is(":selected")){l.val($(this).html());v.addClass(a.currentClass)}u.append(v);v.mouseover(function(r){g=1;jQuery(r.target,f).addClass(a.hoverClass)}).mouseout(function(r){g=-1;jQuery(r.target,f).removeClass(a.hoverClass)}).click(function(){$("li."+a.hoverClass,f).get(0);$("li."+a.currentClass,f).removeClass(a.currentClass);
$(this).addClass(a.currentClass);var r=jQuery("li."+a.currentClass,f).get(0),s=(""+r.id).split("_");s=s[s.length-1];if(a.onChangeCallback){i.get(0).selectedIndex=$("li",f).index(r);a.onChangeParams={selectedVal:i.val()};a.onChangeCallback(a.onChangeParams)}else{i.val(s);i.change()}l.val($(r).text());i.get(0).blur();g=0;f.hide()})});return u}var a=k||{};a.inputType=a.inputType||"input";a.inputClass=a.inputClass||"selectbox";a.containerClass=a.containerClass||"selectbox-wrapper";a.hoverClass=a.hoverClass||
"current";a.currentClass=a.currentClass||"selected";a.loopnoStep=a.loopnoStep||false;a.onChangeCallback=a.onChangeCallback||false;a.onChangeParams=a.onChangeParams||false;var c=d.id,g=0,i=jQuery(d),f=function(n){var m=document.createElement("div");f=jQuery(m);f.attr("id",c+"_container");f.addClass(n.containerClass);f.hide();return f}(a),l=function(n){var m=document.createElement("input");m=jQuery(m);m.attr("id",c+"_input");m.attr("type","text");m.addClass(n.inputClass);m.attr("readonly","readonly");
m.attr("tabIndex",i.attr("tabindex"));return m}(a);i.hide().before(l).before(f);i.bind("rebuild",function(){f.html(e(l.attr("id"))).hide()});f.append(e(l.attr("id"))).hide();l.click(function(){if(f.is(":hidden")){f.css("margin-top","-"+(parseInt(f.height())+36)+"px");f.show()}else f.hide()}).blur(function(){if(f.is(":visible")&&g==0){g=0;f.hide()}})};
