(function(){
	var scaler=Scaler('bg'),els=$('#bg').children(),width=100/els.length;
	var float=$('<span />').css({position:'absolute',color:'#fff',cursor:'pointer',zIndex:2});
	var div=$('<div/>').css({position:'absolute',left:0,bottom:0,marginRight:-20,height:'100%'});
	bredde = div.width(els.css({float:'left',width:width+'%'}).length+'00%').append(els);


	var position;

	var move=function(e){
			float[0].style.left=(e=e||window.event).clientX+25+'px';
			float[0].style.top=e.clientY-25+'px';
			// if(float[0].nxt!=(e.clientX>(document.body.offsetWidth/2)))float[0].innerHTML=(float[0].nxt=!float[0].nxt)?'<div id="next_gallery">></div>':'<div id="prev_gallery"><</div>';	//Change html only if needed

		},
		swap=function(e){
			var key=e.type=='click'?(e.clientX>(document.body.clientWidth/2)?40:37):e.keyCode;
			if(key>36&&key<41)div.animate({left:(position = scaler(key>38?'+1':'-1').to*-1)+'00%'},1000);	//swap with animation
			$('#imagecycle').children().removeClass("highlight");
			$('#number'+position*-1).toggleClass("highlight");
			$('.numberdata').hide('fast');
			$('#numberdata'+position*-1).show('fast');


		}
	
		gotoslide=function(imagenumber){
			div.animate({left:(scaler(imagenumber).to*-1)+'00%'},1000);
			$('#imagecycle').children().removeClass("highlight");
			$('#number'+imagenumber).toggleClass("highlight");
		

		}

	$(window).bind('keydown',swap);
	$('#bg').bind('mousemove',move).bind('click',swap).css('cursor','pointer').append(div,float);

	/*$('#bg').cycle({ //if using jquery.cycle-plugin the window resizing won't behave too good - fixable
		timeout:2000,
		after:function(a,b,c){scaler(c.currSlide)}, //but this part is important - scale the current photo
		fx:'scrollLeft'
	});*/
})();




