/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/

//Version 3.1.1 : alex.rabe : jQuery no colision mode, loading image
//							  add external inits for nextgen plugin	

//Version 3.1.2 : alex.rabe : Add Full size link

(function($){$.bal_tb_init=function(domChunk){bal_tb_init(domChunk)};$.bal_tb_show=function(t,sourceflv,g,a){bal_tb_show(t,sourceflv,g,a)};$.bal_tb_remove=function(){bal_tb_remove()};$(document).ready(function(){bal_tb_init('a.bal_thickbox, area.bal_thickbox, input.bal_thickbox');imgLoader=new Image();if(typeof tb_pathToImage!=="undefined")imgLoader.src=tb_pathToImage});

function bal_tb_init(domChunk){$(domChunk).click(function(){var t=this.title||this.name||null;var a=this.href||null;var sourceflv=this.rel||null;var g=this.alt||false;bal_tb_show(t,sourceflv,g,a);this.blur();return false})}


function bal_tb_show(caption,url,imageGroup, urldest){try{if(typeof document.body.style.maxHeight==="undefined"){$("body","html").css({height:"100%",width:"100%"});$("html").css("overflow","hidden");if(document.getElementById("bal_TB_HideSelect")===null){$("body").append("<iframe id='bal_TB_HideSelect'></iframe><div id='bal_TB_overlay'></div><div id='bal_TB_window'></div>");$("#bal_TB_overlay").click(bal_tb_remove)}}else{if(document.getElementById("bal_TB_overlay")===null){$("body").append("<div id='bal_TB_overlay'></div><div id='bal_TB_window'></div>");
$("#bal_TB_overlay").click(bal_tb_remove)}}

if(bal_tb_detectMacXFF()){$("#bal_TB_overlay").addClass("bal_TB_overlayMacFFBGHack")}else{$("#bal_TB_overlay").addClass("bal_TB_overlayBG")}

// $('#bal_TB_load').show();

var baseURL;if(url.indexOf("?")!==-1){baseURL=url.substr(0,url.indexOf("?"))}else{baseURL=url}var urlString=/\.jpg$|\.jpeg$|\.png$|\.gif$|\.flv$/;var urlType=baseURL.toLowerCase().match(urlString);



if(urlType=='.jpg'||urlType=='.jpeg'||urlType=='.png'||urlType=='.gif'||urlType=='.flv'){
  TB_PrevCaption="";TB_PrevURL="";TB_PrevHTML="";TB_NextCaption="";TB_NextURL="";TB_NextHTML="";TB_imageCount="";TB_FoundURL=false;
  
  
  var pagesize=bal_tb_getPageSize();
  var x=pagesize[0]-150;
  var y=pagesize[1]-150;
  var imageWidth=1024;
  var imageHeight=576;
  /* var imageWidth=imgPreloader.width;
  var imageHeight=imgPreloader.height; */
  if(imageWidth>x){imageHeight=imageHeight*(x/imageWidth);imageWidth=x;if(imageHeight>y){imageWidth=imageWidth*(y/imageHeight);imageHeight=y}}else if(imageHeight>y){imageWidth=imageWidth*(y/imageHeight);imageHeight=y;if(imageWidth>x){imageHeight=imageHeight*(x/imageWidth);imageWidth=x}}
  TB_WIDTH=imageWidth+30;
  TB_HEIGHT=imageHeight+60;
  /* alert(url); */
  $("#bal_TB_window").append("<div id='bal_image'><object width='"+imageWidth+"' height='"+imageHeight+"'><param name='movie' value='http://www.balistikart.fr/_purplaisir/swf/ba_player.swf?film="+url+"' /><param name='bgcolor' value='#000000' /><param name='allowFullScreen' value='true' /><param name='allowScriptAccess' value='always' /><embed src='http://www.balistikart.fr/_purplaisir/swf/ba_player.swf?film="+url+"' bgcolor='#000' type='application/x-shockwave-flash' width='"+imageWidth+"' height='"+imageHeight+"' allowFullScreen='true' allowScriptAccess='always'/></object></div>"+"<div id='bal_TB_caption'>"+caption+"<div id='bal_TB_secondLine'>&nbsp;&nbsp;<a href='http://www.laguna-coupe.com/' id='Renault' title='Discover Renault Laguna Coupe' target='_blank'>DISCOVER RENAULT LAGUNA COUPE</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='http://www.balistikart.fr/_purplaisir/' id='BalistikArt' title='Blog this film' target='_blank'>BLOG THIS FILM</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='"+urldest+"' id='other_films' title='View the other films' target='_blank'>VIEW THE OTHER FILMS</a>&nbsp;&nbsp;</div></div><div id='bal_TB_closeWindow'><a href='#' id='bal_TB_closeWindowButton' title='Close'>close</a> or Esc Key</div>");
  
  $("#bal_TB_closeWindowButton").click(bal_tb_remove);if(!(TB_PrevHTML==="")){function goPrev(){if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev)}$("#bal_TB_window").remove();$("body").append("<div id='bal_TB_window'></div>");bal_tb_show(TB_PrevCaption,TB_PrevURL,imageGroup);return false}$("#bal_TB_prev").click(goPrev)}if(!(TB_NextHTML==="")){function goNext(){$("#bal_TB_window").remove();$("body").append("<div id='bal_TB_window'></div>");bal_tb_show(TB_NextCaption,TB_NextURL,imageGroup);return false}$("#bal_TB_next").click(goNext)}document.onkeydown=function(e){if(e==null){keycode=event.keyCode}else{keycode=e.which}if(keycode==27){bal_tb_remove()}else if(keycode==190){if(!(TB_NextHTML=="")){document.onkeydown="";goNext()}}else if(keycode==188){if(!(TB_PrevHTML=="")){document.onkeydown="";goPrev()}}};bal_tb_position();$("#bal_TB_load").remove();$("#bal_TB_ImageOff").click(bal_tb_remove);$("#bal_TB_window").css({display:"block"})
  ;imgPreloader.src=url
  
}

else{var queryString=url.replace(/^[^\?]+\??/,'');var params=bal_tb_parseQuery(queryString);TB_WIDTH=(params['width']*1)+30||630;TB_HEIGHT=(params['height']*1)+40||440;ajaxContentW=TB_WIDTH-30;ajaxContentH=TB_HEIGHT-45;if(url.indexOf('TB_iframe')!=-1){urlNoQuery=url.split('TB_');$("#bal_TB_iframeContent").remove();if(params['modal']!="true"){$("#bal_TB_window").append("<div id='bal_TB_title'><div id='bal_TB_ajaxWindowTitle'>"+caption+"</div><div id='bal_TB_closeAjaxWindow'><a href='#' id='bal_TB_closeWindowButton' title='Close'>close</a> or Esc Key</div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='bal_TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='bal_tb_showIframe()' style='width:"+(ajaxContentW+29)+"px;height:"+(ajaxContentH+17)+"px;' > </iframe>")}else{$("#bal_TB_overlay").unbind();$("#bal_TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='bal_TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='bal_tb_showIframe()' style='width:"+(ajaxContentW+29)+"px;height:"+(ajaxContentH+17)+"px;'> </iframe>")}}else{if($("#bal_TB_window").css("display")!="block"){if(params['modal']!="true"){$("#bal_TB_window").append("<div id='bal_TB_title'><div id='bal_TB_ajaxWindowTitle'>"+caption+"</div><div id='bal_TB_closeAjaxWindow'><a href='#' id='bal_TB_closeWindowButton'>close</a> or Esc Key</div></div><div id='bal_TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>")}else{$("#bal_TB_overlay").unbind();$("#bal_TB_window").append("<div id='bal_TB_ajaxContent' class='bal_TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>")}}else{$("#bal_TB_ajaxContent")[0].style.width=ajaxContentW+"px";$("#bal_TB_ajaxContent")[0].style.height=ajaxContentH+"px";$("#bal_TB_ajaxContent")[0].scrollTop=0;$("#bal_TB_ajaxWindowTitle").html(caption)}}$("#bal_TB_closeWindowButton").click(bal_tb_remove);if(url.indexOf('TB_inline')!=-1){$("#bal_TB_ajaxContent").append($('#'+params['inlineId']).children());$("#bal_TB_window").unload(function(){$('#'+params['inlineId']).append($("#bal_TB_ajaxContent").children())});bal_tb_position();$("#bal_TB_load").remove();$("#bal_TB_window").css({display:"block"})}else if(url.indexOf('TB_iframe')!=-1){bal_tb_position();if($.browser.safari){$("#bal_TB_load").remove();$("#bal_TB_window").css({display:"block"})}}else{$("#bal_TB_ajaxContent").load(url+="&random="+(new Date().getTime()),function(){bal_tb_position();$("#bal_TB_load").remove();bal_tb_init("#bal_TB_ajaxContent a.bal_thickbox");$("#bal_TB_window").css({display:"block"})})}}if(!params['modal']){document.onkeyup=function(e){if(e==null){keycode=event.keyCode}else{keycode=e.which}if(keycode==27){bal_tb_remove()}}}}catch(e){}}

