function ShowLightbox(Section){

	if($('LightboxShown').value ==0){

		//new Effect.Move('LightboxContainer', { x: 0, y: -140, mode: 'relative' });
		new Effect.Morph('LightboxContainer', {
			style: 'height:40px; height: 155px;', // CSS Properties
			duration: 0.8 // Core Effect properties
		});
		new Effect.Morph('Lightbox', {
			style: 'height:40px; height: 155px;', // CSS Properties
			duration: 0.8 // Core Effect properties
		});

		//~ new Effect.Morph($('CurrentLightboxSection').value+'Images', {
			//~ style: 'height:35; height: 155;', // CSS Properties
			//~ duration: 0.8 // Core Effect properties
		//~ });

		$('LightboxShown').value =1;
	}else if($('LightboxShown').value ==2){

		new Effect.Morph('LightboxContainer', {
			style: 'height:0px; height: 155px;', // CSS Properties
			duration: 0.8 // Core Effect properties
		});
		new Effect.Morph('Lightbox', {
			style: 'height:0px; height: 155px;', // CSS Properties
			duration: 0.8 // Core Effect properties
		});
		//~ new Effect.Morph($('CurrentLightboxSection').value+'Images', {
			//~ style: 'height:0; height: 155;', // CSS Properties
			//~ duration: 0.8 // Core Effect properties
		//~ });
	}
	HideRemoveImage();
	var LightboxTabs= Array;
	LightboxTabs = $('LightboxTabs').value.split(',');
	for (i=0; i < LightboxTabs.length; i++) {
		//~ $(LightboxTabs[i]+'Images').hide();
		//if($(LightboxTabs[i]+'Label').style.backgroundColor !='green'){
			//~ $(LightboxTabs[i]+'Label').style.backgroundColor ='#505050';
			
			/* BORDER HACKS!!!*/
			//~ if(LightboxTabs[i]=='Lightbox'){ 
				//~ $(LightboxTabs[i]+'Label').style.borderWidth = '0 1px 0 0';
			//~ }else{
				//~ $(LightboxTabs[i]+'Label').style.borderColor ='#505050';
			//~ }
		//}
	}
	//~ $(Section+'Images').style.height =155;
	//$(Section+'Images').style.display ='inline-block';
	//if($(Section+'Label').style.backgroundColor !='green'){
	//$(Section+'Label').style.backgroundColor ='#111111';
	//$(Section+'Label').style.borderColor ='#909090';
	
	/* BORDER HACKS!!!*/
	//~ if(Section=='Lightbox'){
		//~ $(Section+'Label').style.borderWidth = '0 1px 0 0';
		//~ $(Section+'Label').style.borderWidth = '0 1px 0 1px';
	//~ }
	//~ //}
	
	//~ if(Section =='Template'){
		//~ ShowTemplates('TemplateTop');
	//~ }
	
	url = "managelightbox.php?action=11&CurrentView="+Section
	 $('CurrentLightboxSection').value =Section;
	new Ajax.Request(url, {
		asynchronous:true,
		method: 'get'
	});
	
	url = "managelightbox.php?action=7&state=1";
	new Ajax.Request(url, {
		asynchronous:true,
		method: 'get'
	});
	
}


function HideLightbox(){
	if($('LightboxShown').value ==1){
		
		$('LightboxShown').value =0;
		//new Effect.Move('LightboxContainer', { x: 0, y: 140, mode: 'relative' });
		new Effect.Morph('LightboxContainer', {
			style: 'height:155px; height: 40px;', // CSS Properties
			duration: 0.8 // Core Effect properties
		});
		new Effect.Morph('Lightbox', {
			style: 'height:155px; height: 40px;', // CSS Properties
			duration: 0.8 // Core Effect properties
		});
		//~ new Effect.Morph($('CurrentLightboxSection').value+'Images', {
			//~ style: 'height:155; height: 35;', // CSS Properties
			//~ duration: 0.8 // Core Effect properties
		//~ });
		$('LightboxShown').value =0;
		
		url = "managelightbox.php?action=7&state=0";
		new Ajax.Request(url, {
			asynchronous:true,
			method: 'get'
		});
	}
}

function ShowHideLightbox(){//Section
	if($('LightboxShown').value ==1){
		HideLightbox();
		$('HideButton').innerHTML = 'Show ^';
		LightboxVal = 0;
	}else if($('LightboxShown').value ==0){
		ShowLightbox( $('CurrentLightboxSection').value);//Section
		$('HideButton').innerHTML = 'Hide v';
		LightboxVal = 1;
	}		
	
	if($('CurrentPage').value=='skinner'){
		ResizeFlash();
	}
	
	//~ LightboxTabs = $('LightboxTabs').value.split(',');
	//~ for (i=0; i < LightboxTabs.length; i++) {
		//~ $(LightboxTabs[i]+'Images').hide();
		//~ if($(LightboxTabs[i]+'Label').style.backgroundColor !='green'){
			//~ $(LightboxTabs[i]+'Label').style.backgroundColor ='#505050';
		//~ }
	//~ }
	
	HideRemoveImage();
	
	//~ Section = $('CurrentLightboxSection').value
	//~ $(Section+'Images').style.display ='inline-block';
	//~ $(Section+'Label').style.backgroundColor ='#111111';
	url = "managelightbox.php?action=7&state="+LightboxVal;
	new Ajax.Request(url, {
		asynchronous:true,
		method: 'get'
	});
}


