// JavaScript Document..
var galleryURL='http://www.studioepic.com:81/AJAX_GALLERY/test.php';
var current_type_index;
var current_index=0;
var gallery_image_count;
var myMovieIntervalID;
var millisecond_interval=5000;
exploded_images=[];
exploded_banners=[];

wedding_path='weddings/Full/';
wedding_images=['IMG_8975_small.jpg','0.jpg','1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','31.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg'];
//alert(wedding_image.length);
for (var i=0; i<wedding_images.length; i++) {
	wedding_images[i]=wedding_path+wedding_images[i];
//	alert(wedding_images[i]);	
}

portrait_path='portraits/';
portrait_images=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg'];
for (var i=0; i<portrait_images.length; i++) {
        portrait_images[i]=portrait_path+portrait_images[i];
//      alert(wedding_images[i]);
}


pregnancy_path='pregnancy/';
pregnancy_images=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg'];
for (var i=0; i<pregnancy_images.length; i++) {
        pregnancy_images[i]=pregnancy_path+pregnancy_images[i];
//      alert(wedding_images[i]);
}


children_path='children/';
children_images=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','25.jpg','26.jpg'];
//alert(wedding_image.length);
for (var i=0; i<children_images.length; i++) {
	children_images[i]=children_path+children_images[i];
//	alert(wedding_images[i]);	
}

model_path='model_actor/';
model_images=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg'];
for (var i=0; i<model_images.length; i++) {
        model_images[i]=model_path+model_images[i];
}


product_path='/product/';
product_images=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg'];
for (var i=0; i<product_images.length; i++) {
        product_images[i]=product_path+product_images[i];
}



wedding_data=['wedding','weddings_tab2.jpg',wedding_images];
portrait_data=['portraits','portraits_tab2.jpg',portrait_images];
pregnancy_data=['pregnancy','pregnancy_tab2.jpg',pregnancy_images];
children_data=['children','children_tab2.jpg',children_images];
products_data=['products','products_tab2.jpg',product_images];
modelactor_data=['modelactor','model_actor_tab2.jpg',model_images];

//children_data=
//products_data=

gallery_data=[wedding_data,portrait_data,pregnancy_data,children_data,products_data,modelactor_data]

/* HTML CALLABLE FUNCTIONS*/
function initialize_gallery_by_type(type){
	//alert(type);
	window.type=type;
//alert(gallery_data[0][2][0]);
	// The first image will always be a wedding image
	if(type=='random'){
		explode_galleries(window.exploded_images,window.exploded_banners);
		//alert(window.exploded_images[0]);
		gallery_image_count = window.exploded_images.length; 
		var banner_image=window.exploded_banners[0];
                var first_image=window.exploded_images[0];
	}
	else{
		// determine the index of the passed type in the gallery_data and set the banner and first images structure
		for (var i=0; i<gallery_data.length; i++) {
			if(gallery_data[i][0]==type){
				var banner_image=window.gallery_data[i][1];
				var first_image=gallery_data[i][2][0];
				current_type_index=i;
				gallery_image_count = gallery_data[i][2].length; 
			}
		}
	}

	//alert ('COUNT:'+gallery_image_count);
	var full_file_name='images/'+banner_image;
        document.portfolio_image.src='images/Potfolio/'+first_image;
        document.gallery_type.src=full_file_name;
        document.getElementById("g_decrement").style.display = "none";
        document.getElementById("play").style.display = "none";
        myMovieIntervalID=setInterval ( "increment_gallery_image()", millisecond_interval );
}

function explode_galleries(exploded_images,exploded_banners){
	var tmp_max_length;
	var this_length;
	var check_continue=true;

        while(check_continue==true){
                check_continue=false;
		for (var i=0; i<gallery_data.length; i++) {
			this_length=gallery_data[i][2].length;
			if(this_length>1)
				check_continue=true;
			if(this_length>0){
				exploded_images.push(gallery_data[i][2][0]);
				exploded_banners.push(gallery_data[i][1]);
				shifted=gallery_data[i][2].shift();
			}
                }
        }
}

function increment_gallery_image(){
	if(current_index<(gallery_image_count-1)){
		current_index=current_index+1;
		if(type=='random'){
        	        var portfolio_image_src='images/Potfolio/'+window.exploded_images[current_index];
        	        var gallery_type_src='images/'+window.exploded_banners[current_index];
	        }
	        else{
	       		var portfolio_image_src='images/Potfolio/'+gallery_data[current_type_index][2][current_index];
			var gallery_type_src='images/'+gallery_data[current_type_index][1];
		}
		if(current_index>0){
			document.getElementById("g_decrement").style.display = "block";
		}
		document.portfolio_image.src=portfolio_image_src;
                document.gallery_type.src=gallery_type_src;
	}
	else{
		current_index=0;
		if(type=='random'){
                        var portfolio_image_src='images/Potfolio/'+window.exploded_images[current_index];
                        var gallery_type_src='images/'+window.exploded_banners[current_index];
                }
                else{
			var portfolio_image_src='images/Potfolio/'+gallery_data[current_type_index][2][current_index];
                        var gallery_type_src='images/'+gallery_data[current_type_index][1];
                }
		document.getElementById("g_decrement").style.display = "none";
		document.portfolio_image.src=portfolio_image_src;
                document.gallery_type.src=gallery_type_src;
	}
}

function decrement_gallery_image(){
	if(current_index>0)
		current_index=current_index-1;
	if(type=='random'){
		var portfolio_image_src='images/Potfolio/'+window.exploded_images[current_index];
		var gallery_type_src='images/'+window.exploded_banners[current_index];
                }
        else{
		var portfolio_image_src='images/Potfolio/'+gallery_data[current_type_index][2][current_index];
		var gallery_type_src='images/'+gallery_data[current_type_index][1];
                }
        document.portfolio_image.src=portfolio_image_src;
        document.gallery_type.src=gallery_type_src;

	if(current_index<=0){
		document.getElementById("g_decrement").style.display = "none";
			
	}
	else
		document.getElementById("g_increment").style.display = "block";
	//if(current_index<gallery_image_count)
}

function play_gallery(){
        document.getElementById("play").style.display = "none";
	document.getElementById("stop").style.display = "block";	
	myMovieIntervalID=setInterval ( "increment_gallery_image()", millisecond_interval );
}

function stop_gallery(){
        document.getElementById("play").style.display = "block";
        document.getElementById("stop").style.display = "none";
	clearInterval(myMovieIntervalID);
}



/* QUASI PRIVATE FUNCTIONS - NOT TO BECALLED FROM HTML*/


