        jQuery.fn.extend({
                photoSwap: function() {
                  return this.each(function() {
                    nu = parseInt($(this).find('img').length);
                    si = 0;
                    photochanger = setInterval(changePhoto,8000);
                  });
                },
                photoSwap1: function() {
                  return this.each(function() {
                    nu = parseInt($(this).find('.segment').length);
                    si = 0;
                    photochanger = setInterval(changePhoto1,8000);
                  });
                }
        });
         function changePhoto() {
                si2 = si+1;
                if(si2==nu){si2=0;}
                bgimg = $('#mainphoto img:eq('+si2+')').attr('src');
                $('#mainphoto').css('background-image','url('+bgimg+')');
                $('#mainphoto img:eq('+si+')').fadeOut(500,function(){
                       $('#photoinfo div span:eq('+si+')').hide();
                       si++;
                       if(si==nu){si=0;}
                       $('#photoinfo div span:eq('+si+')').show();
                       $('#mainphoto img:eq('+si+')').show();
                });
         }
         function changePhoto1() {
                si2 = si;
                if(si2==nu){si2=0;}
                $('#main-photo .segment, .segment-descriptor .seg-section').hide();
                $('#main-photo .segment:eq('+si2+'), .segment-descriptor .seg-section:eq('+si2+')').show();
                $('#which-seg div').css({background:'#fff'});
                $('#which-seg div:eq('+si2+')').css({background:'#44B2FF'});

             /*   if(si2==0) {
                	sa = 0; sc= 380;
                } else if (si2==1) {
                	sa = -228; sc= 320;
                } else if (si2==2) {
                	sa = -412; sc= 370;
                } else if (si2==3) {
                	sa = -580; sc= 400;
                }
                $('#seg-crop').css({width:sc+'px'});
                $('#seg-adjust').animate({left:sa+'px'},1500);*/

                si++;
                if(si==nu){si=0;}
         }

	$(document).ready(function(){
               //$('#mainphoto').photoSwap();
               $('#main-photo').photoSwap1();

               //show main photo label on hover, and change photo on click
               $('#main-photo').click( function () { clearInterval(photochanger);
                              			   changePhoto1();
                                       	photochanger = setInterval(changePhoto1,8000);
                                       });

               //change color of pointer boxes on hover
               $('.big-pointer-box').hover( function() {
               				$(this).addClass('blue').children().css('border-top-color','#016CFF');
                                         },
                                         function () {
                                         $(this).removeClass('blue').children().css('border-top-color','#222222');
                                         });

	      // go to blog when clicking on blog pointer box
	      $('#blog .big-pointer-box').click( function() {
               				window.location = './blog';
                                         });

               // load first x photos of album when hover on image
               $('.photo-album-home>div').hover( function() {
                                         np = $(this).find("#photo-album-mover a").size() - 1;

				                				  var id = $(this).parent().attr('id');
                                         id = id.split('-');
                                         id = id[1];

                                         //$(this).prepend(id);
                                    },
                                    function () {
                                         	$(this).find('#photo-album-mover').css('left','0px');
                                    })
               			    			.mousemove(function(e) {
                                         //$(this).prepend(np);
                                 		  offset = $(this).offset();
													  var x = e.pageX - offset.left;
                                         x /= (285 / np );
                                         x = Math.round(x);
                                         x *= (285 / np ) * np;
													  $(this).find('#photo-album-mover').css('left',-x+'px');
                            });

         });