function AddToLightBox(ImageID, ArtistID, Section, ImageLocation,Combinable,AspectRatio,Customizable){// Width, Height,SecondaryImageID,
	var CurrentImages = Array;
	var CurrentUserImages = Array;
	var CurrentCollabImages = Array;
	
	if($('CurrentImages').value!=''){
		CurrentImages = $('CurrentImages').value.split(',');
		ImageCount = CurrentImages.length
	}else{
		CurrentImages = $('CurrentImages').value.split(',');
		ImageCount= 0;
		
	}
	
	if($('CurrentUserImages').value!=''){
		CurrentUserImages = $('CurrentUserImages').value.split(',');
		UserImageCount = CurrentUserImages.length;
	}else{
		CurrentUserImages = $('CurrentUserImages').value.split(',');
		UserImageCount = 0;
	}
	
	if($('CurrentCollabImages').value!=''){
		CurrentCollabImages = $('CurrentCollabImages').value.split(',');
		CollabImageCount = CurrentCollabImages.length;
	}else{
		CurrentCollabImages = $('CurrentCollabImages').value.split(',');
		CollabImageCount = 0;
	}
	
	TotalImageCount = ImageCount+UserImageCount+CurrentCollabImages;
	ImageExists = ArrayValue(CurrentImages, ImageID);
	CollabImageExists = ArrayValue(CurrentCollabImages, ImageID);




	/*************************
	
	Ugh. More Mr. Men Hardcoding
	this lets folks know that this image 
	
	*****************************/
	Liscencing = 0;
	if(ArtistID ==181){
		ValidCountries = $('ValidMrMenCountries').value.split(',');
		ValidUserCountry = ArrayValue(ValidCountries, $('UserIPCountry').value);
		
		if(ValidUserCountry==0){ // this means the country is not allowed
			Customizable = 0;
			Liscencing = 1;
		}
	}
	
	
	//ShowLightbox('Lightbox'); // make sure the lightbox is shown when adding
	
	ImageName = $('SelectedImageName').value;
	ArtistName = $('SelectedArtistName').value;
	ImageAspectRatio = AspectRatio//$('SelectedAspectRatio').value;
	ImageSize = $('ColumnSize').value
	
	if(ImageSize==''){
		ImageSize = 235;
	}
	ImageHeight = Math.round(parseInt(ImageSize)*AspectRatio);
	if(Section == 'stock'){
		if(ImageExists == 0){
			/*NewImage = '<div id="ImageThumb'+ImageID+'" style="width:90px;display:inline-block;"><img src="images/skins/'+ImageID+'-2.jpg" onmouseover="javascript:ShowRemoveImage('+ImageID+',\'gs\','+ArtistID+');" onmouseout="javascript:HideRemoveImage();" style="height:75px; width:75px;" class="reflect rheight15"></div>';
			$('LightboxImages').innerHTML += NewImage ;
			ManageList(ImageID, 'CurrentImages','add');**/
			
			
			
			/** ADD TO SESSION ***/
			url = "managelightbox.php?action=1&ImageID="+ImageID;
			url += "&ImageName="+ImageName
			url += "&ArtistID="+ArtistID
			url += "&ArtistName="+ArtistName
			url += "&Combinable="+Combinable
			url += "&Customizable="+Customizable
			
			new Ajax.Request(url, {
				asynchronous:true,
				method: 'get',
				onSuccess: function(transport){	
					$('RolloverFavoriteStar').innerHTML = '<a href="javascript:void(0);" onmouseover="javascript:ShowRemoveImage('+ImageID+', \''+Section+'\','+ArtistID+','+ImageID+');" onmousedown="javascript:RemoveImage();" style="text-decoration:none; color:white;display:block; margin-top:10px;"><img src="images/icons/favicon.png" border="0" alt="Add to Favorites" title="Add to Favorites"></a>';
					
					$('Browse'+ImageID).innerHTML = '<img id="BrowseImage'+ImageID+'" src="images/imagedispatcher.php?id='+ImageID+'&size='+ImageSize+'&dim=x&star=1" style="width:'+ImageSize+'px; height:'+ImageHeight+'px;">';
					$('FavoriteDisplayCount').value = parseInt($('FavoriteDisplayCount').value)+1;
					$('FavoriteCount').innerHTML ='('+$('FavoriteDisplayCount').value+')';
					
					/*************************
	
					Ugh. More Mr. Men Hardcoding
					This will display a popup telling folks that they cannot use
					this image in the customizer
					
					*****************************/
					if(Liscencing==1){
						ShowLiscensingNotice();
					}
					
				
					
				}
			});
			
			$('SessionArtSelected').value = 1 ;
			
			/*if(ImageCount==0){
				$('ContextNextButton').innerHTML = 'Welcome to your lightbox. <br> This is used to create custom skins. Confuised? <a href="help.php?s=custom">Click here</a>';
			}else{*/
				//$('ContextNextButton').innerHTML = '';
				//~ if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 0){
					//~ $('ContextNextButton').innerHTML = '<input type="button" value="Select Template" style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;" onclick="window.location=\'create.php\'">';
				//~ }else if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 1){
					//~ $('ContextNextButton').innerHTML = '<input type="button" value="Start Customizing" style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;"  onclick="window.location=\'skinner.php\'">';
				//~ }
			//}
		}
	}else if (Section =='collab'){
		if(CollabImageExists==0){
			/*NewImage = '<div id="CollabImageThumb'+ImageID+'" style="width:90px;display:inline-block;"><img src="images/collabs/'+ImageID+'-2.jpg" onmouseover="javascript:ShowRemoveImage('+ImageID+',\'collab\','+ArtistID+');" onmouseout="javascript:HideRemoveImage();" style="height:75px; width:75px;" class="reflect rheight15"></div>';
			$('LightboxImages').innerHTML += NewImage ;
			ManageList(ImageID, 'CurrentCollabImages','add');
			
			/** ADD TO SESSION ***/
			url = "managelightbox.php?action=9&ImageID="+ImageID;
			url += "&ImageName="+ImageName
			url += "&ArtistID="+ArtistID
			url += "&ArtistName="+ArtistName
			url += "&Combinable="+Combinable
			url += "&Customizable="+Customizable
	
			new Ajax.Request(url, {
				asynchronous:true,
				method: 'get',
				onSuccess: function(transport){	
					$('RolloverFavoriteStar').innerHTML = '<a href="javascript:void(0);" onmouseover="javascript:ShowRemoveImage('+ImageID+', \''+Section+'\','+ArtistID+','+ImageID+');" onmousedown="javascript:RemoveImage();" style="text-decoration:none; color:white;display:block; margin-top:10px;"><img src="images/icons/favicon.png" border="0" alt="Add to Favorites" title="Add to Favorites"></a>';
					$('Browse'+ImageID).innerHTML = '<img id="BrowseImage'+ImageID+'" src="images/imagedispatcher.php?id='+ImageID+'&size='+$('ColumnSize').value+'&dim=x&star=1" style="width:'+ImageSize+'px; height:'+ImageHeight+'px;">';
					$('FavoriteDisplayCount').value = parseInt($('FavoriteDisplayCount').value)+1;
					$('FavoriteCount').innerHTML ='('+$('FavoriteDisplayCount').value+')';
					//~ $('Browse'+ImageID).innerHTML = '<img src="images/imagedispatcher.php?id='+ImageID+'&size='+$('ColumnSize').value+'&dim=x&star=1" onmousedown="window.location=\'image.php?ImageID='+ImageID+'\'" onmouseover="ShowImageTabs('+ImageID+','+ArtistID+',\''+ImageName+'\',\''+ArtistName+'\',\'collab\','+Combinable+')" onmouseout="HideImageTabs('+ImageID+')">';
					
				}
			});
			
			$('SessionArtSelected').value = 1 ;
			/*if(ImageCount==0){
				$('ContextNextButton').innerHTML = 'Welcome to your lightbox. <br> This is used to create custom skins. Confuised? <a href="help.php?s=custom">Click here</a>';
			}else{*/
				//$('ContextNextButton').innerHTML = '';
				//~ if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 0){
					//~ $('ContextNextButton').innerHTML = '<input type="button" value="Select Template" style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;" onclick="window.location=\'create.php\'">';
				//~ }else if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 1){
					//~ $('ContextNextButton').innerHTML = '<input type="button" value="Start Customizing" style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;"  onclick="window.location=\'skinner.php\'">';
				//~ }
			//}
		}
	}else if(Section=='user'){
		/*OldImages = $('LightboxImages').innerHTML 
		NewImage = '<div id="UserImageThumb'+ImageID+'" style="padding:10px; display:inline-block;"><img src="'+ImageLocation+'/'+ArtistID+'/thumbs/'+ImageID+'-1.jpg" onmouseover="javascript:ShowRemoveImage('+ImageID+',\'user\','+ArtistID+','+SecondaryImageID+');" onmouseout="javascript:HideRemoveImage();"></div>';
		$('LightboxImages').innerHTML = NewImage+OldImages ;
		ManageList(ImageID, 'CurrentUserImages','add');
		
		if(ImageCount==0){
			$('ContextNextButton').innerHTML = 'Welcome to your lightbox.<br> This is used to create custom skins. Confuised? <a href="help.php?s=custom">Click here</a>';
		}else{
			$('ContextNextButton').innerHTML = '';
		}
		//ManageList(ImageID, 'CurrentImages','add');
		
		/** ADD TO SESSION ***/
	/*	url = "managelightbox.php?action=5&UserImageID="+ImageID;
		url += "&ArtistID="+ArtistID
		new Ajax.Request(url, {
			asynchronous:true,
			method: 'get'
		});
		*/
		$('SessionArtSelected').value = 1 ;
		
		//~ if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 0){
			//~ $('ContextNextButton').innerHTML = '<input type="button" value="Select Template" style="height:50px; border:0; background-color:grey; -moz-border-radius:5px; color:white; font-weight:bold;" onclick="window.location=\'create.php\'">';
		//~ }else if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 1){
			//~ $('ContextNextButton').innerHTML = '<input type="button" value="Start Customizing" style="height:50px; border:0; background-color:grey; -moz-border-radius:5px; color:white; font-weight:bold;"  onclick="window.location=\'skinner.php\'">';
		//~ }
	}else if(Section=='temp'){
		/*OldImages = $('LightboxImages').innerHTML 
		NewImage = '<div id="UserImageThumb'+ImageID+'" style="padding:10px; display:inline-block;"><img src="upload/'+ArtistID+'/thumbs/'+ImageID+'-1.jpg" onmouseover="javascript:ShowRemoveImage('+ImageID+',\'user\','+ArtistID+');" onmouseout="javascript:HideRemoveImage();"></div>';
		$('LightboxImages').innerHTML = NewImage+OldImages ;
		//ManageList(ImageID, 'CurrentImages','add');
		
		/** ADD TO SESSION ***/
		/*url = "managelightbox.php?action=1&ImageID="+ImageID;
		url += "&ArtistID="+ArtistID
		new Ajax.Request(url, {
			asynchronous:true,
			method: 'get'
		});*/
		
		$('SessionArtSelected').value = 1 ;
		/*if(ImageCount==0){
			$('ContextNextButton').innerHTML = 'Welcome to your lightbox. This is used to create custom skins. Confuised? <a href="help.php?s=custom">Click here</a>';
		}else{*/
		//	$('ContextNextButton').innerHTML = '';
	
		//}
		
	}
	/*
	if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 0){
		$('ContextNextButton').innerHTML = '<input type="button" value="Select Template" style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;" onclick="window.location=\'create.php\'">';
	}else if($('SessionArtSelected').value == 0 && $('SessionTemplateSelected').value == 1){
		$('ContextNextButton').innerHTML = '<input type="button" value="Select Artwork"  style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;" onclick="window.location=\'artwork.php\'">';
	}else if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 1){
		$('ContextNextButton').innerHTML = '<input type="button" value="Start Customizing"  style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;"  onclick="window.location=\'skinner.php\'">';
	}*/
	
	
	/*if(TotalImageCount==0){
		new Effect.Highlight('LightboxLabel', {
		startcolor: "#111111",
		endcolor: "green",
		restorecolor: "green",
		duration: 1,
		});
	}*/
	//$('LightboxLabel').innerHTML = '<a href="javascript:void(0);" onclick="javascript:ShowLightbox(\'Lightbox\');" style="color:white; font-family:Myriad Pro, Helvetica, Sans; font-size:12px; font-weight:normal; text-decoration:none;">My Images</a><img src="images/common/checkmark.png" border="0"style="height:10px; padding-left:5px;"><div style="font-family:Myriad Pro, Helvetica, Sans; font-size:12px; display:inline; color:grey">(<a href="artwork.php" style="font-family:Myriad Pro, Helvetica, Sans; font-size:12px; display:inline; color:grey; text-decoration:none;">add more</a>)</div>';
	
	
	UpdateLightbox('Lightbox');
	if($('PopupMessageRecieved').value != 1 ){
	//	PromptUser(1);
	}
	
	
//	addReflections();
}



