		var itemid =0;
	var config = {    
 sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)    
 interval: 40, // number = milliseconds for onMouseOver polling interval    
 over: makeTall, // function = onMouseOver callback (REQUIRED)    
 timeout: 200, // number = milliseconds delay before onMouseOut    
 out: makeShort // function = onMouseOut callback (REQUIRED)
};
var imagecount = 0;
function makeTall(){

  $('#header').animate({
 
    marginTop: '20px'
  }, 400, function() {
    // Animation complete.
  });
}

function makeShort(){

  $('#header').animate({
 
    marginTop: '-90px'
  }, 400, function() {
    // Animation complete.
  });


}


jQuery(document).ready(

		function($)
		{
		
		if ($(".file img")){
$(".file img").lazyload({  threshold : 200 ,container: $("#main")});
$('.file img').trigger("thumb");
}
aa =$('#homepage').attr('id');

	if (aa){
   
   }else{	
			$('#header').delay(500).animate({marginTop: "-90px"}, 550 );
    }
    
    if ($('.page-text').length > 0){
       $('#main').css('overflow', 'auto');
       
}
    
   //$("#header").hoverIntent( config );
      $("#header a").click( function(ev){
  

    ev.preventDefault();
   var $self=$(this);
   $('#main').fadeOut(300);
   
    $('#header').animate({

    marginTop: '20px'
  }, 400, function() {
    document.location = $self.attr('href');
  });


   
   });
    $('#main').delay(1000).fadeIn(1000);
    $('#prevbut').hide();
 
    $('#nextbut').hide();
    imagecount = $('.file').length;
	if ($('.tumblr').length >0){
	imagecount = $('.tumblr').length;
	
	}
    if (imagecount > 1){
    $('#main').scrollTo($('#image0'),1);
	showButtons();	
}else{
 $('#makeThumb').hide();

}


					resizeMe();
			$('#main').hide();
	    			$(window).bind('resize',function() {
			resizeMe();
		});
				
		//$('.file img').addClass('animate');
		$('.file:eq(0) img').removeClass('animate');
setImageTitle(0);
		$('#header').addClass('animateHeader');
		$('#prevbut').hide();
		$('#nextbut').hide();
		checkButtons();
			
			$('.file').bind('click', function(){
			zoomMe($(this));
			
						});
		$('#makeThumb').click(function(){
		thumbs();
		});
		
	
		/*$('#nextbut').hover(function(){$(this).removeClass('animatebut').addClass('animatebutlarge')},function(){$(this).removeClass('animatebutlarge').addClass('animatebut')});*/
		$('#nextbut').click(function(event){
		$('#main').stop();
		
		if (itemid < (imagecount-1)){
			itemid +=1;
			//url='#image'+(itemid);
			//window.location.replace(url);
		//$(this).attr('href', '#image'+(itemid+1))	
			animateSlide(itemid,itemid-1);
		}else{
		//$(this).fadeOut();
		//$('#prevbut').fadeIn();
		}
		checkButtons();
		
		});

		$('#prevbut').click(function(){
		 	//event.preventDefault();
			//event.stopPropagation();
		$('#main').stop();
			if (itemid-1 >= 0){
				itemid -=1;
				
			//url='#image'+(itemid);
			//window.location.replace(url);
		
				//$(this).attr('href', '#image'+(itemid-1))
				animateSlide(itemid,itemid+1);
			}else{
		//$(this).fadeOut();
		//$('#nextbut').fadeIn();
		}
		showButtons(true);
				});

		
});
function zoomMe(me){
$('#zoom').fadeIn();
			$('.container').html(me.html());
			$('#zoom img').addClass('panning');
			$('#zoom img').removeClass('animate2');
			$('#zoom img').removeClass('animate');
			ww=$(window).width();
			wh=$(window).height();
			
			scaleImageMax($('#zoom img'),ww,wh);
			
			$('window').unbind('resize');
			$('window').bind('resize',function() {
panResize()});
			initPan();
			
			
		$('#zoom').click(function(){
			$('#zoom').fadeOut();
			$('window').unbind('resize');
				$(window).bind('resize',function() {
			resizeMe();
		});

			});


}
function showButtons(ja){
if (ja){
checkButtons();
$('#makeThumb').show();
}else{
$('#nextbut').fadeOut();
$('#prevbut').fadeOut();
}


}

function checkButtons(){
next = $('#nextbut');
prev = $('#prevbut');

if (itemid >= (imagecount-1)){
next.fadeOut();
}else{
next.fadeIn();
}
if (itemid > 0){
prev.fadeIn();

}else{
prev.fadeOut();
}
}

function animateSlide(itemid,previd){

var previous = $('.file:eq('+previd+') img');
var current = $('.file:eq('+itemid+') img');
var next = $('.file:eq('+(itemid+1)+') img');
previous.removeClass('animate2');
previous.addClass('animate');
current.removeClass('animate2');
current.addClass('animate2');
next.removeClass('animate2');
next.addClass('animate');

//$('#prevbut').'#image'+itemid).click();
$('#main').scrollTo($('#image'+itemid),650);
setImageTitle(itemid);


}
function thumbs(){
$('#main').trigger("thumb");
$(window).unbind('resize');
//$('.fileGroup').fadeOut();
showButtons(false);
$('.fileGroup').css('width','80%').css('padding','10%')
$('#main').css('overflow', 'scroll');



$('.file').css('width',150).css('height',150).css('margin','0 10px 10px 0');
$('#footer').fadeOut();
max_width = 150;
max_height = 150;
$('.file img').each(function(){
$(this).removeClass('animate2');
$(this).removeClass('animate');

scaleImage($(this),max_width,max_height);
//$('.fileGroup').fadeIn();

}); 

$('.file').unbind('click');
$('.file').bind('click', function(){
$('#footer').fadeIn();
$('.fileGroup').css('width','1155000px').css('padding','0');
$('#main').css('overflow', 'hidden');
$('.file').removeClass('thumb');

//alert(itemid);
$('.file').css('height','100%');
$('.file').css('height','100%');
//$('#main').scrollTo($(this),150);
var tid=$(this).attr('id');
itemid = parseInt(tid.substr(5,tid.length));
$('#makeThumb').html(itemid);
//alert(itemid);
 curitem = '#image'+itemid;

//$('.file:not('+curitem+') img').addClass('animate');

resizeMe();vensters(); 
$('#main').scrollTo($('#image'+itemid),1);

showButtons(true);
checkButtons(true);
animateSlide(itemid,itemid-1);
$(window).bind('resize',function() {
			resizeMe();
		});
	$('.file').bind('click', function(){
			zoomMe($(this));
			
						});
});

}

