if(document.getElementById("txt_template_directory")){
		
	g_theme_path=document.getElementById("txt_template_directory").value;
		
	g_site_path=document.getElementById("txt_siteurl").value;

}

$(document).ready(function() {			
	
	$('#gallery_slideshow a').css({opacity: 0.0});
			
	$('#gallery_slideshow .gallerycaption').css({opacity: 0.7});
	
	//Get the caption of the first image from REL attribute and display it
	if(document.getElementById("gallery_slideshow"))
	{
	$('#gallery_slideshow .content').html($('#gallery_slideshow a:first').attr('rel'))
	.animate({opacity: 0.8}, 400);		
	slideShow();
	}
	
});	


function slideShow() {							
	
    $('#gallery_slideshow a').removeClass('hideslide');
    
	intialize_show();
	
	setInterval('append_image()',4000);
	
	setInterval('gallery()',6000);
	
}

function intialize_show(){

	 $("#loaderimg").hide();  
	 
	 $("#gallery_slideshow a:first").addClass('show');
	 
	  $("#gallery_slideshow a:first").css({opacity: 1.0});
	
}

function append_image(){

	var imgcount = $("#img_content a").length;
	 
	var total = $("#total_img").val();

	if(imgcount<total){
	 
		$.ajax({						

			type : "post",

			url	 :g_theme_path+"/ajax-page.php",

			data :'imgcount='+imgcount+'&mode=slideshow&rand='+Math.random(),		

			success: function(data){				
				
				$("#img_content").append(data);					
								
			}
				
		});	
	
	 }		 

}

function gallery() {
	
	//if no IMGs have the show class, grab the first image		

	var cur_img,nxt_img,nxt_id,total,img_cunt,img_id;	      
		
	total = $("#total_img").val();
	
	if(total>1){
		
		if($('#gallery_slideshow a').hasClass('show')){
			
			cur_img = $('.show').attr('id');	
	
		}else{
		
			cur_img = "show_1";	
		}
	
		var id_arr = cur_img.split('_');
	
		img_cunt = parseInt(id_arr[1]);	
	
		if(img_cunt==1){
		
			nxt_img = 'show_2';
		
		}else{
		
			if(img_cunt==total){ 
									
				nxt_img = 'show_1';
			
			}else{
			
				nxt_id = img_cunt+1;
			
				nxt_img = 'show_'+nxt_id;
		
			}
		
		
		}
	}else{
		
		cur_img = 'show_1';
		
		nxt_img = 'show_1';		
	}
	
	var caption = $("#"+nxt_img).attr('rel');	
	
	$("#"+nxt_img).removeClass('hideslide');
	
	$("#"+nxt_img).css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	
	if(total>1){	
		$("#"+cur_img).animate({opacity: 0.0}, 1000)
		.removeClass('show');	
	}
	
	$('#gallery_slideshow .gallerycaption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery_slideshow .gallerycaption').animate({opacity: 0.8},40 ).animate({height: '40px'},500 );
	
	//Display the content
	$('#gallery_slideshow .content').html(caption);
		
}
