
(function($){var CanoePhoto={updateMediaButtons:function(){var button_image=$('#add_image');if(button_image&&typeof button_image.attr('href')!='undefined'){button_image.attr('href',button_image.attr('href').replace(/type=image/,'type=image&tab=canoe_photo'));}},insertPhoto:function(imgURL,title,url){var img='<img alt="'+title+'" src="'+imgURL+'" />';if(url!='')img='<a href="'+url+'" title="'+title+'">'+img+'</a>';CanoePhoto.insert(img);},insertPhotoCustomField:function(link,title){if(link.search("size")!=-1){switch(theme){case"Autonet News":link=link.replace('400x400','580x340').replace('500x500','580x340');break;case"Micasa":case"ImmoExtra":link=link.replace('400x400','615x315').replace('500x500','615x315');break;default:link=link.replace('400x400','520x292').replace('500x500','520x292');break;}}
var data=link+'\n'+title;CanoePhoto.insertCustomField(data);},insert:function(h){var win=window.dialogArguments||opener||parent||top;if(typeof win.send_to_editor=='function'){win.send_to_editor(h);if(typeof win.tb_remove=='function')
win.tb_remove();return false;}
tinyMCE=win.tinyMCE;if(typeof tinyMCE!='undefined'&&tinyMCE.getInstanceById('content')){tinyMCE.selectedInstance.getWin().focus();tinyMCE.execCommand('mceInsertContent',false,h);}else{win.edInsertContent(win.edCanvas,h);}
return false;},insertCustomField:function(h){var win=window.dialogArguments||opener||parent||top;if(typeof win.send_to_editor=='function'){$('#metavalue',window.parent.document).val(h);if(typeof win.tb_remove=='function')
win.tb_remove();$('#metavalue',window.parent.document).focus();return false;}
return false;}};var Gallery={currentPhoto:1,currentSlide:0,slides:-1,firstPhotoOfEachSlide:[1,7,13,19,25,31,37,43,49,55,61],display:function(container,image,title,description,cnt){$('#gallery_'+container+' h3').text(title);$('#gallery_'+container+' h4').text(description);$('#gallery_'+container+' img').attr('src',image);$('#gallery_'+container+' img').attr('alt',title);$('#gallery_'+container+' img').show();$('.gallery_image .nbphotos span:first').text(cnt);},displayLightBox:function(container,src){$('#lightbox_'+container+' img').attr('src',src.replace('580x340','940x940'));widthOverlay=$(document).width();heightOverlay=$(document).height();$('#overlay_'+container).css('width',widthOverlay+'px');$('#overlay_'+container).css('height',heightOverlay+'px');Gallery.imgLoad($('#lightbox_'+container+' img'),function completeDisplay(heightImage){$('#lightbox_'+container).css('left',widthOverlay/2-($('#lightbox_'+container).width()/2)-25+'px');$('#lightbox_'+container).css('top',$(document).scrollTop()+$(window).height()/2-heightImage/2-25+'px');$('#lightbox_'+container).css('height',heightImage);$('#navbarCanoe_container').css('z-index','1');$('.bigbox').hide();$('#bannerbar_pub, #bigbox_iframe, .bigbox').hide();$('embed, object').each(function(){$(this).hide();});$('#overlay_'+container).prependTo("body");$('#overlay_'+container).show();$('#lightbox_'+container).insertAfter('#overlay_'+container);$('#lightbox_'+container).show();});},imgLoad:function(img,completeDisplay){var loadWatch=setInterval(function watchThat(){var imageQ=new Image();imageQ.src=img.attr('src');if(imageQ.height!=0){clearInterval(loadWatch);completeDisplay(imageQ.height);}},100);},hideLightBox:function(id){$('.lightbox_autonet img').attr('src','');$('.lightbox_autonet').hide();$('.overlay_autonet').hide();$('#navbarCanoe_container').css('z-index','100000001');$('.bigbox').show();$('embed, object').each(function(){$(this).show();});$('#bannerbar_pub, #bigbox_iframe, .bigbox').show();},next:function(){var current=$('ul.gallery_thumbs li a.selected').parent();$(current).children().removeClass('selected');var next=($(current).hasClass('last')?$('ul.gallery_thumbs:first li:first').children():$('ul.gallery_thumbs [cpt="'+(parseInt($(current).attr('cpt'))+1)+'"]').children());$(next).addClass('selected');if($(next).parent().hasClass('last')){$('#slideshow_'+$(next).parent().attr('postid')+' .nav_next').hide();}else{$('#slideshow_'+$(next).parent().attr('postid')+' .nav_next').show();}
$('#slideshow_'+$(next).parent().attr('postid')+' .nav_previous').show();Gallery.display($(next).parent().parent().attr('post'),$(next).attr('href'),$(next).attr('title'),$(next).attr('rel'));Gallery.update_count('+');if($(current).hasClass('slidable'))
Gallery.setNumberOfSlides($(current).attr('postid'));if($(current).hasClass('slidable')&&$(current).attr('cpt')%6==0&&Gallery.currentSlide<Gallery.slides-1){Gallery.nextSlide($(current).attr('postid'));}
if($(current).hasClass('slidable')&&$(current).hasClass('last')&&Gallery.slides>1){Gallery.gotoSlide($(current).attr('postid'),0);}},previous:function(){var current=$('ul.gallery_thumbs li a.selected').parent();$(current).children().removeClass('selected');var previous=($(current).hasClass('first')?$('ul.gallery_thumbs:last li:last').children():$('ul.gallery_thumbs [cpt="'+(parseInt($(current).attr('cpt'))-1)+'"]').children());$(previous).addClass('selected');if($(previous).parent().hasClass('first')){$('#slideshow_'+$(previous).parent().attr('postid')+' .nav_previous').hide();}else{$('#slideshow_'+$(previous).parent().attr('postid')+' .nav_previous').show();}
$('#slideshow_'+$(previous).parent().attr('postid')+' .nav_next').show();Gallery.display($(previous).parent().parent().attr('post'),$(previous).attr('href'),$(previous).attr('title'),$(previous).attr('rel'));Gallery.update_count('-');if($(current).hasClass('slidable'))
Gallery.setNumberOfSlides($(current).attr('postid'));if($(current).hasClass('slidable')&&$.inArray(parseInt($(current).attr('cpt')),Gallery.firstPhotoOfEachSlide)>=0&&Gallery.currentSlide>0){Gallery.previousSlide($(current).attr('postid'));}
if($(current).hasClass('slidable')&&$(current).hasClass('first')&&Gallery.slides>1){Gallery.gotoSlide($(current).attr('postid'),Gallery.slides-1);}},update_count:function(type){var cnt=parseInt($('.gallery_image .nbphotos span:first').text());var total=parseInt($('.gallery_image .nbphotos span:last').text());if(type=='+'&&cnt!=total){cnt=cnt+1;}else if(type=='+'&&cnt==total){cnt=1;}else if(type=='-'&&cnt==1){cnt=total;}else if(type=='-'&&cnt!=1){cnt=cnt-1;}
$('.gallery_image .nbphotos span:first').text(cnt);},gotoSlide:function(post_id,currentSlide){$('#slideshow_'+post_id+' .slide').hide();$('#slideshow_'+post_id+' .slide_'+currentSlide).show();Gallery.currentSlide=currentSlide;},nextSlide:function(post_id){$('#slideshow_'+post_id+' .slide_'+Gallery.currentSlide).hide();$('#slideshow_'+post_id+' .slide_'+(Gallery.currentSlide+1)).show();Gallery.currentSlide++;if(Gallery.currentSlide==Gallery.slides-1){$('#slideshow_'+post_id+' .slide_arrow_next').hide();}
$('#slideshow_'+post_id+' .slide_arrow_previous').show();},previousSlide:function(post_id){$('#slideshow_'+post_id+' .slide_'+Gallery.currentSlide).hide();$('#slideshow_'+post_id+' .slide_'+(Gallery.currentSlide-1)).show();Gallery.currentSlide--;if(Gallery.currentSlide==0){$('#slideshow_'+post_id+' .slide_arrow_previous').hide();}
$('#slideshow_'+post_id+' .slide_arrow_next').show();},setNumberOfSlides:function(post_id){Gallery.slides=$('#slideshow_'+post_id+' ul.gallery_thumbs').size();}};$(document).ready(function(){$(".savesend").each(function(intIndex){$(this).append('<br /><br /><a href="#" class="addImageToCustom button">Add to Custom Field</a>');});$('.addImageToCustom').click(function(){photoLink=($(this).parent().parent().parent().children('.url').children(".field").children().val());title=($(this).parent().parent().parent().children('.post_title').children(".field").children().val());CanoePhoto.insertPhotoCustomField(photoLink,title);return false;});CanoePhoto.updateMediaButtons();$('#canoe_photo_insert').submit(function(){CanoePhoto.insertPhoto($('#photo_url').val(),$('#photo_title').val(),$('#photo_link').val());return false;});$('#canoe_photo_insert .urlnone').click(function(){$('#photo_link').val('');return false;});$('#canoe_photo_insert .urlfile').click(function(){$('#photo_link').val($('#photo_url').val());return false;});$("ul.gallery_thumbs li a").click(function(e){$("ul.gallery_thumbs li a.selected").removeClass('selected');if($(this).parent().hasClass('first')){$('#slideshow_'+$(this).parent().attr('postid')+' .nav_previous').hide();}else{$('#slideshow_'+$(this).parent().attr('postid')+' .nav_previous').show();}
if($(this).parent().hasClass('last')){$('#slideshow_'+$(this).parent().attr('postid')+' .nav_next').hide();}else{$('#slideshow_'+$(this).parent().attr('postid')+' .nav_next').show();}
$(this).addClass('selected');Gallery.display($(this).parent().parent().attr('post'),$(this).attr('href'),$(this).attr('title'),$(this).attr('rel'),$(this).parent().attr('cpt'));return false;});$("ul.gallery_thumbs li a").mousedown(function(e){e.preventDefault();});$('.gallery_image .nav_next').click(function(e){Gallery.next();return false;});$('.gallery_image .nav_next').mousedown(function(e){e.preventDefault();});$('.gallery_image .nav_previous').click(function(e){Gallery.previous();return false;});$('.gallery_image .nav_previous').mousedown(function(e){e.preventDefault();});$('.gallery_image img').click(function(e){Gallery.displayLightBox($(this).attr('postid'),$(this).attr('src'));return false;});$('.lightbox_autonet, .overlay_autonet').click(function(e){Gallery.hideLightBox($(this).attr('id').replace('overlay_','').replace('lightbox_',''));return false;});$('.slide_arrow_previous').click(function(e){Gallery.setNumberOfSlides($(this).attr('postid'));if(Gallery.currentSlide>0){Gallery.previousSlide($(this).attr('postid'));LastElement=$(".slide_"+Gallery.currentSlide+" li").last().children('a');LastElement.mousedown();LastElement.click();}
return false;});$('.slide_arrow_previous').mousedown(function(e){e.preventDefault();});$('.slide_arrow_next').click(function(e){Gallery.setNumberOfSlides($(this).attr('postid'));if(Gallery.currentSlide<Gallery.slides-1){Gallery.nextSlide($(this).attr('postid'));FirstElement=$(".slide_"+Gallery.currentSlide+" li").first().children('a');FirstElement.mousedown();FirstElement.click();}
return false;});$('.slide_arrow_next').mousedown(function(e){e.preventDefault();});});})(jQuery);
