$(document).ready(function(){	 

				var g_count_div = 0;
				var g_cur_f = 1;			
				var g_move_b = 196;
				var g_cur_type = 0;
				var clicked = false;
				$('#pic-list a').click(function(){	
						//prevent bug
						clicked = true;
						
						/*
						 * reset all the variables
						 */
						g_count_div = 0;
						g_cur_f = 1;
						g_cur_type = 0;
						g_move_b = 196;
						$.post('ajax/showgallery.php',
							   {aid: $(this).attr('class') , img: $(this).attr('rel') },
							   function(data){						
								overlay(data);	
							   g_count_div = $('#pic-list-slider img').length - 2;//count of clicks	
											});
								});
				$('.car-rental-detail-box a').click(function(){
						//prevent bug
						clicked = true;									 
						/*
						 * reset all the variables
						 */
						g_count_div = 0;
						g_cur_f = 1;
						g_cur_type = 0;
						g_move_b = 196;		
						$.post('ajax/showgallery.php',
							   {aid: $(this).attr('class') , img: $(this).attr('rel'),page: $('.page').text()  },
							   function(data){						
								overlay(data);	
							   g_count_div = $('#pic-list-slider img').length - 2;//count of clicks	
											});
															 });
				$('.limu-list-rental-detail-holder a').click(function(){
						//prevent bug
						clicked = true;									 
						/*
						 * reset all the variables
						 */
						g_count_div = 0;
						g_cur_f = 1;
						g_cur_type = 0;
						g_move_b = 196;		
						$.post('ajax/showgallery.php',
							   {aid: $(this).attr('class') , img: $(this).attr('rel'),page: $('.page').text()  },
							   function(data){						
								overlay(data);	
							   g_count_div = $('#pic-list-slider img').length - 2;//count of clicks	
											});
					   });
				$('.view-album-btn').click(function(){
						//prevent bug
						clicked = true;							
						/*
						 * reset all the variables
						 */							
						g_count_div = 0;
						g_cur_f = 1;
						g_cur_type = 0;
						g_move_b = 196;
						$.post('ajax/showgallery.php',
							   {aid: $(this).attr('rel') },
							   function(data){						
								overlay(data);	
							   g_count_div = $('#pic-list-slider img').length - 2;//count of clicks	
							   g_move_b = $('#types').text() == 1 ? 136 : 196;
							   g_cur_type = $('#types').text();
							   if ( $('#types').text() == 1 )
							      {
									  $('.pic-list-thumbs').css('width' , '554px');
									  $('.pic-list-arrows').css('width' , '554px');
								  } else {
									  $('.pic-list-thumbs').css('width' , '598px');
									  $('.pic-list-arrows').css('width' , '598px');
								  }
											});
								});
				$('.vip-list a').click(function(){
						//prevent bug
						clicked = true;						
						/*
						 * reset all the variables
						 */						
						g_count_div = 0;
						g_cur_f = 1;
						g_cur_type = 0;
						g_move_b = 196;
						$.post('ajax/showgallery.php',
							   {aid: $(this).attr('class') , img: $(this).attr('rel')},
							   function(data){						
								overlay(data);	
							   g_count_div = $('#pic-list-slider img').length - 2;//count of clicks	
							   g_move_b = $('#types').text() == 1 ? 136 : 196;
							    g_cur_type = $('#types').text();
							    if ( $('#types').text() == 1 )
							      {
									  $('.pic-list-thumbs').css('width' , '554px');
									  $('.pic-list-arrows').css('width' , '554px');
								  } else {
									  $('.pic-list-thumbs').css('width' , '598px');
									  $('.pic-list-arrows').css('width' , '598px');
								  }
							});
						});
				
				//gallery slide
				$('.pic-list-left').live('click',function(){
					if ( g_cur_f != 1 )
					   {									
						$('#pic-list-slider').animate({ left: '+='+g_move_b }, 1000);
						--g_cur_f;
					   }
														});
				$('.pic-list-right').live('click',function(){
					if ( g_cur_f != g_count_div && g_cur_f < g_count_div ) 
					   {
						$('#pic-list-slider').animate({ left: '-='+g_move_b }, 1000);
						++g_cur_f;
					   }
														});
				$('#pic-list-slider img').live('click',function(){
								var src = $(this).attr('src');
								var new_img = src.split('/');
								var nr = $.browser.msie ? ($.browser.version <= 7.0 ? 5 : 1): 1;
								if ( g_cur_type == 1 || $('#types').text() == 1) 
								   {
										var expl = new_img[nr].split('_');
										var out_new =  expl[1]+'_'+expl[2]+'_'+expl[3];

										$('.pic-list-big-img').html('<img src="upload/'+out_new +'"  alt="" />');
								   } else {
										$('.pic-list-big-img').html('<img src="upload/'+new_img[nr]+'" alt="" />');	
								   }
																});
						   });

function overlay(content){
		$('#main-overlay-shadow').css({ height: $(document).height()}).show();//fix the height and show
		$('#main-overlay').css('top', $(window).scrollTop() + 100 + 'px').append(content).show(); //moving overlay 100px from top
}
