$(document).ready( function(){
	if (document.getElementById('mosh_largeim_slideshow_container')){
		var moshHomepageSlideInterval;
		var moshHomepageSlideMidSwitch = false;
		$('#mosh_largeim_slideshow_container').append('<img src="image_cache.php?f='+mosh_gal_srcs[0]+'&x=815&y=455" />');
		$('#mosh_largeim_slideshow_container > img:first').bind("load", function(i){
			for (var i=1; i < mosh_gal_srcs.length; i++){
				$('#mosh_largeim_slideshow_container').append('<img src="image_cache.php?f='+mosh_gal_srcs[i]+'&x=815&y=455" />');
			}
			$('#mosh_img_loading_div').remove();
			$('#mosh_largeim_slideshow_container > img:first').hide();  //necessary for chrome... dont know why
			$('#mosh_largeim_slideshow_container > img:first').fadeIn();
			if ($('#mosh_largeim_slideshow_container').children().length > 1){	
				$('#mosh_largeim_slideshow_container').click(function(){
					if ($($('#mosh_largeim_slideshow_container').children()[1]).attr('complete') && !moshHomepageSlideMidSwitch){
						moshHomepageSlideMidSwitch = true;
						$($('#mosh_largeim_slideshow_container').children()[1]).fadeIn(1000, function(){
							($($('#mosh_largeim_slideshow_container').children()[0])).hide();
							$('#mosh_largeim_slideshow_container').append($($('#mosh_largeim_slideshow_container').children()[0]));
							moshHomepageSlideMidSwitch = false;
						});
						clearInterval(moshHomepageSlideInterval);
						moshHomepageSlideInterval = setInterval("$('#mosh_largeim_slideshow_container').click()", 5000);
					}
				});
				moshHomepageSlideInterval = setInterval("$('#mosh_largeim_slideshow_container').click()", 5000);
			}
		});
		$('#mosh_homepage_photo_link').hover(
											 function(){
												 $('#mosh_homepage_photo_link_white').hide();
												 $('#mosh_homepage_photo_link_black').show();
											 }
											 ,
											 function(){
												 $('#mosh_homepage_photo_link_white').show();
												 $('#mosh_homepage_photo_link_black').hide();
											 }
											);
	}
	if (document.getElementById('mosh_photo_album_holder')){
		$('#mosh_photo_album_holder').children().each(function(i){
			$(this).css('margin-left', (25*(i%2)+Math.random()*20)+'px');
			//$(this).css('margin-left', (i*10) - 15 +'px');
			this.zindex = (200-i);
			$(this).css('z-index', this.zindex);
			$(this).hide();
			$(this).show();
		});
		mosh_photo_fade_speed = 250;
		$('#mosh_photo_album_holder').children().hover(
			function() {
				$(this).siblings().children().stop();
				$(this).css('z-index', 1000);
				//$(this).siblings().children().fadeTo(mosh_photo_fade_speed, .6);
			
				$(this).siblings().children().each(function(i){
					//if (!$(this).is("a")) alert($(this).text());
					if (!$(this).is("a")) $(this).fadeTo(mosh_photo_fade_speed, .6);
//					else $(this).fadeTo(mosh_photo_fade_speed, 1);
				});
				
			},
			function() {
				$(this).siblings().children().stop();
				$(this).css('z-index', this.zindex);
				//$(this).siblings().children().fadeTo(mosh_photo_fade_speed, 1);
				$(this).siblings().children().each(function(i){
					if (!$(this).is("a")) $(this).fadeTo(mosh_photo_fade_speed, 1);
				});
			}
		);
	}
	//inline gallery
	if (document.getElementById('mosh_gallery_inline_buttons')){
		var moshPhotoAlbum = false;
		if (document.getElementById('mosh_photoalbum_container')) moshPhotoAlbum = true;
		if (moshPhotoAlbum) $('#mosh_img_loading_div').css('margin-top','180px');
		else $('#mosh_img_loading_div').css('margin-top','110px');
		$('#mosh_gallery_inline_prev_container').hover(
			function(){$('#mosh_gallery_inline_prev').hide();$('#mosh_gallery_inline_prev_plump').show(); },
			function(){$('#mosh_gallery_inline_prev').show();$('#mosh_gallery_inline_prev_plump').hide(); });
		$('#mosh_gallery_inline_next_container').hover(
			function(){$('#mosh_gallery_inline_next').hide();$('#mosh_gallery_inline_next_plump').show(); },
			function(){$('#mosh_gallery_inline_next').show();$('#mosh_gallery_inline_next_plump').hide(); });
		var moshInlineSlideInterval;
		var moshInlineSlideMidSwitch = false;
		var moshInlinePicCount = 1;
		var moshInlinePicTotal = 0;
		
		if (moshPhotoAlbum) $('#mosh_inline_image_gal').append('<img src="image_cache.php?f='+mosh_gal_srcs[0]+'&x=535&y=390" />');
		else $('#mosh_inline_image_gal').append('<img src="image_cache.php?f='+mosh_gal_srcs[0]+'&x=365&y=265" />');
		$('#mosh_inline_image_gal > img:first').bind("load", function(i){
			for (var i=1; i < mosh_gal_srcs.length; i++){
				if (moshPhotoAlbum) $('#mosh_inline_image_gal').append('<img src="image_cache.php?f='+mosh_gal_srcs[i]+'&x=535&y=390" />');
				else $('#mosh_inline_image_gal').append('<img src="image_cache.php?f='+mosh_gal_srcs[i]+'&x=365&y=265" />');
			}
			$('#mosh_img_loading_div').remove();
			moshInlinePicTotal = $('#mosh_inline_image_gal').children().length;
			$('#mosh_inline_image_gal > img:first').hide();  //necessary for chrome... dont know why
			$('#mosh_inline_image_gal > img:first').fadeIn();
			$('#mosh_gallery_inline_label').html(mosh_gal_cpts[0]);

			if ($('#mosh_inline_image_gal').children().length > 1){	
				$('#mosh_inline_image_gal').click(function(){
					if ($($('#mosh_inline_image_gal').children()[1]).attr('complete') && !moshInlineSlideMidSwitch){
						if (++moshInlinePicCount > moshInlinePicTotal) moshInlinePicCount = 1;
						moshInlineSlideMidSwitch = true;
						$('#mosh_gallery_inline_label').html(mosh_gal_cpts[moshInlinePicCount-1]);
						$($('#mosh_inline_image_gal').children()[1]).fadeIn(1000, function(){
							($($('#mosh_inline_image_gal').children()[0])).hide();
							$('#mosh_inline_image_gal').append($($('#mosh_inline_image_gal').children()[0]));
							moshInlineSlideMidSwitch = false;
						});
					}
				});
				$('#mosh_gallery_inline_next_container').click(function(){$('#mosh_inline_image_gal').click();});
				$('#mosh_gallery_inline_prev_container').click(function(){
					if ($($('#mosh_inline_image_gal').children()[moshInlinePicTotal-1]).attr('complete') && !moshInlineSlideMidSwitch){
						if (--moshInlinePicCount < 1) moshInlinePicCount = moshInlinePicTotal;
						$('#mosh_gallery_inline_label').html(mosh_gal_cpts[moshInlinePicCount-1]);
						moshInlineSlideMidSwitch = true;
						$($('#mosh_inline_image_gal').children()[moshInlinePicTotal-1]).fadeIn(1000, function(){								  
							($($('#mosh_inline_image_gal').children()[0])).hide();
							$('#mosh_inline_image_gal').prepend($($('#mosh_inline_image_gal').children()[moshInlinePicTotal-1]));
							moshInlineSlideMidSwitch = false;
						});
					}												
				});
			}
		});
	}
});