function AddTemplateToLightBox(DeviceID, CategoryID,DevicePrice,Combo,ComboPrice){
	
	var CurrentTemplates = Array;
	
	CurrentTemplates = $('CurrentTemplates').value.split(',');
	ImageExists = ArrayValue(CurrentTemplates, DeviceID);
	if(ImageExists == 0){
	
		// make sure the lightbox is shown when adding
		
		
			//OldTemplateList = $('TemplateImages').innerHTML 
		/*	NewTemplate = '<div style="display:inline-block;" id="UserTemplateThumb'+DeviceID+'"><img src="'+$('HostBase').value+'images/devices/device_'+DeviceID+'_100.jpg" onmouseover="javascript:ShowRemoveImage('+DeviceID+',\'template\','+CategoryID+');" onmouseout="javascript:HideRemoveImage();" style="height:75px; width:75px;" ></div>';
			$('TemplateImages').innerHTML += NewTemplate;*/
			//$('TemplateThumb'+DeviceID).style.opacity = 0.5;
			ManageList(DeviceID, 'CurrentTemplates','add');
			
			var url = 's3cr3td4t4/devices/device-'+DeviceID+'-1.xml';
			var xml = new JKL.ParseXML( url );
			var data = xml.parse(xml);
			DeviceTitle = data.device.secondaryname;
			DeviceDescription = data.device.description;
			DeviceDetails = data.device.dimensions;
			/** ADD TO SESSION ***/
			url = "managelightbox.php?action=2&DeviceID="+DeviceID;
			url += "&CategoryID="+CategoryID+"&DeviceName="+DeviceTitle
			url += "&DevicePrice="+DevicePrice+"&DeviceDescription="+DeviceDescription;
			url += "&Combo="+Combo;
			url += "&ComboPrice="+ComboPrice;
			url += "&DeviceDetails="+DeviceDetails;
			new Ajax.Request(url, {
				asynchronous:true,
				method: 'get',
				onSuccess: function(transport){	
					if(transport.responseText==1){
						UpdateLightbox('Template');
						//~ if($('SessionTemplateSelected').value ==0 ){
							//~ $('SessionTemplateSelected').value = 1 ;
							//~ if($('SessionArtSelected').value == 1){
								//~ window.location='skinner.php';
							//~ }else{
								 window.location='artwork.php';
							//~ }
						//~ }
					}
				}
			});
	}	
			
			
			/*DeviceInfo='';
			DeviceInfo += '<div align="left" style="display:inline-block">';
				DeviceInfo +='<div style="display:inline-block;vertical-align:middle; padding-top:20px; text-align:center; color: white;"><img src="images/devices/device_'+DeviceID+'_100.jpg" style="height:60px;"></div>';
				DeviceInfo +='<div style="display:inline-block; text-align:left; vertical-align:top;">';
					DeviceInfo +='<h2 class="h6" style="font-weight:normal; font-family:Myriad Pro, Arial, Helvetica, Sans; font-size:13px;padding-left:25px; color:white;">GelaSkins for '+DeviceTitle+'</h2>';
					DeviceInfo +='<div class="ProductDescription" style="padding-left:25px; max-width:750px; text-align:left;font-weight:normal; font-family:Myriad Pro, Arial, Helvetica, Sans; font-size:13px; color:#a0a0a0;">'+DeviceDescription+'</div>';
				DeviceInfo +='</div>';
			DeviceInfo +='</div>';
			
			
			$('TemplateLabel').innerHTML  = '<a href="javascript:void(0);" onclick="javascript:ShowLightbox(\'Template\');" style="color:white; font-family:Myriad Pro, Helvetica, Sans; font-size:12px; font-weight:normal; text-decoration:none;">My Design Template: '+DeviceTitle+'</a> <div style="display:inline-block;"><a href="create.php" style="font-family:Myriad Pro, Helvetica, Sans; font-size:12px; display:inline; color:grey; text-decoration:none;">(change)</a></div>'
			$('TemplateImages').innerHTML = DeviceInfo;
			$('CurrentTemplateName').value = DeviceTitle;*/
			/*
			<a href="javascript:void(0);" onclick="javascript:ShowLightbox(\'Template\');" style="color:black; font-family:Myriad Pro, Helvetica, Sans; font-size:12px; font-weight:normal; text-decoration:none;">DEVICE TEMPLATES - '.$DeviceTitle .'</a> <div style="display:inline-block;">'.$DevicePrompt.'</div>
			*/
	//~ }
		
			/*if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 1){
				window.location='skinner.php';
			}else if($('SessionArtSelected').value == 0 && $('SessionTemplateSelected').value == 1){
				window.location='artwork.php';
			}*/
			
			/*if($('SessionArtSelected').value == 0 && $('SessionTemplateSelected').value == 1){
				$('ContextNextButton').innerHTML = '<input type="button" value="Select Artwork" style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;" onclick="window.location=\'home.php\'">';
			}else if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 1){
				$('ContextNextButton').innerHTML = '<input type="button" value="Start Customizing" style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;"  onclick="window.location=\'skinner.php\'">';
			}*/
		//window.location='skinner.php';
	//~ }
	
	//~ if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 0){
		//~ $('ContextNextButton').innerHTML = '<input type="button" value="Select Template"  style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;" onclick="window.location=\'create.php\'">';
	//~ }else if($('SessionArtSelected').value == 0 && $('SessionTemplateSelected').value == 1){
		//~ $('ContextNextButton').innerHTML = '<input type="button" value="Select Artwork"  style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;" onclick="window.location=\'artwork.php\'">';
	//~ }else if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 1){
		//~ $('ContextNextButton').innerHTML = '<input type="button" value="Start Customizing"  style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;" onclick="window.location=\'skinner.php\'">';
	//~ }
	
	//~ if($('TemplatePopupMessageRecieved').value != 1 ){
		//~ //PromptUser(2);
	//~ }
	
	//ShowLightbox('Template'); 
}

function ShowTemplates(SectionID){

	/*DevicesTabs = $('DeviceIDs').value.split(',');
	for (i=0; i < LightboxTabs.length; i++) {
		$(DevicesTabs[i]+'Templates').hide();
	}
	$('TemplateTop').hide();

	if(SectionID=='TemplateTop'){
		$('TemplateTop').show();
	}else{
		$(SectionID+'Templates').show();
	}*/


}

function ShowRemoveImage(ImageLocationID, Section, ArtistID,ImageID,Combinable,AspectRatio ){
	if($('LightboxShown').value==1){
		LeftAdj = 0 ;
		if(Section =='stock'){
			ImagePrefix = 'ImageThumb';
		}else if(Section == 'collab'){
			ImagePrefix = 'CollabImageThumb';
		}else if(Section == 'user'){
			ImagePrefix = 'UserImageThumb';
		}else if(Section == 'template'){
			ImagePrefix = 'UserTemplateThumb';
			LeftAdj  = 25;
		}
		
		/** THESE IDS
		are misnomers for Template removal
		RemoveID = TemplateID
		RemoveArtistID = CategoryID
		***/
		$('RemoveSection').value = Section;
		$('RemoveLocation').value = ImageLocationID;
		$('RemoveID').value = ImageID;
		$('RemoveArtistID').value = ArtistID;
		$('RemoveCombinable').value = Combinable;
		$('RemoveAspectRatio').value = AspectRatio;
		
		//~ $('RemoveImageIcon').style.top = $('LightboxContainer').offsetTop+$(ImagePrefix+ImageLocationID).offsetTop+document.documentElement.scrollTop+25+'px';
		//~ $('RemoveImageIcon').style.left = $(ImagePrefix+ImageLocationID).offsetLeft+LeftAdj+390+'px';//+((document.body.clientWidth/100) *33);//
		//~ $('RemoveImageIcon').style.display = 'block';
	}
}

