var w; var h; var colorboxWidth; var colorboxFaktorWidth = 0; var colorboxFaktorHeight = 0; function initColorbox(){ $(".group1").colorbox({current:"Bild {current} von {total}"}); $(".group2").colorbox({rel:'group2', transition:"fade"}); $(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"}); $(".group4").colorbox({current:"{current} von {total}",slideshowStart:"Diashow starten",slideshowStop:"Diashow beenden",slideshow:true, slideshowAuto:false, slideshowSpeed:"5000"}); $(".youtube").colorbox({iframe:true, innerWidth:425, innerHeight:344}); $(".iframe, .ajax").click(function(){ w = $(this).attr('data-width'); h = $(this).attr('data-height'); getSize($(this)); url = $(this).attr('href'); if (url == undefined){ url = $(this).parent().attr('href'); } if (url == undefined){ url = $(this).parent().find('a').attr('href'); } if (url.indexOf('http://www.dtvbilten.ch') > -1){ if (url.indexOf('?') > -1){ url += '&ajax=true'; } else { url += '?ajax=true'; } } colorboxWidth = w; colorboxFaktorWidth = $(window).width() / w; colorboxFaktorHeight = $(window).height() / h; if (h > $(window).height()){ h = $(window).height() - 60; } $.colorbox({iframe:true, href:""+url+"", width:""+w+"", height:""+h+"", onComplete:function(){ $('#cboxLoadedContent').addClass('loaded'); } }); $('#cboxContent').css('marginTop',scrolled + 30); $('#cboxLoadedContent').css('height',h-12); $('#cboxLoadedContent').css('marginBottom',0); return false; }); $(".inline").colorbox({inline:true, width:"50%"}); $(".callbacks").colorbox({ onOpen:function(){ alert('onOpen: colorbox is about to open'); }, onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); }, onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); }, onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); }, onClosed:function(){ alert('onClosed: colorbox has completely closed'); } }); //Example of preserving a JavaScript event for inline calls. $("#click").click(function(){ $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here."); return false; }); } /********** deactivate scroll on parent window if colorbox opens *****/ $(document).bind('cbox_open', function(){ $('body').css('overflow','hidden'); $('body').addClass('cbx'); }); /********** activate scroll parent window on close *****/ $(document).bind('cbox_closed', function(){ $('body').css('overflow','auto'); $('body').removeClass('cbx'); }); $(document).ready(function(){ initColorbox(); }); function getSize(obj){ if (obj){ if ($(obj).attr('class').indexOf('Small') > -1){ if (w == undefined){ w = '30%';} if (h == undefined){ h = '75%';} } if ($(obj).attr('class').indexOf('Medium') > -1){ if (w == undefined){ w = '50%';} if (h == undefined){ h = '80%';} } if ($(obj).attr('class').indexOf('Large') > -1){ if (w == undefined){ w = '80%';} if (h == undefined){ h = '85%';} } if ($(window).width() < 1200){ if ($(obj).attr('class').indexOf('Small') > -1){ w = '40%'; h = '80%'; } if ($(obj).attr('class').indexOf('Medium') > -1){ w = '60%'; h = '85%'; } if ($(obj).attr('class').indexOf('Large') > -1){ w = '88%'; h = '90%'; } } if ($(window).width() < 780){ if ($(obj).attr('class').indexOf('Small') > -1){ w = '66%'; h = '80%'; } if ($(obj).attr('class').indexOf('Medium') > -1){ w = '86%'; h = $(window).height() - 65; } if ($(obj).attr('class').indexOf('Large') > -1){ w = '98%'; h = '90%'; } } if (w == undefined){ w = '70%';} if (h == undefined){ h = '95%';} if (w.indexOf('%') > 0 || w.indexOf('px') > 0){ if (typeof(w) == 'string'){ w = ($(window).width() / 100) * parseFloat(w.replace('%')); } else { w = ($(window).width() / 100) * parseFloat(w); } if (typeof(h) == 'string'){ h = ($(window).height() / 100) * parseFloat(h.replace('%')); } else { h = ($(window).height() / 100) * parseFloat(h); } } if ($(window).width() < 650) { w = $(window).width() - 10; h = $(window).height() - 60; if ($(window).height() < 600){ h = $(window).height() - 150; } } } else { if ($(window).width() > 650){ if (colorboxFaktorWidth < 1.2){ colorboxFaktorWidth = 1.2; } if (colorboxFaktorHeight < 1.1){ colorboxFaktorHeight = 1.1; } w = $(window).width() / colorboxFaktorWidth; h = $(window).height() / colorboxFaktorHeight; } else { w = $(window).width() - 10; h = $(window).height() - 60; if ($(window).height() < 600){ h = $(window).height() - 150; } } } } $(window).resize(function(){ if (colorboxFaktorWidth > 0){ getSize(); $.colorbox.resize({width:w, height:h}); } });