function setImageTitle(itemid){
var content = $('.file:eq('+itemid+') .info .title').html();
$('.imageinfo').stop(true);
if (content){

$('.imageinfo').fadeOut(300,function(){$('.imageinfo .title').html(content);});

$('.imageinfo').delay(500).fadeIn();
}else{

$('.imageinfo').fadeOut();
}

}

function vensters(){
	$(".file").width($(window).width());
	var totalwidth = 0;
	var h = $(window).height()-150;
	
	$('.file').each(function(){
	
		var width = $(this).width();
		totalwidth += width;
		
		
	});
	
	$('.fileGroup').css('width',totalwidth);
	$('.fileGroup').css('height',h);
	$('#main').css('height',h);
$('#main').scrollTo($('.file:eq('+itemid+')'),1);

}

function resizeMe(){
vensters();


var max_height = $(window).height()-250;
var max_width = $(window).width()-210;

$('.file img').each(function(i) {

h = scaleImage($(this),max_width,max_height);
 
 var ih = $(this).height();
		var ihtop = ((max_height) - h )/2;
		$(this).css('marginTop',ihtop);
		
		
});


}


function initPan(){
    $outer_container=$("#zoom");
    $imagePan_panning=$("#imagePan .panning");
    $imagePan=$("#imagePan");
    $imagePan_container=$("#imagePan .container");

    $imagePan_panning.css("margin-top",($imagePan.height()-$imagePan_panning.height())/2+"px");
    containerWidth=$(window).width();
    containerHeight=$(window).height();
    totalContentW=$imagePan_panning.width();
    totalContentH=$imagePan_panning.height();
    $imagePan_container.css("width",totalContentW).css("height",totalContentH);
 
     
    $imagePan_panning.css("margin-left",($imagePan.width()-$imagePan_panning.width())/2).css("margin-top",($imagePan.height()-$imagePan_panning.height())/2);
 
    $imagePan.bind("mousemove", function(event){
        MouseMove(event);
    });

 
function MouseMove(e){
        var mouseCoordsX=(e.pageX - $imagePan.offset().left);
        var mouseCoordsY=(e.pageY - $imagePan.offset().top);
        var mousePercentX=mouseCoordsX/containerWidth;
        var mousePercentY=mouseCoordsY/containerHeight;
        var destX=-(((totalContentW-(containerWidth))-containerWidth)*(mousePercentX));
        var destY=-(((totalContentH-(containerHeight))-containerHeight)*(mousePercentY));
        var thePosA=mouseCoordsX-destX;
        var thePosB=destX-mouseCoordsX;
        var thePosC=mouseCoordsY-destY;
        var thePosD=destY-mouseCoordsY;
        var marginL=$imagePan_panning.css("marginLeft").replace("px", "");
        var marginT=$imagePan_panning.css("marginTop").replace("px", "");
        var animSpeed=500; //ease amount
        var easeType="easeOutCirc";
        if(mouseCoordsX>destX || mouseCoordsY>destY){
            //$imagePan_container.css("left",-thePosA-marginL); $imagePan_container.css("top",-thePosC-marginT); //without easing
            $imagePan_container.stop().animate({left: -thePosA-marginL, top: -thePosC-marginT}, animSpeed,easeType); //with easing
        } else if(mouseCoordsX<destX || mouseCoordsY<destY){
            //$imagePan_container.css("left",thePosB-marginL); $imagePan_container.css("top",thePosD-marginT); //without easing
            $imagePan_container.stop().animate({left: thePosB-marginL, top: thePosD-marginT}, animSpeed,easeType); //with easing
        } else {
            $imagePan_container.stop();
        }
    }
 }
 
function panResize() {
alert('a');
    $imagePan.unbind("mousemove");
    $imagePan_container.css("top",0).css("left",0);
    ww=$(window).width();
			wh=$(window).height();
			
			scaleImageMax($('#zoom img'),ww,wh);
    initPan();
};





function scaleImage(image,max_width,max_height){
 if (image.height() >= image.width()) {

    var h = max_height;

    var w = Math.ceil(image.width() / image.height() * max_height);

  } else {

    var w = max_width;

    var h = Math.ceil(image.height() / image.width() * max_width);
 if (h > max_height){
  var h = max_height;

    var w = Math.ceil(image.width() / image.height() * max_height);

 
 
 }
  }

  image.css({ height: h, width: w });
return h;


}

function scaleImageMax(image,max_width,max_height){
r =image.height()/image.width();

 if (max_width >= max_height) {
  var w = max_width;

    var h = Math.ceil(max_width * r);

}else{
var h = max_height;

    var w = Math.ceil(max_height*r);
}
if (image.height()>=image.width()){
  r =image.height()/image.width();
 
  } else {
    

  }

  image.css({ height: h, width: w });



}