function HideRemoveImage(){
	$('RemoveImageIcon').hide();
}

function PrepRemoveImage(ImageLocationID, Section, ArtistID,ImageID,Combinable){
	$('RemoveSection').value = Section;
	$('RemoveLocation').value = ImageLocationID;
	$('RemoveID').value = ImageID;
	$('RemoveArtistID').value = ArtistID;
	$('RemoveCombinable').value = Combinable;
}

function PrepRemoveImage_skynet(ImageLocationID, Section, ArtistID,ImageID, ImageFiletype){
	$('RemoveSection').value = Section;
	$('RemoveLocation').value = ImageLocationID;
	$('RemoveID').value = ImageID;
	$('RemoveArtistID').value = ArtistID;
	$('RemoveSuffix').value= ImageFiletype;
}


function RemoveImage(){
	/** THESE IDS
	are misnomers for Template removal
	RemoveID = TemplateID
	RemoveArtistID = CategoryID
	***/
	Section = $('RemoveSection').value;
	ImageID = $('RemoveID').value;
	ImageLocation = $('RemoveLocation').value;
	ArtistID = $('RemoveArtistID').value;
	OldSection = $('RemoveSection').value;
	Combinable = $('RemoveCombinable').value ;
	ImageSize =$('ColumnSize').value ;
	AspectRatio =$('RemoveAspectRatio').value ;
	ImageHeight = Math.round(parseInt(ImageSize)*AspectRatio);
	if(Combinable == ''){
		Combinable =0;
	}

	switch(Section){
		case 'stock':
			ImageLocation = ImageID
			url = "managelightbox.php?action=3&ImageID="+ImageID;
			url += "&ArtistID="+ArtistID;
			Section = 'Lightbox';
			$('FavoriteDisplayCount').value = parseInt($('FavoriteDisplayCount').value)-1;
			break;
		case 'collab':
			url = "managelightbox.php?action=10&ImageID="+ImageID+"&UserImageID="+ImageLocation;
			url += "&ArtistID="+ArtistID;
			Section = 'Lightbox';
			$('FavoriteDisplayCount').value = parseInt($('FavoriteDisplayCount').value)-1;
			break;
		case 'user':
			url = "managelightbox.php?action=6&ImageID="+ImageID+"&UserImageID="+ImageLocation;
			url += "&ArtistID="+ArtistID;
			Section = 'Lightbox';
			break;
		case 'skynet':
			url = "managelightbox.php?action=6&ImageID="+ImageID+"&UserImageID="+ImageLocation;
			url += "&ArtistID="+ArtistID;
			url += "&ext="+$('RemoveSuffix').value;
			url += "&UserDirectory="+$('UserDirectory').value;
			url += "&skyn3t=1";
			break;
		case 'template':
			url = "managelightbox.php?action=4&DeviceID="+ImageID;
			url += "&CategoryID="+ArtistID;
			Section = 'Template';
			break;
		

	}
	
	new Ajax.Request(url, {
			asynchronous:true,
			method: 'get',
			onSuccess: function(transport){	
				imagetesturl = "managelightbox.php?action=13";
				new Ajax.Request(imagetesturl, {
						asynchronous:true,
						method: 'get',
						onSuccess: function(transport){	
							if(transport.responseText==0){
								$('SessionArtSelected').value =0;
							}
							//~ Combinable  =$('RemoveCombinable').value; 
							$('RolloverFavoriteStar').innerHTML = '<a href="javascript:void(0);" onclick="javascript: AddToLightBox('+ImageLocation+','+ArtistID+', \''+OldSection+'\','+ImageID+','+Combinable +')" style="text-decoration:none; color:white;display:block; margin-top:10px;"><img src="images/icons/favicon-grey.png"  alt="Remove from Favorites" title="Remove from Favorites"></a>';
							$('Browse'+ImageID).innerHTML = '<img id="BrowseImage'+ImageID+'" src="images/imagedispatcher.php?id='+ImageID+'&size='+$('ColumnSize').value+'&dim=x&star=0" onmousedown="window.location=\'image.php?ImageID='+ImageID+'\'" style="height:'+ImageHeight+'px; width:'+ImageSize+'px;">';
							$('FavoriteCount').innerHTML ='('+$('FavoriteDisplayCount').value+')';
						}
				});
			}
	});
	
	if(Section=='template'){
		RemoveTemplateFromLightbox(ImageID);
	}else{
		RemoveFromLightbox(ImageLocation, Section);
	}

	
	UpdateLightbox(Section);
	

}

function RemoveTemplate(){
	/*url = "managelightbox.php?action=4&DeviceID="+DeviceID+"&Category="+CategoryID;
		new Ajax.Request(url, {
			asynchronous:true,
			method: 'get'
	});*/
	
	RemoveTemplateFromLightbox();

}

function RemoveFromLightbox(ImageID, Section){

	var ImageCount=0;
	var UserImageCount=0;
	var CollabCount=0;
	
	
	
	if(Section =='stock'){
		ImagePrefix = 'ImageThumb';
		ManageList(ImageID, 'CurrentImages','remove');
		if($('CurrentImages').value !=''){
			ImageCount =$('CurrentImages').value.split(',').length;
		}else{
			ImageCount =0;
		}
	}else if(Section == 'user'){
		ImagePrefix = 'UserImageThumb';
		ManageList(ImageID, 'CurrentUserImages','remove');
		if($('CurrentUserImages').value !=''){
			UserImageCount = $('CurrentUserImages').value.split(',').length;
		}else{
			UserImageCount=0;
		}
	}else if(Section == 'collab'){
		ImagePrefix = 'CollabImageThumb';
		ManageList(ImageID, 'CurrentCollabImages','remove');
		if($('CurrentCollabImages').value !=''){
			CollabCount = $('CurrentCollabImages').value.split(',').length
		}else{
			CollabCount=0;
		}
	}
	
	/*
	TotalImageCount = ImageCount+ CollabCount+UserImageCount;
	HideRemoveImage();
	if(TotalImageCount == 0){
		MessageText = '<div style="width:1000px; text-align:center;font-weight:normal; font-family:Myriad Pro, Arial, Helvetica, Sans; font-size:25px; color:white; padding-top:15px;">';
		MessageText +=  'You have not added any artwork yet';
		MessageText += '</div>';
		MessageText += '<div style="width:1000px;text-align:center;"><a  href="artwork.php" style=" text-align:center;font-weight:normal; font-family:Myriad Pro, Arial, Helvetica, Sans; font-size:15px; color:white; padding-top:25px; ">Click here to start adding images</a></div>';
		$('LightboxImages').innerHTML =MessageText;
		$('LightboxLabel').style.backgroundColor='#069adf';
		$('LightboxLabel').innerHTML='<a href="javascript:void(0);" onclick="javascript:ShowLightbox(\'Lightbox\');" style="color:white; font-family:Myriad Pro, Helvetica, Sans; font-size:12px; font-weight:normal; text-decoration:none;">My Images</a> <div style="font-family:Myriad Pro, Helvetica, Sans; font-size:12px; display:inline; color:grey">(<a href="artwork.php" style="font-family:Myriad Pro, Helvetica, Sans; font-size:12px; display:inline; color:grey; text-decoration:none;">add more</a>)</div>';
	}*/
	
	if(Section!='skynet'){
		//~ $(ImagePrefix+ImageID).innerHTML ='';
		//~ $(ImagePrefix+ImageID).style.padding='0';
		//~ HideRemoveImage();
	}
	/** IF THE USER IS ON THE HOME PAGE 
	and this is a user image, delete the secondary display
	**///&& Section == 'user' || Section == 'skynet' ){
	if(($('CurrentPage').value == 'home' || $('CurrentPage').value == 'artwork')) {
		$('HomeUserImage'+$('RemoveID').value).innerHTML = '';
		$('HomeUserImage'+$('RemoveID').value).style.border= '0';
		$('HomeUserImage'+$('RemoveID').value).style.margin= '0';
	}
	UpdateLightbox('Lightbox');
}

function RemoveTemplateFromLightbox(TemplateID){
	$('TemplateThumb'+TemplateID).style.opacity = 1;
	
	$('UserTemplateThumb'+TemplateID).innerHTML ='';
	HideRemoveImage();
	UpdateLightbox('Template');
}


