//AJAX FUNCTION FOR PHOTO GALLERY
var preload_image;

function ajaxPhotoGallery(photo_id,type)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
			
			try{
				
				// Opera 8.0+, Firefox, Safari
				ajaxRequest = new XMLHttpRequest();
			} catch (e){
				// Internet Explorer Browsers
				try{
					
					ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try{
						
						ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e){
						// Something went wrong
						alert("Your browser broke!");
						return false;
					}
				}
			}
			
			// Create a function that will receive data sent from the server
			ajaxRequest.onreadystatechange = function()
			{
				if(ajaxRequest.readyState == 4)
				{
					jsonData = null;
					var jsonData = eval('(' + ajaxRequest.responseText + ')');					
					var img_file = jsonData.img_file; 
					
					/* Preloading Image */
					if(document.images)
					{						
					  	preload_image = new Image();
						
						var ajaxDisplay = document.getElementById("gallery");
						ajaxDisplay.appendChild(preload_image);
						
					  	preload_image.onload=showGalleryImage;
						preload_image.className='pgHideIMG';
						
						preload_image.src = host + "image/Brand/gallery/" + img_file;
					}
					
				}
				else 
				{
					var loader = document.getElementById("gallery");
					loader.innerHTML = '<img id="galleryMainImgID" src="'+normal_path+'image/templateImg/gallery_loader.gif" >';
				}
			}
			
			if(global_photo_gallery_photo_id != null)
			{				
				var photoImgEle = document.getElementById(global_photo_gallery_photo_id);
				
				//photoImgEle.className='galleryThumbPhotoIMG';								
				photoImgEle.style.border= "solid 1px #dedcd1";				
			
			}		
						
			document.getElementById(photo_id).style.border="solid 2px #AB9D83";
			global_photo_gallery_photo_id = photo_id;
		
		var queryString = "photo_id=" + photo_id + "&gallery_type=" + type;
			
			ajaxRequest.open("POST", "php/ajaxGallery.php", true);
			
			//Send the proper header information along with the request
			ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			ajaxRequest.setRequestHeader("Content-length", queryString.length);
			ajaxRequest.setRequestHeader("Connection", "close");
			
			ajaxRequest.send(queryString); 
}

function showGalleryImage()
{	
	document.getElementById("galleryMainImgID").parentNode.removeChild(document.getElementById("galleryMainImgID"));
	preload_image.className='pgShowIMG';
}

function galleryThumbOff(thumb)
{	
	if(global_photo_gallery_photo_id != thumb.id)
	{
		/*thumb.style.width='90';
		thumb.style.height='100';
		thumb.style.border='solid 1px #dedcd1';*/
		thumb.style.border= 'solid 1px #dedcd1';
		thumb.className='galleryThumbPhotoIMG';
	}
}

function galleryThumbOn(thumb)
{
	
	if(global_photo_gallery_photo_id != thumb.id)
	{
		//thumb.style.width='92';
		//thumb.style.height='102';
		thumb.style.border= 'solid 2px #AB9D83';//'solid 2px #C7C4B5';
		
		thumb.className='galleryThumbPhotoHoverIMG';
		
		
	}
}
