	
// Init Gallery
$(window).load(function() {
	initGallery();
});

//Bind on window reesize, reset gallery
$(document).ready(function() {
$(window).bind("resize", function() {
	
	initGallery();
	//alert('OK')
}); 
});
		
function initGallery(){
	//If no gallery
	if(!document.getElementById('gallery_images')){
	return false;	
	}
	
	//If No Images
	if(setGalleryImages()<1){
	//alert('No Images');
		$("#photo_container").remove();
		$("#count_container").remove();
		$("#gallery_container").html('<div>NO IMAGES SELECTED</div>');
		return false;
	}
	
	//Start Init
	$("#photo_container").remove();
	$("#count_container").remove();
	$("#gallery_container").html('<div id="photo_container"></div>');


	$("#photo_container").css({
		"width": $("#gallery_container").width() + "px",
		//"height": $(window).height() + "px"
		"height": document.getElementById('galleryHeight').value+"px"
	});
	
	iscGlobal.autoplay = false;	
	autoPlayTime = 5000;
	if(document.getElementById('galleryAuto')){
	if(document.getElementById('galleryAuto').checked){
		iscGlobal.autoplay = true;	
		if(document.getElementById('galleryAutoTime').value > 1000){
		autoPlayTime = document.getElementById('galleryAutoTime').value;
		}
	}
	} else 
	if(document.getElementById('galleryAutoToggle')){
	if(document.getElementById('galleryAutoToggle').value==1){
		iscGlobal.autoplay = true;	
		if(document.getElementById('galleryAutoTime').value > 1000){
		autoPlayTime = document.getElementById('galleryAutoTime').value;
		}
	}
	}
	$("#photo_container").isc({ 
			imgArray: carousel_images,
			autoplay: iscGlobal.autoplay,
			autoplayTimer: autoPlayTime // 5 seconds. 
	});
	
}		
		// Example with autoplay
		/* $(window).load(function() {
			$("#photo_container").isc({
				imgArray: carousel_images,
				autoplay: true,
				autoplayTimer: 5000 // 5 seconds.
			});	
		}); */
		
		
		
function startGalleryUpload(){
	  InsertContent('galleryImage_upload_process');
	  RemoveContent('submitUploadBtn_galleryImage');
      document.getElementById('galleryImage_upload_form').style.visibility = 'hidden';
	  document.getElementById('galleryImage_fail_msg').innerHTML='';
	  
      return true;
}
var imageID;
function stopGalleryUpload(success,img){
//alert(success)
	//alert(img);
	var result = '';
      if (success == 1){
         result = '<span>Image Upload Complete<\/span><br/>';
		 //alert(result);
		 //$('#image_preview').attr('src',img);
		 //if(document.getElementById('itemImage')){
		 //	 $('#itemImage').val(img); 
		 //}
		 //$('#removeLogoBtn').css('display','inline');
		 //$('#scr_branding').html('<a href="#" target="_blank"><img id="scr_logo" src="images/SCR_white_sml.png" alt="" border="0" align="right" height="40" style="margin-top:5px; margin-right:15px;" /></a>');
	  	 //document.getElementById('header_logo').src = img;
		 //$('#header_logo').attr('src',img);
		 
		 imgFileName = img.substring(img.lastIndexOf('/')+1);
		 imgThumb = imgFileName.split('.');
		 imgThumbSrc = imgThumb[0];
		 imgThumbExtension = imgThumb[1];
		 
		 $('#galleryGrid').append('<div class="layout_box group1" id="imageHolder'+imageID+'" style=" width:120px; background: url('+img.replace(imgFileName,'')+imgThumbSrc+'-thumb.'+imgThumbExtension+') center no-repeat;" ><div><strong><a href="javascript:;" onclick="document.getElementById(\'image'+imageID+'\').value=\'\';RemoveContent(\'imageHolder'+imageID+'\')"><img border="0" src="images/icons/cross.png" width="16" height="16" /></a></strong><br /> <span style="font-size: x-small;"></span><input name="image'+imageID+'" type="hidden" id="image'+imageID+'" value="'+img+'" /></div></div>');
		 imageID++;
		 
      }
      else 
	  if (success == 0){
         result = '<span>The file was removed successfully!<\/span><br/>';
		 //alert(result);
      }
      else {
         result = '<span>There was an error during file upload!<\/span><br/>';
		 //alert(result);
		 $('#galleryImage_fail_msg').html(success);
      }
    
      RemoveContent('galleryImage_upload_process');
	  //uploadform = '<input name="image" type="file" size="30" onchange="document.getElementById(\'galleryImage_upload_form\').submit();blockUI(\'Uploading...\');" /><br />';
	  uploadform = '<input name="image" type="file" size="30" onchange="$.colorbox.close();alertBlock(\'Uploading...\');document.getElementById(\'galleryImage_uploadForm\').submit();" /><br />';
	  alertBlock(result);
	  
	  InsertContent('submitUploadBtn_galleryImage');
	  document.getElementById('galleryImage_upload_form').innerHTML = uploadform;
      document.getElementById('galleryImage_upload_form').style.visibility = 'visible';   
	  setTimeout("RemoveContent('galleryImage_uploadResult');",3000);


      return true;   
}




function removeLogo(id){
	var answer = confirm("Remove Header Logo?")
	if (answer){
		//alert("Bye bye!")
		$.post("upload.php", { type: "delete", id: id },
	   function(data) {
		 //alert("Data Loaded: " + data);
		 alertBlock('Logo Removed');
		 $('#header_logo').attr('src','images/SCR_white.png');
		 $('#scr_branding').html('');
		 $('#removeLogoBtn').css('display','none');
	   });
	} else {
		//alert("Thanks for sticking around!")
	}
	
}

function removeImage(id,item){
	var answer = confirm("Remove Item Image?")
	if (answer){
		//alert("Bye bye!")
		$.post("upload.php", { type: "deleteImage", id: id, item: item },
	   function(data) {
		 //alert("Data Loaded: " + data);
		 alertBlock('Image Removed');
		 $('#image_preview').attr('src','images/blank.gif');
		 //$('#scr_branding').html('');
		 $('#removeLogoBtn').css('display','none');
	   });
	} else {
		//alert("Thanks for sticking around!")
	}
	
}
