/**
 * --------------------------------------------------------------------
 * jQuery-Plugin SuperBGimage - Scaling Fullscreen Backgrounds and Slideshow using jQuery
 * Version: 1.0, 29.08.2009
 *
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://dev.andreaseberhard.de/projects/superbgimage/
 *
 * Copyright (c) 2009 Andreas Eberhard
 * licensed under a Creative Commons Attribution 3.0
 *
 *  Inspired by 
 *	  Supersized - Fullscreen Slideshow jQuery Plugin
 *    http://buildinternet.com/project/supersized/
 *	  By Sam Dunn (www.buildinternet.com // www.onemightyroar.com)
 * --------------------------------------------------------------------
 * License:
 * http://creativecommons.org/licenses/by/3.0/
 * http://creativecommons.org/licenses/by/3.0/deed.de
 *
 * You are free:
 *       * to Share - to copy, distribute and transmit the work
 *       * to Remix - to adapt the work
 *
 * Under the following conditions:
 *       * Attribution. You must attribute the work in the manner specified
 *         by the author or licensor (but not in any way that suggests that
 *         they endorse you or your use of the work).
 * --------------------------------------------------------------------
 * Changelog:
 *    29.08.2009 initial Version 1.0
 * --------------------------------------------------------------------
 */
$j = jQuery.noConflict();
(function($j){jQuery.fn.superbgimage=function(loadingoptions){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options,loadingoptions);$j.superbg_inAnimation=false;$j.superbg_slideshowActive=false;$j.superbg_imgIndex=1;$j.superbg_imgActual=1;$j.superbg_imgLast=-1;$j.superbg_imgSlide=0;$j.superbg_interval=0;$j.superbg_preload=0;$j.superbg_direction=0;$j.superbg_max_randomtrans=7;$j.superbg_lasttrans=-1;$j.superbg_isIE6=false;$j.superbg_firstLoaded=false;$j.superbg_saveId=$j(this).attr('id');if($j('#'+options.id).length===0){$j('body').prepend('<div id="'+options.id+'" style="display:none;"></div>');}else{$j('body').prepend($j('#'+options.id));}$j('#'+options.id).css('display','none').css('overflow','hidden').css('z-index',options.z_index);if(options.inlineMode===0){$j('#'+options.id).css('position','fixed').css('width','100%').css('height','100%').css('top',0).css('left',0);}if(options.reload){$j('#'+options.id+' img').remove();}$j('#'+options.id+' img').hide().css('position','absolute');$j('#'+options.id).children('img').each(function(){$j(this).attr('rel',$j.superbg_imgIndex++);if(!options.showtitle){$j(this).attr('title','');}});$j(this).children('a').each(function(){$j(this).attr('rel',$j.superbg_imgIndex++).click(function(){$j(this).superbgShowImage();return false;}).addClass('preload');});$j.superbg_imgIndex--;$j(window).bind('load',function(){$j(this).superbgLoad();});$j(window).bind('resize',function(){$j(this).superbgResize();});$j.superbg_isIE6=/msie|MSIE 6/.test(navigator.userAgent);if($j.superbg_isIE6&&(options.inlineMode===0)){$j('#'+options.id).css('position','absolute').width($j(window).width()).height($j(window).height());$j(window).bind('scroll',function(){$j(this).superbgScrollIE6();});}if(options.reload){$j(this).superbgLoad();}return this;};jQuery.fn.superbgScrollIE6=function(){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);$j('#'+options.id).css('top',document.documentElement.scrollTop+'px');};jQuery.fn.superbgLoad=function(){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);if(($j('#'+options.id).children('img').length>0)||($j('#'+$j.superbg_saveId).children('a').length>0)){$j('#'+options.id).show();}if((typeof options.showimage!='undefined')&&(options.showimage>=0)){$j.superbg_imgActual=options.showimage;}if(options.randomimage===1){$j.superbg_imgActual=(1+parseInt(Math.random()*($j.superbg_imgIndex-1+1),10));}$j(this).superbgShowImage($j.superbg_imgActual);};jQuery.fn.superbgimagePreload=function(){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);clearInterval($j.superbg_preload);if(!$j.superbg_firstLoaded&&($j('#'+$j.superbg_saveId).children('a').length>0)){$j.superbg_preload=setInterval("$j(this).superbgimagePreload()",111);return;}$j('#'+$j.superbg_saveId).children('a.preload:first').each(function(){var imgrel=$j(this).attr('rel');var imgtitle=$j(this).attr('title');var img=new Image();$j(img).load(function(){$j(this).css('position','absolute').hide();if($j('#'+options.id).children('img'+"[rel='"+imgrel+"']").length===0){$j(this).attr('rel',imgrel);if(options.showtitle===1){$j(this).attr('title',imgtitle);}$j('#'+options.id).prepend(this);}img.onload=function(){};}).error(function(){img.onerror=function(){};}).attr('src',$j(this).attr('href'));$j.superbg_preload=setInterval("$j(this).superbgimagePreload()",111);}).removeClass('preload');};jQuery.fn.startSlideShow=function(){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);$j.superbg_imgSlide=$j.superbg_imgActual;if($j.superbg_interval!==0){clearInterval($j.superbg_interval);}$j.superbg_interval=setInterval("$j(this).nextSlide()",options.slide_interval);$j.superbg_slideshowActive=true;return false;};jQuery.fn.stopSlideShow=function(){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);clearInterval($j.superbg_interval);$j.superbg_slideshowActive=false;return false;};jQuery.fn.nextSlide=function(){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);if($j.superbg_inAnimation)return false;if($j.superbg_slideshowActive){clearInterval($j.superbg_preload);}$j.superbg_direction=0;$j.superbg_imgSlide++;if($j.superbg_imgSlide>$j.superbg_imgIndex){$j.superbg_imgSlide=1;}if(options.randomimage===1){$j.superbg_imgSlide=(1+parseInt(Math.random()*($j.superbg_imgIndex-1+1),10));while($j.superbg_imgSlide===$j.superbg_imgLast){$j.superbg_imgSlide=(1+parseInt(Math.random()*($j.superbg_imgIndex-1+1),10));}}$j.superbg_imgActual=$j.superbg_imgSlide;return $j(this).superbgShowImage($j.superbg_imgActual);};jQuery.fn.prevSlide=function(){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);if($j.superbg_inAnimation)return false;$j.superbg_direction=1;$j.superbg_imgSlide--;if($j.superbg_imgSlide<1){$j.superbg_imgSlide=$j.superbg_imgIndex;}if(options.randomimage===1){$j.superbg_imgSlide=(1+parseInt(Math.random()*($j.superbg_imgIndex-1+1),10));while($j.superbg_imgSlide===$j.superbg_imgLast){$j.superbg_imgSlide=(1+parseInt(Math.random()*($j.superbg_imgIndex-1+1),10));}}$j.superbg_imgActual=$j.superbg_imgSlide;return $j(this).superbgShowImage($j.superbg_imgActual);};jQuery.fn.superbgResize=function(){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);var thisimg=$j('#'+options.id+' img.activeslide');var dimensions=$j(this).superbgCalcSize($j(thisimg).width(),$j(thisimg).height());var newwidth=dimensions[0];var newheight=dimensions[1];var newleft=dimensions[2];var newtop=dimensions[3];$j(thisimg).css('width',newwidth+'px');$j(thisimg).css('height',newheight+'px');if($j.superbg_isIE6&&(options.inlineMode===0)){$j('#'+options.id).width(newwidth).height(newheight);$j(thisimg).width(newwidth);$j(thisimg).height(newheight);}$j(thisimg).css('left',newleft+'px');if(options.vertical_center===1){$j(thisimg).css('top',newtop+'px');}else{$j(thisimg).css('top','0px');}};jQuery.fn.superbgCalcSize=function(imgw,imgh){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);var browserwidth=$j(window).width();var browserheight=$j(window).height();if(options.inlineMode===1){browserwidth=$j('#'+options.id).width();browserheight=$j('#'+options.id).height();}var ratio=imgh/imgw;var newheight=0;var newwidth=0;if((browserheight/browserwidth)>ratio){newheight=browserheight;newwidth=Math.round(browserheight/ratio);}else{newheight=Math.round(browserwidth*ratio);newwidth=browserwidth;}var newleft=Math.round((browserwidth-newwidth)/2);var newtop=Math.round((browserheight-newheight)/2);var rcarr=[newwidth,newheight,newleft,newtop];return rcarr;};jQuery.fn.superbgShowImage=function(img){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);$j.superbg_imgActual=$j(this).attr('rel');if(typeof img!=='undefined'){$j.superbg_imgActual=img;}if($j('#'+options.id+' img.activeslide').attr('rel')===$j.superbg_imgActual){return false;}if($j.superbg_inAnimation){return false;}else{$j.superbg_inAnimation=true;}var imgsrc='';var imgtitle='';if($j('#'+options.id).children('img'+"[rel='"+$j.superbg_imgActual+"']").length===0){imgsrc=$j('#'+$j.superbg_saveId+' a'+"[rel='"+$j.superbg_imgActual+"']").attr('href');imgtitle=$j('#'+$j.superbg_saveId+' a'+"[rel='"+$j.superbg_imgActual+"']").attr('title');}else{imgsrc=$j('#'+options.id).children('img'+"[rel='"+$j.superbg_imgActual+"']").attr('src');}if((typeof options.onHide==='function')&&(options.onHide!==null)&&($j.superbg_imgLast>=0)){options.onHide($j.superbg_imgLast);}$j('#'+options.id+' img.activeslide').superbgLoadImage(imgsrc,imgtitle);$j('#'+$j.superbg_saveId+' a').removeClass('activeslide');$j('#'+$j.superbg_saveId).children('a'+"[rel='"+$j.superbg_imgActual+"']").addClass('activeslide');$j.superbg_imgSlide=$j.superbg_imgActual;$j.superbg_imgLast=$j.superbg_imgActual;return false;};jQuery.fn.superbgLoadImage=function(imgsrc,imgtitle){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);if($j('#'+options.id).children('img'+"[rel='"+$j.superbg_imgActual+"']").length===0){var img=new Image();$j(img).load(function(){$j(this).css('position','absolute').hide();if($j('#'+options.id).children('img'+"[rel='"+$j.superbg_imgActual+"']").length===0){$j(this).attr('rel',$j.superbg_imgActual);if(options.showtitle===1){$j(this).attr('title',imgtitle);}$j('#'+options.id).prepend(this);}var thisimg=$j('#'+options.id).children('img'+"[rel='"+$j.superbg_imgActual+"']");var dimensions=$j(this).superbgCalcSize(img.width,img.height);$j(this).superbgTransition(thisimg,dimensions);if(!$j.superbg_firstLoaded){if(options.slideshow===1){$j(this).startSlideShow();}if((options.preload===1)&&($j('#'+$j.superbg_saveId).children('a').length>0)){$j.superbg_preload=setInterval("$j(this).superbgimagePreload()",250);}}$j.superbg_firstLoaded=true;img.onload=function(){};}).error(function(){$j.superbg_inAnimation=false;img.onerror=function(){};}).attr('src',imgsrc);}else{var thisimg=$j('#'+options.id).children('img'+"[rel='"+$j.superbg_imgActual+"']");var dimensions=$j(this).superbgCalcSize($j(thisimg).width(),$j(thisimg).height());$j(this).superbgTransition(thisimg,dimensions);if(!$j.superbg_firstLoaded){if(options.slideshow===1){$j(this).startSlideShow();}if((options.preload===1)&&($j('#'+$j.superbg_saveId).children('a').length>0)){$j.superbg_preload=setInterval("$j(this).superbgimagePreload()",250);}$j.superbg_firstLoaded=true;}}};jQuery.fn.superbgTransition=function(thisimg,dimensions){var options=$j.extend($j.fn.superbgimage.defaults,$j.fn.superbgimage.options);var newwidth=dimensions[0];var newheight=dimensions[1];var newleft=dimensions[2];var newtop=dimensions[3];$j(thisimg).css('width',newwidth+'px').css('height',newheight+'px').css('left',newleft+'px');if((typeof options.onClick==='function')&&(options.onClick!==null)){$j(thisimg).unbind('click').click(function(){options.onClick($j.superbg_imgActual);});}if((typeof options.onMouseenter==='function')&&(options.onMouseenter!==null)){$j(thisimg).unbind('mouseenter').mouseenter(function(){options.onMouseenter($j.superbg_imgActual);});}if((typeof options.onMouseleave==='function')&&(options.onMouseleave!==null)){$j(thisimg).unbind('mouseleave').mouseleave(function(){options.onMouseleave($j.superbg_imgActual);});}if((typeof options.onMousemove==='function')&&(options.onMousemove!==null)){$j(thisimg).unbind('mousemove').mousemove(function(e){options.onMousemove($j.superbg_imgActual,e);});}if(options.randomtransition===1){var randomtrans=(0+parseInt(Math.random()*($j.superbg_max_randomtrans-0+1),10));while(randomtrans===$j.superbg_lasttrans){randomtrans=(0+parseInt(Math.random()*($j.superbg_max_randomtrans-0+1),10));}options.transition=randomtrans;}if(options.vertical_center===1){$j(thisimg).css('top',newtop+'px');}else{$j(thisimg).css('top','0px');}var akt_transitionout=options.transitionout;if((options.transition===6)||(options.transition===7)){akt_transitionout=0;}if(akt_transitionout===1){$j('#'+options.id+' img.activeslide').removeClass('activeslide').addClass('lastslide').css('z-index',0);}else{$j('#'+options.id+' img.activeslide').removeClass('activeslide').addClass('lastslideno').css('z-index',0);}$j(thisimg).css('z-index',1);options.transition=parseInt(options.transition,10);$j.superbg_lasttrans=options.transition;var theEffect='';var theDir='';if(options.transition===0){$j(thisimg).show(1,function(){if((typeof options.onShow==='function')&&(options.onShow!==null))options.onShow($j.superbg_imgActual);$j.superbg_inAnimation=false;if($j.superbg_slideshowActive){$j('#'+options.id).startSlideShow();}}).addClass('activeslide');}else if(options.transition===1){$j(thisimg).fadeIn(options.speed,function(){if((typeof options.onShow==='function')&&(options.onShow!==null))options.onShow($j.superbg_imgActual);$j('#'+options.id+' img.lastslideno').hide(1,null).removeClass('lastslideno');$j.superbg_inAnimation=false;if($j.superbg_slideshowActive){$j('#'+options.id).startSlideShow();}}).addClass('activeslide');}else{if(options.transition===2){theEffect='slide';theDir='up';}if(options.transition===3){theEffect='slide';theDir='right';}if(options.transition===4){theEffect='slide';theDir='down';}if(options.transition===5){theEffect='slide';theDir='left';}if(options.transition===6){theEffect='blind';theDir='horizontal';}if(options.transition===7){theEffect='blind';theDir='vertical';}if(options.transition===90){theEffect='slide';theDir='left';if($j.superbg_direction===1){theDir='right';}}if(options.transition===91){theEffect='slide';theDir='down';if($j.superbg_direction===1){theDir='up';}}$j(thisimg).show(theEffect,{direction:theDir},options.speed,function(){if((typeof options.onShow==='function')&&(options.onShow!==null))options.onShow($j.superbg_imgActual);$j('#'+options.id+' img.lastslideno').hide(1,null).removeClass('lastslideno');$j.superbg_inAnimation=false;if($j.superbg_slideshowActive){$j('#'+options.id).startSlideShow();}}).addClass('activeslide');}if(akt_transitionout===1){var outspeed=options.speed;if(options.speed=='slow'){outspeed=600+200;}else if(options.speed=='normal'){outspeed=400+200;}else if(options.speed=='fast'){outspeed=400+200;}else{outspeed=options.speed+200;}if(options.transition===0){$j('#'+options.id+' img.lastslide').hide(1,null).removeClass('lastslide');}else if(options.transition==1){$j('#'+options.id+' img.lastslide').fadeOut(outspeed).removeClass('lastslide');}else{if(options.transition===2){theEffect='slide';theDir='down';}if(options.transition===3){theEffect='slide';theDir='left';}if(options.transition===4){theEffect='slide';theDir='up';}if(options.transition===5){theEffect='slide';theDir='right';}if(options.transition===6){theEffect='';theDir='';}if(options.transition===7){theEffect='';theDir='';}if(options.transition===90){theEffect='slide';theDir='right';if($j.superbg_direction===1){theDir='left';}}if(options.transition===91){theEffect='slide';theDir='up';if($j.superbg_direction===1){theDir='down';}}$j('#'+options.id+' img.lastslide').hide(theEffect,{direction:theDir},outspeed).removeClass('lastslide');}}else{$j('#'+options.id+' img.lastslide').hide(1,null).removeClass('lastslide');}};jQuery.fn.superbgimage.defaults={id:'superbgimage',z_index:0,inlineMode:0,showimage:1,vertical_center:1,transition:1,transitionout:1,randomtransition:0,showtitle:0,slideshow:0,slide_interval:5000,randomimage:0,speed:'slow',preload:1,onShow:null,onClick:null,onHide:null,onMouseenter:null,onMouseleave:null,onMousemove:null};})(jQuery);