function SwapEditImageName(ImageID){
	if($('DisplayImageName'+ImageID).style.display =='block'){
		$('DisplayImageName'+ImageID).style.display = 'none'
		$('EditImageName'+ImageID).style.display = 'block'
	}else{
		$('DisplayImageName'+ImageID).style.display = 'block'
		$('EditImageName'+ImageID).style.display = 'none'
	}
}

function EditImageName(ImageID,UserImageID){
	url = "managelightbox.php?action=8&ImageID="+ImageID+"&UserImageID="+UserImageID;
	url += "&ImageName="+$('NewImageName'+ImageID).value;
	
	new Ajax.Request(url, {
			asynchronous:true,
			method: 'get'
	});
	
	$('DisplayImageName'+ImageID).innerHTML =$('NewImageName'+ImageID).value;
	SwapEditImageName(ImageID)
}


function ViewImage(ImageFile, FileType, Width, Height){


	if(Width > Height){
		LimitDim = 'x';
		LimitSize = document.body.offsetWidth-50;
	}else if(Height >= Width){
		LimitDim = 'y';
		LimitSize = document.body.offsetHeight-50;
		LimitX = LimitSize*(Width/Height);
	}
	//alert(LimitSize,LimitDim);
	$('popupmask').show();
	$('ViewImage').innerHTML ='<img src="images/imagedispatcher.php?id='+ImageFile+'&size='+LimitSize+'&dim='+LimitDim+'&ext='+FileType+'"><br><a href="javascript:void(0);" onclick="javascript:HideImage();" style="color:black;">(close)</a>';
	if(LimitDim == 'x'){
		$('ViewImage').style.top = 25;
		$('ViewImage').style.left = ((document.body.clientWidth/2)-parseInt(LimitSize/2) );
	}else if(LimitDim == 'y'){
		$('ViewImage').style.top = 25;
		$('ViewImage').style.left = ((document.body.clientWidth/2)-parseInt(LimitX/2) );
	}
	$('ViewImage').show();
}


function HideImage(){
	$('popupmask').hide();
	$('ViewImage').hide();
}


function PromptUser(MessageType){
	
	switch(MessageType){
		case 1:
			MessageText = '<div style="font-weight:bold; padding-bottom:25px;">GelaSkins Custom</div><p>You\'ve just added a new image to the \'My Images\' toolbar at the bottom of the page. These are the images that you will use to create your custom GelaSkin. </p>';
			if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 0){
				MessageText += '<div style="padding-bottom:15px;"> - Click \'Continue\' to proceed to the Template Selection stage</div>';
				MessageText += '<div style="padding-bottom:15px;"> - Click \'Close\' to keep browsing for more images</div>';
				MessageText += '<p>You can skip to the Template Selection stage at any time by clicking CREATE on the toolbar at the top of the page</p>'
				ButtonValue =1;
			}else if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 1){
				MessageText += '<div style="padding-bottom:15px;"> - Click \'Continue\' to proceed to the custom Layout stage</div>';
				MessageText += '<div style="padding-bottom:15px;"> - Click \'Close\' to keep browsing for more images</div>';
				MessageText += '<p>You can start your custom layout at any time by clicking \'Continue to Layout\' on the toolbar below </p>'
				ButtonValue =2;
			}
			
			MessageText += '<input type="checkbox" value="1" id="HideThisMessage" name="HideThisMessage"> Don\'t show this message again.<br>'
			MessageText += '<p><input type="button" value="Close" onclick="ClosePopup('+ButtonValue+',0);"> | <input type="button" value="Continue" onclick="ClosePopup('+ButtonValue+',1);"></p>';
			break;
		case 2: // TEMPLATE MESSAGES
			MessageText = '<div style="font-weight:bold; padding-bottom:25px;">GelaSkins Custom</div><p>You\'ve just selected a new design template for your custom GelaSkin: '+$('CurrentTemplateName').value +'</p>';
			if($('SessionArtSelected').value == 0 && $('SessionTemplateSelected').value == 1){
				MessageText += '<p>The next step is to select the artwork that you would like to use with this template. </p><div style="padding-bottom:15px;"> - Click \'Continue\' start adding your artwork for your custom project.</div><div style="padding-bottom:15px;"> - Click \'Close\' below to choose a different Design Template.</div>';
				ButtonValue =3;
			}else if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 1){
				MessageText += '<p>We see that you already have artwork in your \'My Images\' toolbar so you\'re ready for the layout stage.</p><div style="padding-bottom:15px;"> - Click \'Continue\' to proceed to the custom layout stage.</div><div style="padding-bottom:15px;"> - Click \'Add More Images\' to browse for more images.</div><div style="padding-bottom:15px;"> - Click \'Close\' below to choose a different Design Template.</div>';
				ButtonValue =2;
			}
			MessageText += '<input type="checkbox" value="1" id="HideThisMessage" name="HideThisMessage"> Don\'t show this message again.<br>'
			//MessageText += ' or if you want to select some more images click close. When you are ready to begin click create.</p>';
			MessageText += '<p><input type="button" value="Close" onclick="ClosePopup('+ButtonValue+',0);"> | ';
			if(ButtonValue==2){
				MessageText += '<input type="button" value="Add More Images" onclick="window.location=\'artwork.php\'"> |';
			}
			
			MessageText += '<input type="button" value="Continue" onclick="ClosePopup('+ButtonValue+',1);"></p>';
			break;
	}
	
	$('PopupText').innerHTML =MessageText;
	$('popupmask').show();
	$('PopupText').style.top = 150;
	$('PopupText').style.left = ((document.body.clientWidth/2)-parseInt(400/2) );
	$('PopupText').show();
	
}

function ClosePopup(Action,Redir){

	$('PopUpText').hide();	
	$('PopUpMask').hide();
	//~ $('PopupMessageRecieved').value =1;
	//~ MessageHide = $('HideThisMessage').checked;
	//~ if(Action ==1){
		
		//~ if($('HideThisMessage').checked){
			//~ $('PopupMessageRecieved').value =1;
			//~ url = "managepopup.php?popupaction="+Action;

			//~ new Ajax.Request(url, {
					//~ asynchronous:true,
					//~ method: 'get'
			//~ });
		//~ }
		//~ if(Redir==1){
			//~ window.location = 'create.php';
		//~ }
	//~ }else if(Action ==2){
		
			
		//~ if($('HideThisMessage').checked){
			
			//~ $('TemplatePopupMessageRecieved').value =1;
		//~ }
		//~ if(Redir==1){
			//~ window.location = 'skinner.php';
		//~ }
	//~ }else if(Action ==3){
		
		//~ if(MessageHide=='true'){
			//~ $('TemplatePopupMessageRecieved').value =1;
			//~ url = "managepopup.php?popupaction="+Action;
			
			//~ new Ajax.Request(url, {
					//~ asynchronous:true,
					//~ method: 'get'
			//~ });
		//~ }
		//~ if(Redir==1){
			//~ window.location = 'artwork.php';
		//~ }
	//~ }
}


function HightlightTab(TabName){

	 new Effect.Highlight(TabName+'Label', 
		{
		startcolor: "#111111",
		endcolor: "#069adf",
		restorecolor: "#111111",
		duration: 1,
		afterUpdate:ShowLightbox(TabName)
		});
		
	ShowLightbox(TabName)
	
}

function UpdateLightbox(Section){
	url = "managelightbox.php?action=12&page="+$('CurrentPage').value
		new Ajax.Request(url, {
			asynchronous:true,
			method: 'get',
			onSuccess: function(transport){	
				$('ThisIsTheLightbox').innerHTML = decodeURIComponent(transport.responseText);
				//~ ShowLightbox(Section); 
				//~ Droppables.add('LightboxImages', { 
				//~ accept: 'draggable',
				//~ hoverclass: 'hover',
				//~ onDrop: function() {
					//~ AddToLightBox($('SelectedImageID').value, $('SelectedArtistID').value, $('SelectedImageSection').value);
				
				//~ }
			//~ },'Lightbox', { 
				//~ accept: 'draggable',
				//~ hoverclass: 'hover',
				//~ onDrop: function() {
					//~ AddToLightBox($('SelectedImageID').value, $('SelectedArtistID').value, $('SelectedImageSection').value);
				
				//~ }
			//~ });
			}
		});
		//addReflections();	
}

function GetLightboxTemplate(){
	url = "managelightbox.php?action=22";
	hostbase = $('HostBase').value
	
	var xml = new JKL.ParseXML( url );
	var data = xml.parse(xml);

	DeviceArray = new Array;
	DeviceArray[0] = data.device.id
	DeviceArray[1] = data.device.name
	DeviceArray[2] = data.device.description
	DeviceArray[3] = data.device.price
	DeviceArray[4] = data.device.combo
	DeviceArray[5] = data.device.comboprice
	DeviceArray[6] = '/images/devices/device_'+data.device.id+'_100.png';
	return DeviceArray;
	
}