function bal_tb_showIframe(){$("#bal_TB_load").remove();$("#bal_TB_window").css({display:"block"})}

function bal_tb_remove(){$("#bal_TB_imageOff").unbind("click");$("#bal_TB_closeWindowButton").unbind("click");$("#bal_TB_window").fadeOut("fast",function(){$('#bal_TB_window,#bal_TB_overlay,#bal_TB_HideSelect').trigger("unload").unbind().remove()});$("#bal_TB_load").remove();if(typeof document.body.style.maxHeight=="undefined"){$("body","html").css({height:"auto",width:"auto"});$("html").css("overflow","")}document.onkeydown="";document.onkeyup="";return false}

function bal_tb_position(){$("#bal_TB_window").css({marginLeft:'-'+parseInt((TB_WIDTH/2),10)+'px',width:TB_WIDTH+'px'});if(!(jQuery.browser.msie&&jQuery.browser.version<7)){$("#bal_TB_window").css({marginTop:'-'+parseInt((TB_HEIGHT/2),10)+'px'})}}function bal_tb_parseQuery(query){var Params={};if(!query){return Params}var Pairs=query.split(/[;&]/);for(var i=0;i<Pairs.length;i++){var KeyVal=Pairs[i].split('=');if(!KeyVal||KeyVal.length!=2){continue}var key=unescape(KeyVal[0]);var val=unescape(KeyVal[1]);val=val.replace(/\+/g,' ');Params[key]=val}return Params}

function bal_tb_getPageSize(){var de=document.documentElement;var w=window.innerWidth||self.innerWidth||(de&&de.clientWidth)||document.body.clientWidth;var h=window.innerHeight||self.innerHeight||(de&&de.clientHeight)||document.body.clientHeight;arrayPageSize=[w,h];return arrayPageSize}function bal_tb_detectMacXFF(){var userAgent=navigator.userAgent.toLowerCase();if(userAgent.indexOf('mac')!=-1&&userAgent.indexOf('firefox')!=-1){return true}}})(jQuery);
