// JavaScript Document


function load_particle( pageName, target ){
	
	//alert( target );
	//alert( pageName );
	$("#"+target).fadeTo('fast', 0.15 );
	
		
	$.ajax({
	   type: "POST",
	   url: pageName,
	   cache: false,
	   data: "delta=1",
	   success: function(msg){
		// alert( "Data Saved: " + msg );
		execute_scripts( msg );
		 $("#"+target).html(msg).fadeTo('slow', 1, function() {
				if($.browser.msie) {this.style.removeAttribute('filter');}
			} );
	   },
	   error:function(msg){
		 alert( "Error: " + msg );
	   }
	 });

}

function initialize_gallery(){
	$("#prevImage").hide();
	
	$("#prevImage").removeAttr( "href" );
	$("#nextImage").removeAttr( "href" );
	
	
	//$("#galleryImage").load( function(){$("#galleryImage").animate({"width" : "90%" },'slow');});
	//$("#galleryImage").change( function(){$("#galleryImage").animate({"width" : "0" },'slow');});
	
	$("#prevImage").click( function(){
								var toImageIndex = window.galleryHash[window.currentImage]-1;	
								
								if( window.gallery[toImageIndex] ){
									//$("#galleryImage").animate({"width" : "0%" },'slow');
									$("#galleryImage").attr( "src", window.siteRoot + "/Galleries/image_" + window.gallery[toImageIndex]["Id"] + ".jpg" ).attr( "alt", window.gallery[toImageIndex]["Description"] );	
									window.currentImage = window.gallery[toImageIndex]["Id"];
									
									$("#nextImage").show();
								} else {
									$(this).hide();	
								}
							});
	
	$("#nextImage").click( function(){
								$("#prevImage").show();
								
								var toImageIndex = window.galleryHash[window.currentImage]+1;
								
								if( window.gallery[toImageIndex] ){
									//$("#galleryImage").animate({"width" : "0%" },'slow');
									$("#galleryImage").attr( "src", window.siteRoot + "/Galleries/image_" + window.gallery[toImageIndex]["Id"] + ".jpg" ).attr( "alt", window.gallery[toImageIndex]["Description"] );	
									window.currentImage = window.gallery[toImageIndex]["Id"];
									
									
								} else {
									$(this).hide();	
								}
							});
	
}


function initialize_eventGallery(){
	$("#downImage").hide();
	
	$("#downImage").removeAttr( "href" );
	$("#upImage").removeAttr( "href" );
	
	
	//$("#galleryImage").load( function(){$("#galleryImage").animate({"width" : "90%" },'slow');});
	//$("#galleryImage").change( function(){$("#galleryImage").animate({"width" : "0" },'slow');});
	
	window.currentIndex = 1;
	
	$("#downImage").click( function(){
								
								window.currentIndex -= 1;
								
								var firstImageIndex = window.currentIndex-1;
								var secondImageIndex = window.currentIndex;
								
								if( window.gallery[firstImageIndex] ){
									//$("#galleryImage").animate({"width" : "0%" },'slow');
									$("#firstImage").show();
									$("#firstImage").attr( "src", window.siteRoot + "/Galleries/image_" + window.gallery[firstImageIndex]["Id"] + ".jpg" ).attr( "alt", window.gallery[firstImageIndex]["Description"] );
									
									
									$("#upImage").show();
								}
								
								if( window.gallery[secondImageIndex] ){
									$("#secondImage").show();
									$("#secondImage").attr( "src", window.siteRoot + "/Galleries/image_" + window.gallery[secondImageIndex]["Id"] + ".jpg" ).attr( "alt", window.gallery[secondImageIndex]["Description"] );	
								}
								
								if( !window.gallery[firstImageIndex-1] ){
									$(this).hide();	
								}
								
								
								
							});
	
	$("#upImage").click( function(){
								$("#downImage").show();
								
								
								var firstImageIndex = window.currentIndex;
								var secondImageIndex = window.currentIndex+1;
								
																
								if( window.gallery[firstImageIndex] ){
									//$("#galleryImage").animate({"width" : "0%" },'slow');
									$("#firstImage").show();
									$("#firstImage").attr( "src", window.siteRoot + "/Galleries/image_" + window.gallery[firstImageIndex]["Id"] + ".jpg" ).attr( "alt", window.gallery[firstImageIndex]["Description"] );
									
									
								}
								
								if( window.gallery[secondImageIndex] ){
									$("#secondImage").show();
									$("#secondImage").attr( "src", window.siteRoot + "/Galleries/image_" + window.gallery[secondImageIndex]["Id"] + ".jpg" ).attr( "alt", window.gallery[secondImageIndex]["Description"] );	
								} else {
									$("#secondImage").hide();
								}
								
								if( !window.gallery[secondImageIndex+1] ){
									$(this).hide();	
								}
								
								window.currentIndex += 1;
							});
	
}

function update_title( title ){

	document.title = title;
}