function GetLightboxImages(){
	url = "managelightbox.php?action=14";
	hostbase = $('HostBase').value
	//~ url = "managelightbox.php?action=12&page="+$('CurrentPage').value
		new Ajax.Request(url, {
			asynchronous:true,
			method: 'get',
			onSuccess: function(transport){
				return transport.responseText;
			}
		});
		
	//~ var xml = new JKL.ParseXML( url );
	//~ var data = xml.parse(xml);
	//~ var ImageArray = new Array;
	
	//~ if(data.images.image.length == undefined){
		/*//~ ImageArray[0] = new Array;
		ImageArray[0][0] = data.images.device.id
		ImageArray[0][1] = data.images.device.name
		ImageArray[0][2] = data.images.device.description
		ImageArray[0][3] = data.images.device.price
		ImageArray[0][4] = data.images.device.combo
		ImageArray[0][5] = data.images.device.comboprice*/
		
		//~ ImageArray[0] = new Array;
		//~ if(data.images.image.type=='collab'){
			//~ ImageArray[0][0] = hostbase+'/images/imagedispatcher.php?id='+data.images.image.id+'&size=75&dim=det&reflection=1&collaborator=1';//hostbase+data.images.image.thumb;
		//~ }else if(data.images.image.type=='upload'){
			//~ ImageArray[0][0] = hostbase+'/images/imagedispatcher.php?id='+data.images.image.id+'&ext='+data.images.image.imagetype+'&size=75&dim=det&reflection=1&user=1';//hostbase+data.images.image.thumb;
		//~ }else{
			//~ ImageArray[0][0] = hostbase+'/images/imagedispatcher.php?id='+data.images.image.id+'&size=75&dim=det&reflection=1';//hostbase+data.images.image.thumb;
		//~ }
		
		//~ ImageArray[0][1] = hostbase+data.images.image.full;
		//~ ImageArray[0][2] = data.images.image.id;
		//~ ImageArray[0][3] = data.images.image.type;
		//~ ImageArray[0][4] = data.images.image.name;
		//~ ImageArray[0][5] = data.images.image.artist;
		//~ /*//ImageArray[0][2] = hostbase+data.images.image.id;
		//~ //$('LightboxReturns').innerHTML += '<img src="'+hostbase+data.images.image.full+'">';*/
	//~ }else{
	
		/*//~ ImageArray[0] = new Array;
		ImageArray[0][0] = data.images.device.id
		ImageArray[0][1] = data.images.device.name
		ImageArray[0][2] = data.images.device.description
		ImageArray[0][3] = data.images.device.price
		ImageArray[0][4] = data.images.device.combo
		ImageArray[0][5] = data.images.device.comboprice*/
		
		//~ for(var j = 0; j <data.images.image.length; j++){
			//~ ImageArray[j] = new Array;
			//~ if(data.images.image[j].type=='collab'){
				//~ ImageArray[j][0] = hostbase+'/images/imagedispatcher.php?id='+data.images.image[j].id+'&size=75&dim=det&reflection=1&collaborator=1';//hostbase+data.images.image.thumb;
			//~ }else if(data.images.image[j].type=='upload'){
				//~ ImageArray[j][0] = hostbase+'/images/imagedispatcher.php?id='+data.images.image[j].id+'&ext='+data.images.image[j].imagetype+'&size=75&dim=det&reflection=1&user=1';//hostbase+data.images.image.thumb;
			//~ }else{
				//~ ImageArray[j][0] = hostbase+'/images/imagedispatcher.php?id='+data.images.image[j].id+'&size=75&dim=det&reflection=1';//hostbase+data.images.image.thumb;
			//~ }
			//~ /*//ImageArray[j][0] = hostbase+data.images.image[j].thumb;*/
			//~ ImageArray[j][1] = hostbase+data.images.image[j].full;
			//~ ImageArray[j][2] = data.images.image[j].id;
			//~ ImageArray[j][3] = data.images.image[j].type;
			//~ ImageArray[j][4] = data.images.image[j].name;
			//~ ImageArray[j][5] = data.images.image[j].artist;
		//~ /*//$('LightboxReturns').innerHTML += '<img src="'+hostbase+data.images.image[j].full+'">'*/
		//~ }
	//~ }
	
//~ //	$('LightboxReturns').innerHTML +=ImageArray;
	//~ return ImageArray;
	
}


function RestoreLayout(){

	if($('LayoutID').value!=0){
		
		
		UserImages = $('LayoutUserImages').value.split(',');
		StockImages = $('LayoutStockImages').value.split(',');
		CollabImages = $('LayoutCollabImages').value.split(',');
		if($('LayoutUserImages').value!=''){
			for (i=0; i < UserImages.length; i++) {
				ArtistID = $('ArtistIDuser'+UserImages[i]).value;
				Combinable = $('CombinableStateuser'+UserImages[i]).value;
				SendToFlash(UserImages[i],'user',1,ArtistID,Combinable);
			}
		}
		
		if($('LayoutStockImages').value!=''){
			for (i=0; i < StockImages.length; i++) {
				
				ArtistID = $('ArtistIDstock'+StockImages[i]).value;
				Combinable = $('CombinableStatestock'+StockImages[i]).value;
				//
				SendToFlash(StockImages[i],'stock',1,ArtistID,Combinable);
				//setTimeout( "SendToFlash("+StockImages[i]+",'gs',1)", 5000 );
				
			}
		}
		
		if($('LayoutCollabImages').value!=''){
			for (i=0; i < CollabImages.length; i++) {
				ArtistID = $('ArtistIDcollab'+CollabImages[i]).value;
				Combinable = $('CombinableStatecollab'+CollabImages[i]).value;
				SendToFlash(CollabImages[i],'collab',1,ArtistID,Combinable);
			}
		}
	}
}


function SendToFlash(ImageID,ImageType,Restore,ArtistID,Combinable){
	ImageID = parseInt(ImageID);
	SkinCreator = getSWF('skinCreator');
	//~ alert(ImageID+','+ImageType+','+Restore+','+ArtistID+','+Combinable);
	//~ alert(SkinCreator.addImageFromLightbox(ImageID));
	var ImageSuccess = SkinCreator.addImageFromLightbox(ImageID);	
	
	if(ImageSuccess == true){
		ProcessImageAddition(ImageID,ImageType,Restore,ArtistID,Combinable);
	}else{
		alert("VROOOOOOM F ");
	}
}


function RemoveFromFlash(ImageID,ImageType){
	if(ImageType=='stock'){
		ImageType = 'stock';
	}
	
	
	switch(ImageType){
		case 'user':
			ManageList(ImageID, 'LayoutUserImages','remove');
			break;
		case 'stock':
			ManageList(ImageID, 'LayoutStockImages','remove');
			break;
		case 'collab':
			ManageList(ImageID, 'LayoutCollabImages','remove');
			break;
	}
	
	LayoutID = $('LayoutID').value
	url = "managelightbox.php?action=17";
	url +=  "&LayoutIndex="+LayoutID;
	url +=  "&ImageID="+ImageID;
	url +=  "&ImageType="+ImageType;
	
	new Ajax.Request(url, {
		asynchronous:true,
		method: 'get',
		onSuccess: function(transport){	
			
		}
	});
	
	if($('LayoutUserImages').value=='' &&$('LayoutStockImages').value=='' &&$('LayoutCollabImages').value=='' ){
		DisableEnableLightBox(0,0,ImageID,ImageType)
	}
}

function ProcessImageAddition(ImageID,ImageType,Restore,ArtistID,Combinable){
	var NewTemplate=1;
	
	if($('LayoutUserImages').value != ''){
		NewTemplate = 0;
	}
	if($('LayoutStockImages').value != ''){
		NewTemplate = 0;
	}
	if($('LayoutCollabImages').value != ''){
		NewTemplate = 0;
	}
	
	if(NewTemplate == 1 && $('LayoutID').value == '0'){
		InitializeLayout(ImageID,ImageType,Restore,ArtistID,Combinable);
	}else{
		LayoutID = $('LayoutID').value
		
		switch(ImageType){
			case 'user':
				ManageList(ImageID, 'LayoutUserImages','add');
				break;
			case 'stock':
				ManageList(ImageID, 'LayoutStockImages','add');
				break;
			case 'collab':
				ManageList(ImageID, 'LayoutCollabImages','add');
				break;
		}

		
		
		
		if(Restore == 0){
			url = "managelightbox.php?action=16";
			url +=  "&LayoutIndex="+LayoutID;
			url +=  "&TemplateID="+$('TemplateID').value;
			url +=  "&ImageID="+ImageID;
			url +=  "&ImageType="+ImageType;
			url +=  "&ArtistID="+ArtistID;
			url +=  "&Combinable="+Combinable;
			
			new Ajax.Request(url, {
				asynchronous:true,
				method: 'get',
				onSuccess: function(transport){	
					
				}
			});
		}
		
		
		if(Combinable == 0){
			DisableEnableLightBox(1,1,ImageID,ImageType);
		}else if(Combinable == 1){
			DisableEnableLightBox(1,0,ImageID,ImageType);
		}else if(Combinable == 2){
			DisableEnableLightBox(2,0,$('SkinnerArtistID').value,ImageType);
		}else{
			DisableEnableLightBox(0,0,ImageID,ImageType);
		}
	
		//clearTimeout();
	}
	
	
	
}


function ShowLayoutImages(LayoutID){
	if($('LightboxDebug').value==42){
		/* 
		if  you want to debug the lightbox
		get the data
		
		right now this is just all the images for the given layout
		*/
		
		DebugURL = 'managelightbox.php?action=26';
		DebugURL +=  "&LayoutIndex="+LayoutID;
		new Ajax.Request(DebugURL, {
			asynchronous:true,
			method: 'get',
			onSuccess: function(transport){
				var DebugContent = transport.responseText;
				$('LightboxDebugOutput').innerHTML = DebugContent;
				
			}
		});
	}
}


function InitializeLayout(ImageID,ImageType,Restore,ArtistID,Combinable){
	TemplateID = $('TemplateID').value;
	CategoryID = $('CategoryID').value;
	TemplateName = $('TemplateName').value;
	url = "managelightbox.php?action=15";
	url +=  "&TemplateID="+TemplateID;
	url +=  "&CategoryID="+CategoryID;
	url +=  "&TemplateName="+TemplateName;

	new Ajax.Request(url, {
		asynchronous:true,
		method: 'get',
		onSuccess: function(transport){	
			LayoutID = transport.responseText;
			$('LayoutID').value = LayoutID;
			
			ProcessImageAddition(ImageID,ImageType,Restore,ArtistID,Combinable);
			
		}
	});
			
}


function getSWF(movieName) {
 //~ if (window.document[movieName]) 
  //~ {
      //~ return window.document[movieName];
  //~ }
  //~ if (navigator.appName.indexOf("Microsoft Internet")==-1)
  //~ {
    //~ if (document.embeds && document.embeds[movieName])
      //~ return document.embeds[movieName]; 
  //~ }
  //~ else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  //~ {
    //~ return document.getElementById(movieName);
  //~ }

    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    }
    else {
      if(document[movieName].length != undefined){
          return document[movieName][1];
      }
        return document[movieName];
    }
}
function DisableEnableLightBox(Disable,DisableAll,ExceptMatch,ExceptType){

	url = "managelightbox.php?action=18&page="+$('CurrentPage').value;
	url +=  "&Disable="+Disable;
	url +=  "&DisableAll="+DisableAll;
	url +=  "&ExceptMatch="+ExceptMatch;
	url +=  "&ExceptType="+ExceptType;

	new Ajax.Request(url, {
		asynchronous:true,
		method: 'get',
		onSuccess: function(transport){	
			$('ThisIsTheLightbox').innerHTML = decodeURIComponent(transport.responseText);	
			
			if(DisableAll==1 && Disable==1){
				/**
				MAKE ONLY THE CURRENTLY ADDED
				IMAGE DRAGGABLE
				**/
				switch(ExceptType){
					case 'user':
						new Draggable('UserImageThumb'+ ExceptMatch, { revert: true });
						break;
					case 'stock':
						new Draggable('ImageThumb'+ExceptMatch, { revert: true });
						break;
					case 'collab':
						new Draggable('CollabImageThumb'+ ExceptMatch, { revert: true });
						break;
				}
			}else if(DisableAll==0 && Disable==1){
				/** 
				NEED TO MAKE ONLY IMAGES 
				WHICH ARE COMBINABLE DRAGGABLE 
				**/
				UserCombinableImages = $('CurrentCombinableUserImages').value.split(',');
				StockCombinableImages = $('CurrentCombinableImages').value.split(',');
				CollabCombinableImages = $('CurrentCombinableCollabImages').value.split(',');
				if($('CurrentCombinableUserImages').value!=''){
					for (i=0; i < UserCombinableImages.length; i++) {
						new Draggable('UserImageThumb'+ UserCombinableImages[i], { revert: true });
					}
				}
				
				if($('CurrentCombinableImages').value!=''){
					for (i=0; i < StockCombinableImages.length; i++) {
						new Draggable('ImageThumb'+StockCombinableImages[i], { revert: true });
					}
				}
				
				if($('CurrentCombinableCollabImages').value!=''){
					for (i=0; i < CollabCombinableImages.length; i++) {
						new Draggable('CollabImageThumb'+ CollabCombinableImages[i], { revert: true });
						
					}
				}
				
			}else if(Disable==2){
				/**
				MAKE ALL IMGAES BY THE SAME ARTIST
				draggable
				**/
				url = "managelightbox.php?action=20&ArtistID="+ExceptMatch;
				url += "&ArtistType="+ExceptType;
				new Ajax.Request(url, {
					asynchronous:true,
					method: 'get',
					onSuccess: function(transport){
						EnableIDs = transport.responseText.split(',');
						switch(ExceptType){
							case 'stock':
								ImgPrefix ='ImageThumb';
								break
							case 'collab':
								ImgPrefix ='CollabImageThumb';
								break;
						}
						for (i=0; i < EnableIDs.length; i++) {
							//alert(ImgPrefix+ EnableIDs[i]);
							if($(ImgPrefix+ EnableIDs[i])){
								new Draggable(ImgPrefix+ EnableIDs[i], { revert: true });
							}
						}
					}
				});
			}else if(Disable==0){
				
				UserImages = $('CurrentUserImages').value.split(',');
				StockImages = $('CurrentImages').value.split(',');
				CollabImages = $('CurrentCollabImages').value.split(',');
				if($('CurrentUserImages').value!=''){
					for (i=0; i < UserImages.length; i++) {
						new Draggable('UserImageThumb'+ UserImages[i], { revert: true });
					}
				}
				
				if($('CurrentImages').value!=''){
					for (i=0; i < StockImages.length; i++) {
						new Draggable('ImageThumb'+StockImages[i], { revert: true });
					}
				}
				
				if($('CurrentCollabImages').value!=''){
					for (i=0; i < CollabImages.length; i++) {
						new Draggable('CollabImageThumb'+ CollabImages[i], { revert: true });
						
					}
				}
			
			}


			Droppables.add('SkinnerContainer', { 
				accept: 'draggable',
				hoverclass: 'hover',
				onDrop: function() {
					SendToFlash($('SkinnerImageID').value,$('SkinnerImageType').value,1,$('SkinnerArtistID').value,$('SkinnerCombinable').value);
				}
			});
		}
	})
	
	
}

function RemoveLayout(LayoutID){

	url = "managelightbox.php?action=19&page="+$('CurrentPage').value;
	url +=  "&LayoutIndex="+LayoutID;
	
	new Ajax.Request(url, {
		asynchronous:true,
		method: 'get',
		onSuccess: function(transport){
			if(transport.responseText !=0){
				
				ManageList(LayoutID, 'LayoutList','remove');
				$('LayoutContainer'+LayoutID).innerHTML = '';
				
				if($('LayoutList').value==''){
					$('LayoutListContainer').remove();
				}
			}
		}
	});
	
}

function CompleteLayout(){
	LayoutID = $('LayoutID').value;
	
	if(LayoutID!=0){
		url = "managelightbox.php?action=21&page="+$('CurrentPage').value;
		url +=  "&LayoutIndex="+LayoutID;
		
		new Ajax.Request(url, {
			asynchronous:true,
			method: 'get',
			onSuccess: function(transport){
				if(transport.responseText !=0){
					alert('OK, this layout can be added to the cart');
				}
			}
		});
	}
}


function GetDevice(){
	return $('TemplateID').value;
}

function ResizeFlash(){
	//~ if($('LightboxShown').value==1){
		//~ OldSkinnerContainerHeight = $('SkinnerContainer').style.height;
		//~ OldSkinnerSpacerHeight = $('SkinnerSpacer').style.height ;
		
		//~ $('SkinnerContainer').style.height = "900px";
		SkinnerHeight =  (document.documentElement.clientHeight)-137;
		if(SkinnerHeight<555){
			SkinnerHeight = 555;
		}
		$('SkinnerContainer').style.height =  SkinnerHeight +"px";
		/*$('SkinnerSpacer').style.height = document.documentElement.clientHeight-250+"px";*/
		
		//~ new Effect.Morph('LightboxContainer', {
			//~ style: 'height:'+OldSkinnerContainerHeight+'; height: '+(document.documentElement.clientHeight)-250+'px;', // CSS Properties
			//~ duration: 0.8 // Core Effect properties
		//~ });
		//~ new Effect.Morph('SkinnerSpacer', {
			//~ style: 'height:'+OldSkinnerSpacerHeight+'; height: '+document.documentElement.clientHeight-250+'px;', // CSS Properties
			//~ duration: 0.8 // Core Effect properties
		//~ });

	//~ }else if($('LightboxShown').value==0){
		//~ $('SkinnerContainer').style.height = "900px";//(document.documentElement.clientHeight)-140+
		/*$('SkinnerSpacer').style.height = document.documentElement.clientHeight-140+"px";*/
		//~ OldSkinnerContainerHeight = $('SkinnerContainer').style.height;
		//~ OldSkinnerSpacerHeight = $('SkinnerSpacer').style.height ;
		//~ new Effect.Morph('LightboxContainer', {
			//~ style: 'height:'+OldSkinnerContainerHeight+'; height: '+(document.documentElement.clientHeight)-80+'px;', // CSS Properties
			//~ duration: 0.8 // Core Effect properties
		//~ });
		//~ new Effect.Morph('SkinnerSpacer', {
			//~ style: 'height:'+OldSkinnerSpacerHeight+'; height: '+document.documentElement.clientHeight-80+'px;', // CSS Properties
			//~ duration: 0.8 // Core Effect properties
		//~ });
	//~ }
}

function GetWindowDimensions(){
	$('CurrentWindowSize').value = document.documentElement.clientWidth;
}

function UpdateLayoutName(LayoutName, ArtistName){

}

function GetUpdatedPrice(ImageID, ArtistID, ImageType){

}

function SimpleRemoveFromLightbox(Section,ImageID,ImageName,ArtistID, ArtistName,Combinable,Customizable){

	if(Section =='collab'){
		url = "managelightbox.php?action=10&ImageID="+ImageID
	}else{
		url = "managelightbox.php?action=3&ImageID="+ImageID
	}
		
	url += "&ArtistID="+ArtistID
		new Ajax.Request(url, {
		asynchronous:true,
		method: 'get',
		onSuccess: function(transport){	
			$('FavoriteDisplayCount').value = parseInt($('FavoriteDisplayCount').value)-1;
			$('FavoriteCount').innerHTML ='('+$('FavoriteDisplayCount').value+')';
			$('FavoriteIcon').src='images/icons/favicon-big-grey.png';
			$('FavoriteBadge').setAttribute('onclick','SimpleAddToLightbox(\''+Section+'\','+ImageID+',\''+ImageName+'\','+ArtistID+', \''+ArtistName+'\','+Combinable+','+Customizable+')')
			$('FavoriteVerbText').innerHTML = 'Add to';
		}
	});
}

function SimpleAddToLightbox(Section,ImageID,ImageName,ArtistID, ArtistName,Combinable,Customizable){


	if(Section == 'stock'){
		//~ if(ImageExists == 0){
			/*NewImage = '<div id="ImageThumb'+ImageID+'" style="width:90px;display:inline-block;"><img src="images/skins/'+ImageID+'-2.jpg" onmouseover="javascript:ShowRemoveImage('+ImageID+',\'gs\','+ArtistID+');" onmouseout="javascript:HideRemoveImage();" style="height:75px; width:75px;" class="reflect rheight15"></div>';
			$('LightboxImages').innerHTML += NewImage ;
			ManageList(ImageID, 'CurrentImages','add');**/
			
			
			
			/** ADD TO SESSION ***/
			url = "managelightbox.php?action=1&ImageID="+ImageID;
			url += "&ImageName="+ImageName
			url += "&ArtistID="+ArtistID
			url += "&ArtistName="+ArtistName
			url += "&Combinable="+Combinable
			url += "&Customizable="+Customizable
			
			new Ajax.Request(url, {
				asynchronous:true,
				method: 'get',
				onSuccess: function(transport){	
					$('FavoriteIcon').src ='images/icons/favicon-big.png';
					$('FavoriteDisplayCount').value = parseInt($('FavoriteDisplayCount').value)+1;
					$('FavoriteCount').innerHTML ='('+$('FavoriteDisplayCount').value+')';
					$('FavoriteBadge').setAttribute('onclick','SimpleRemoveFromLightbox(\''+Section+'\','+ImageID+',\''+ImageName+'\','+ArtistID+', \''+ArtistName+'\','+Combinable+','+Customizable+')')
					$('FavoriteVerbText').innerHTML = 'Remove from';
				}
			});
			
			$('SessionArtSelected').value = 1 ;
			
			/*if(ImageCount==0){
				$('ContextNextButton').innerHTML = 'Welcome to your lightbox. <br> This is used to create custom skins. Confuised? <a href="help.php?s=custom">Click here</a>';
			}else{*/
				//$('ContextNextButton').innerHTML = '';
				//~ if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 0){
					//~ $('ContextNextButton').innerHTML = '<input type="button" value="Select Template" style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;" onclick="window.location=\'create.php\'">';
				//~ }else if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 1){
					//~ $('ContextNextButton').innerHTML = '<input type="button" value="Start Customizing" style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;"  onclick="window.location=\'skinner.php\'">';
				//~ }
			//}
		//~ }
	}else if (Section =='collab'){
		//~ if(CollabImageExists==0){
			/*NewImage = '<div id="CollabImageThumb'+ImageID+'" style="width:90px;display:inline-block;"><img src="images/collabs/'+ImageID+'-2.jpg" onmouseover="javascript:ShowRemoveImage('+ImageID+',\'collab\','+ArtistID+');" onmouseout="javascript:HideRemoveImage();" style="height:75px; width:75px;" class="reflect rheight15"></div>';
			$('LightboxImages').innerHTML += NewImage ;
			ManageList(ImageID, 'CurrentCollabImages','add');
			
			/** ADD TO SESSION ***/
			url = "managelightbox.php?action=9&ImageID="+ImageID;
			url += "&ImageName="+ImageName
			url += "&ArtistID="+ArtistID
			url += "&ArtistName="+ArtistName
			url += "&Combinable="+Combinable
			url += "&Customizable="+Customizable
	
			new Ajax.Request(url, {
				asynchronous:true,
				method: 'get',
				onSuccess: function(transport){	
					$('FavoriteIcon').src ='images/icons/favicon-big.png';
					$('FavoriteDisplayCount').value = parseInt($('FavoriteDisplayCount').value)+1;
					$('FavoriteCount').innerHTML ='('+$('FavoriteDisplayCount').value+')';
					//~ $('Browse'+ImageID).innerHTML = '<img src="images/imagedispatcher.php?id='+ImageID+'&size='+$('ColumnSize').value+'&dim=x&star=1" onmousedown="window.location=\'image.php?ImageID='+ImageID+'\'" onmouseover="ShowImageTabs('+ImageID+','+ArtistID+',\''+ImageName+'\',\''+ArtistName+'\',\'collab\','+Combinable+')" onmouseout="HideImageTabs('+ImageID+')">';
					$('FavoriteBadge').setAttribute('onclick','SimpleRemoveFromLightbox(\''+Section+'\','+ImageID+',\''+ImageName+'\','+ArtistID+', \''+ArtistName+'\','+Combinable+','+Customizable+')')
					$('FavoriteVerbText').innerHTML = 'Remove from';
					
				}
			});
			
			$('SessionArtSelected').value = 1 ;
			/*if(ImageCount==0){
				$('ContextNextButton').innerHTML = 'Welcome to your lightbox. <br> This is used to create custom skins. Confuised? <a href="help.php?s=custom">Click here</a>';
			}else{*/
				//$('ContextNextButton').innerHTML = '';
				//~ if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 0){
					//~ $('ContextNextButton').innerHTML = '<input type="button" value="Select Template" style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;" onclick="window.location=\'create.php\'">';
				//~ }else if($('SessionArtSelected').value == 1 && $('SessionTemplateSelected').value == 1){
					//~ $('ContextNextButton').innerHTML = '<input type="button" value="Start Customizing" style="color:white;border:0px; height:70px; margin-top:10px; -moz-border-radius:10px; background-color:darkblue;"  onclick="window.location=\'skinner.php\'">';
				//~ }
			//}
		//~ }
	

	}
}
