// Caldwell Snyder Gallery
// Written by Nic Hubbard - Zed Said Studio
// http://www.zedsaid.com
// nic@zedsaid.com


/**
* iScroll Wrapper
*
* @access public
*/
(function($){
    $.fn.iscroll = function(options){
		if(this.data('iScrollReady') == null){
			var that = this;
            var options =  $.extend({}, options);
				options.onScrollEnd = function(){
					that.triggerHandler('onScrollEnd', [this]);
				};
			arguments.callee.object  = new iScroll(this.get(0), options);
			// NOTE: for some reason in a complex page the plugin does not register
			// the size of the element. This will fix that in the meantime.
			setTimeout(function(scroller){
				scroller.refresh();
			}, 1000, arguments.callee.object);
			this.data('iScrollReady', true);
		}else{
			arguments.callee.object.refresh();
		}
		return arguments.callee.object;
	};
})(jQuery);


/**
* Take functions out of global scope
*
* @access public
*/
var cs = {};


/**
* jQuery method that fire when the dom is ready
*
* @access public
*/
$(function (){
	
	cs.init();
	
});//end


/**
* Make calls to all of our initial functions
*
* @access public
*/
cs.init = function() {
	
	cs.simpleEdit();
	cs.home();
	cs.artists();
	cs.exhibitions();
	cs.about();
		
}//end


/**
 * Checks if we are in dev mode
 *
 * @version $Revision: 0.1
 */
cs.dev = function(){
    var h = document.location.hash.replace('#', '');
    return (h && h == 'dev');
}//end


/**
 * Checks if this device is an iphone
 *
 * @version $Revision: 0.1
 */
cs.isIphone = function(){
    return (
        (navigator.platform.indexOf("iPhone") != -1) ||
        (navigator.platform.indexOf("iPod") != -1)
    );
}//end


/**
 * Checks if this device is an ipad
 *
 * @version $Revision: 0.1
 */
cs.isIpad = function(){
    return (navigator.platform.indexOf("iPad") != -1);
}//end


/**
 * Init simple edit
 *
 * @version $Revision: 0.1
 */
cs.simpleEdit = function(){
    
    // Check to see if we are in simple edit
    window.simple_edit = parseFloat($('#simple_edit_check').val());
    
    // Allow dragging and moving of Exhibitions to set their location
    	if ($('ul.simple_list').length > 0) {
    		$('ul.simple_list li').draggable({ axis: 'y' });
    		$('ul.simple_list').droppable({
    			activeClass: 'ui-state-hover',
    			drop: function(event, ui) {
    				$(this).html('Added');
    			}
    		});
    	}//end if
    
    	
    	// Deactivate Artist
    	$('#adminDeactivateArtist').click(function() {
    		var del = confirm('Are you sure you want to deactive this artist?\n\n Once you deactive, you must clear the cache for the artists menu.');
    		if (del) {
    			// Run our ajax to hit the trigger
    			$.ajax({
    				url: $('#current_url').val()+'?action=deactivate_artist',
    				type: 'POST',
    				success: function(html){
    					// Redirect back to the admin interface
    					alert('This artist has been deactivated.  Be sure to clear the cache');
    					document.location = 'http://www.caldwellsnyder.com/admin';
    				}//end success
    			});//end ajax	
    		}//end if
    	});//end click
    	
    	
    	// Re-sort select list of artists
    	var image_menu_arr = $('#artist_menu_image option');
    	var opts = jQuery.makeArray(image_menu_arr).
    		sort(function(a,b) {
    			return (a.innerHTML > b.innerHTML) ? 1 : -1;
    		});
    		$('#artist_menu_image').html(opts);
    	  
    	  
    	// Replace current user text
    	$('#logged_in_user').text($('#current_user').val());
    	
    	// Set size of curret preview image
    	$('#current_image').each(function() {
    	
    		var height = $(this).attr('height');
    		var width = $(this).attr('width');
    		
    		if (width > 200 || height > 200) {
    			$(this).attr('height', parseInt(height*.3));
    			$(this).attr('width', parseInt(width*.3));
    		}
    	
    	});	
    	
    	// ----- Don't Allw Double Clicking -----
    	$('#sq_commit_button').click(function() {
    		$(this).attr('disabled','disabled');								  
    	});
    	
    	
    	// ----- Remove Image Editor Button -----
    	$('#image_0_use_editor_button').remove();
    	
    	
    	// ----- Set the current date for metadata date fields -----
    	var current_full_date = new Date();
    	var current_year = current_full_date.getFullYear();
    	var current_day = current_full_date.getDate();
    	var current_month = current_full_date.getMonth();
    	var current_hour = current_full_date.getHours();
    	var current_min = current_full_date.getMinutes();
    	
    	// Check to see if we are in simple edit mode
    	if ($('#simple_edit_check').val() == 'FALSE') {
    	
    		// Set to the current day
    		$("select[id*='[d]']").children('option').each(function() { 
    			if ($(this).val() == current_day) { 
    				$(this).attr('selected', true); 
    			} 
    		});
    		// Set to the current month
    		$("select[id*='[m]']").children('option').each(function() { 
    			if ($(this).val() == current_month + 1) { 
    				$(this).attr('selected', true);
    			} 
    		});
    		// Set to the current hour
    		$("select[id*='[h]']").children('option').each(function() { 
    			if ($(this).val() == current_hour) { 
    				$(this).attr('selected', true);
    			} 
    		});
    		// Set to the current minute
    		$("select[id*='[i]']").children('option').each(function() { 
    			if ($(this).val() == current_min) { 
    				$(this).attr('selected', true);
    			} 
    		});
    		// Set to the current year
    		$("input[id*='[y]']").val(current_year);
    		
    	}//end if
    	
    	
    	// ----- Editing Mode: Set current artist dropdown -----
    	var artist_name = $("input[id*='folder'][type='text']").val();
    	$('#artist_edit').children('option').each(function() { 
            if ($(this).text() == artist_name) { 
    			$(this).attr('selected', true);
            } 
    	});
    	
    	
    	// ----- Editing Mode: Dynamically load artist artwork listing -----
    	$('#artwork_edit_front').change(function() {
    		var current = $(this).children('option:selected').val();
    		$.ajax({
    		  url: current,
    		  cache: false,
    		  beforeSend: function() {
    			  $('#artworkEditLoad').show();
    		  },
    		  success: function(html){
    			$('#artwork_edit_artist').html(html);
    			$('#artworkEditLoad').hide();
    		  }
    		});		
    	});//end change
    	
    	
    	// ----- Delete Mode: Dynamically load artist artwork listing -----
    	$('#artwork_delete_front').change(function() {
    		var current = $(this).children('option:selected').val();
    		$.ajax({
    		  url: current,
    		  cache: false,
    		  beforeSend: function() {
    			  $('#artworkEditLoad').show();
    		  },
    		  success: function(html){
    			$('#artwork_edit_artist').html(html);
    			$('#artworkEditLoad').hide();
    		  }
    		});		
    	});//end change
    	
    	
    	// ----- Clear Cache -----
    	$('#clear_cache').change(function() {
    		var current = $(this).children('option:selected').val();
    		$.ajax({
    		  url: current,
    		  cache: false,
    		  beforeSend: function() {
    			  $('#artworkEditLoad').show();
    		  },
    		  success: function(html){
    			$('#clear_cache_target').html(html);
    			$('#artworkEditLoad').hide();
    		  }
    		});		
    	});//end change
    	
    	$('.matrixCache').live('click', function(){
    		var current = $(this).attr('href');
    		var obj = $(this);
    		$.ajax({
    		  url: current,
    		  type: 'GET',
    		  cache: false,
    		  beforeSend: function() {
    			  obj.parent().append('<img src="/__data/assets/image/0018/2277/ajax-loader.gif" class="cache_load" />');
    		  },
    		  success: function(html){
    			  obj.parent().children('.cache_load').remove();
    		  }
    		});		
    		
    		return false;
    		
    	});// End live click
    	
    	
    	$('.add_aquisition').live('click', function(){
    		var current = $(this).attr('href');
    		var obj = $(this);
    		$.ajax({
    			url: current + '&action=add_acquisition',
    			type: 'POST',
    			cache: false,
    			beforeSend: function() {
    				obj.parent().append('<img src="/__data/assets/image/0018/2277/ajax-loader.gif" class="aquisition_load" />');
    			},
    			success: function(html){
    				obj.parent().children('.aquisition_load').remove();
    			}
    		});		
    		
    		return false;
    		
    	});// End live click
    
    
    	// ----- New Acquisitions: Dynamically load artist artwork listing -----
    	$('#artwork_acquisition').change(function() {
    		var current = $(this).children('option:selected').val();
    		$.ajax({
    		  url: current,
    		  cache: false,
    		  beforeSend: function() {
    			  $('#artworkEditLoad').show();
    		  },
    		  success: function(html){
    			$('#artwork_edit_artist').html(html);
    			$('#artworkEditLoad').hide();
    		  }
    		});// End Ajax
    		
    		// Add click to links
    		$('.matrixAdd').click(function () {
    			
    			// Grab our attributes
    			var item_name = $(this).attr('rel');
    			var item_href = $(this).attr('href');
    			
    			// Confirm they want to add
    			var add_item = confirm('Are you sure you want to add " + item_name + " to New Acquisitions?');
    			if (add_item) {
    				$.ajax({
    					url: item_href,
    					success: function(html){
    						$(this).parent().append('Added!');
    					}
    				});// End Ajax
    
    			}// End if
    			
    			return false;
    			
    		});
    		
    	});//end change
    
}//end


/**
 * Init homepage
 *
 * @version $Revision: 0.1
 */
cs.home = function(){

	// ----- Homepage Slideshow -----
	if ($('#home_exhibition_hold').length) {
		$('#home_exhibition_hold').cycle({ 
			fx:      'none', 
			speed:    2000, 
			timeout:  7000,
			pause: 	0,
			pager:   '#slide_pager'
		});	
	}
	if ($('.home_slides').length < 2) {
		$('#slide_pager').hide();
	}
	
	// ----- Remove Text in Pager -----
	$('#slide_pager a').each(function() {
		$(this).text('');							  
	});
	// Add our preview images to the pager
	var i = 0;
	$('#slide_pager a').each(function() {
		$(this).append('<img src="' + pager_arr[i] + '" alt="Exhibition Pager Image" />');
		i++;
	});
	
	// Remove reception is start/end is the same
	$('.artistReception').each(function() {
		if ($(this).text() === '12:00 - 12:00 AM' || $(this).text() === '12 - 12 AM') {
			$(this).parent('.receptionParent').hide();
		}
	});
	
	
	// Remove reception is start/end is the same
	$('span.artworkMedium').each(function() {
		$(this).text($(this).text().replace(/12:00 - 12:00 AM/gi, ""));
	});
	
	
	// Special fix
	$('span.artworkId').each(function() {
		$(this).text($(this).text().replace(/11 - 11/gi, "11"));
	});

}//end


/**
 * Init Artists
 *
 * @version $Revision: 0.1
 */
cs.artists = function() {

	// If not an artist, remove dimensions
		if ($('#artistCycleParent').length > 0) {
			$('span.artworkSizeIn').each(function () {
				if ($(this).text() === ' in') {
					$(this).text('');
				}
			});
			$('span.artworkSizeCm').each(function () {
				if ($(this).text() === ' cm') {
					$(this).text('');
				}
			});
		}//end if
		
		
		// ----- Artists Menu: Load Up Artists Menu Dynamically
		if (simple_edit === 1) {
			$('a#Artists').hover(function() {
				cs.menu_disabled();
			});
		} else {
			var artist_menu_url;
			// Check to see what Gallery we are using!
			if (asset.site == '6965') {
				artist_menu_url = $('#artistsMenuLinkCampton').attr('href');
			} else {
				artist_menu_url = $('#artistsMenuLink').attr('href');
			}
	
			$.ajax({
			  url: artist_menu_url,
			  cache: true,
			  success: function(html){
					$('#artistsBoxHold').html(html);
					
					cs.load_artist_menu();
				
				}// End Success
			  
			});// End ajax	
			
		}// End else
		
		// Load artists menu thumbnail view
		$('#artistsBoxHeader a').live('click', function() {
			var obj = $(this);
			if (obj.hasClass('selected')) {
				return false;
			} else {
				$('#artistsBoxHeader a').removeClass('selected');
				obj.addClass('selected');
			}
			
			$.ajax({
				url: obj.attr('href'),
				cache: true,
				beforeSend: function () {
					$('<div id="artist_menu_over"><img src="/__data/assets/image/0018/2277/ajax-loader.gif" alt="Load" /></div>').appendTo('#artistsBoxLoad');
				},
				success: function(html){
					// Add our content
					$('#artistsBoxLoad').html(html);
					if (obj.text() == 'Artist List') {
						cs.load_artist_menu();
					}
	
					// Hide our loader
					$('#artist_menu_over').remove();
					
					// ----- Exhibition exhibitionsBoxInner Bars -----
					$ebi = $('#artistsThumbs');
					
					// Check if we are using iOS
					if (cs.isIpad() || cs.isIphone()) {
						// Implement iscroll
						$ebi.iscroll({ scrollbarClass: 'iScrollBar'});
					} else {
						$ebi.jScrollPane({
							showArrows:false,
							scrollbarWidth: 6
						});
					}//end
					
				}//end
			
			});//end ajax
			
			return false;
		});
		
		// Change on mouse over
		$('#artistsThumbs a').live('mouseover', function(){
			// Set artist name
			$('#artistsBoxHeader span').text($(this).attr('title'));
		});
		
		
		// ----- Artists Menu: Prevent the user from visiting the real page
		$('a#Artists, a#Exhibitions').click(function() {
			return false;			  
		});//end click
		
		
		// ----- Artists: Check to see if artwork is sold -----
		$('.artworkSold').each(function() {
			if ($(this).attr('alt') == 'Yes') {
				$(this).show();	
			}
		});
		
		
		// ----- Artists Artwork: Preload Slideshow
		$('#artistCycleParent img').preload();
		
		
		// ----- Artists: Don't let our browser have nothing to click -----
		if ($('#artworkNext').attr('href') === '') {
			$('#artworkNext').attr('href', '#');
		} else if ($('#artworkPrev').attr('href') === '') {
			$('#artworkPrev').attr('href', '#');
		}
		
		// Pause slide if we click image
		$('img.currentArtworkImage').click(function() {
			if ($(this).hasClass('paused')) {
				$('#artistCycleParent').cycle('resume');
				$(this).removeClass('paused');
				$('#pauseButton').show();
				$('#resumeButton').hide();
			} else {
				$('#artistCycleParent').cycle('pause');
				$(this).addClass('paused');
				
				$('#pauseButton').hide();
				$('#resumeButton').show();
			}//end
		
		});
		
		
		// ----- Artists Artwork: Inquiry Form -----
		$('.inquiry_link').click(function(){
			var inquiry_id = $(this).attr('rel');
			var current_artist = $('.artistInfoHead h3:first').text();
			
			// Set the inquiry value
			$('#q3713_q3').val(current_artist + ' - ' + inquiry_id);
			$('#artwork_id').text(current_artist + ' - ' + inquiry_id);
			
			// Pause our slideshow
			$('#artistCycleParent').cycle('pause');
			$('#pauseButton').hide();
			$('#resumeButton').show();
			
			// Show our hidden Form
			$('#nested_artwork_inquiry').fadeIn('fast');
			// Show our invisible div
			var blanket = $('#site_blanket');
			blanket.show();
			blanket.click(function(){
				$('#nested_artwork_inquiry').fadeOut('fast');			   
				$(this).hide();	
				
				// Resume slideshow
				$('#artistCycleParent').cycle('resume');
				$('#pauseButton').show();
				$('#resumeButton').hide();
				
			});
			
			return false;
			
		});//end click

}//end


/**
 * Init Exhibitions
 *
 * @version $Revision: 0.1
 */
cs.exhibitions = function() {

	// ----- Exhibitions Menu: Load Up Exhibitions Menu Dynamically
	if (simple_edit === 1) {
		$('a#Exhibitions').hover(function() {
			cs.menu_disabled();
		});
	} else {
		var exhibit_menu_url;
		// Check to see what Gallery we are using!
		if (asset.site == '6965') {
			exhibit_menu_url = $('#exhibitMenuLinkCampton').attr('href');
		} else {
			exhibit_menu_url = $('#exhibitMenuLink').attr('href');
		}
		$.ajax({
		  url: exhibit_menu_url,
		  cache: true,
		  success: function(html){
			$('#exhibitionsBoxHold').html(html);
			// Fix some special instances
			$('span.artworkMedium').each(function() {
				$(this).text($(this).text().replace(/Dec 11 - Dec 11/gi, "Dec 11"));
			});
			// ----- Show Exhibitions Menu When Link moused over ------
			var onMenu = false;
			var onImg = false;
			$('a#Exhibitions').hover(
				 function() {
				// Show Our Artists Box
				var onImg = true;
				$('#exhibitionsBox').fadeIn('fast');
				 },
				 function() {
				// Show Our Artists Box
				var onImg = false;
					setTimeout(function() {
						if (!onMenu) $('#exhibitionsBox').fadeOut('fast');
					},
					100);
				});
				$('#exhibitionsBox').hover(
				function() {
					onMenu = true;
				},
				function() {
					onMenu = false;
					setTimeout(function() {
						if (!onImg) $('#exhibitionsBox').fadeOut('fast');
					},
					100);
				});
				
			// ----- Remove Receptions -----
			// Check to see if we should remove the receptions
			$('span.time_check').each(function () {
				if ($(this).text() === '12:00 - 12:00 AM' || $(this).text() === '12 - 12 AM') {
					$(this).parent('p.reception').hide();
				}
			});
			
			// -- Add our schollers
			$eb = $('#exhibitionsBoxInner').parent().parent();
			$eb.show();
			
			// Check if we are using iOS
			if (cs.isIpad() || cs.isIphone()) {
				// Implement iscroll
				$('#exhibitionsBoxInner').children().wrapAll('<div id="iscroll-current" />');
				$('#exhibitionsBoxInner').iscroll({ scrollbarClass: 'iScrollBar'});
			} else {
				$('#exhibitionsBoxInner').jScrollPane({
					showArrows:false,
					scrollbarWidth: 6
				});
			}//end
			
			$eb.hide();
				
		  }// End Success
		  
		});// End ajax
		
		// Load up our other menu options
		$('#exhibit_future, #exhibit_archive').live('click', function() {
			// Current object
			var obj = $(this);
			// Set our var for already visited
			var visited = true;
			
			var future_url = $(this).attr('href');
			$('#exhibition_options a').removeClass('current');
			$(this).addClass('current');
			
			if (!$(this).hasClass('visited')) {
				$(this).addClass('visited');
				$.ajax({
				  url: future_url,
				  cache: true,
				  beforeSend: function () {
					$('<img id="load_img" src="/__data/assets/image/0018/2277/ajax-loader.gif" alt="Load" /><div id="menu_over"></div>').appendTo('#exhibitionsBox');
				  },
				  success: function(html){
					  // Remove our loading stuff
					  $('#menu_over, #load_img').remove();
					  
					  // Hide the current content
					  if (cs.isIpad() || cs.isIphone()) { 
					  	$('#exhibitionsBoxInner').hide();
					  } else {
					  	$('#exhibitionsBoxInner').parent().hide();
					  }
					
					// Show our new stuff
					if (obj.attr('id') === 'exhibit_archive') {
					  $('#exhibit_holder_arc').html(html).show();
					  
					  // Hide the current content
					  if (cs.isIpad() || cs.isIphone()) { 
					  	 $('#exhibit_holder').hide();
					  } else {
					  	 $('#exhibit_holder').parent('.jScrollPaneContainer').hide();
					  }//end
					 
					  
						// ----- Remove Receptions -----
						// Check to see if we should remove the receptions
						$('span.time_check').each(function () {
							if ($(this).text() === '12:00 - 12:00 AM' || $(this).text() === '12 - 12 AM') {
								$(this).parent('p.reception').hide();
							}
						});
						
						// ----- Exhibition Scroll Bars -----
						$ebi = $('#exhibit_holder_arc');
						
						// Check if we are using iOS
						if (cs.isIpad() || cs.isIphone()) {
							// Implement iscroll
							$ebi.children().wrapAll('<div id="iscroll-archives" />');
							$ebi.iscroll({ scrollbarClass: 'iScrollBar'});
						} else {
							$ebi.jScrollPane({
								showArrows:false,
								scrollbarWidth: 6
							});
						}//end
						
					} else {
					  // Future Exhibitions
					  $('#exhibit_holder').html(html).show();
					  
					  if (cs.isIpad() || cs.isIphone()) { 
					  	$('#exhibit_holder_arc').hide();
					  } else {
					  	$('#exhibit_holder_arc').parent('.jScrollPaneContainer').hide();
					  }
					  
						// ----- Remove Receptions -----
						// Check to see if we should remove the receptions
						$('span.time_check').each(function () {
							if ($(this).text() === '12:00 - 12:00 AM' || $(this).text() === '12 - 12 AM') {
								$(this).parent('p.reception').hide();
							}
						});
						
						// ----- Exhibition Scroll Bars -----
						$ebi = $('#exhibit_holder');
						
						// Check if we are using iOS
						if (cs.isIpad() || cs.isIphone()) {
							// Implement iscroll
							$ebi.children().wrapAll('<div id="iscroll-future" />');
							$ebi.iscroll({ scrollbarClass: 'iScrollBar'});
						} else {
							$ebi.jScrollPane({
								showArrows:false,
								scrollbarWidth: 6
							});
						}//end
						
					}
					  
				  }// End success
				  
			   });// End ajax
			
			} else {
			  // Show our new stuff
			  if (obj.attr('id') === 'exhibit_archive') {
				  
				  if (cs.isIpad() || cs.isIphone()) {
				  	$('#exhibitionsBoxInner').hide();
				  	$('#exhibit_holder').hide();
				  	$('#exhibit_holder_arc').show();
				  } else {
				  	$('#exhibitionsBoxInner').parent('.jScrollPaneContainer').hide();
				  	$('#exhibit_holder').parent('.jScrollPaneContainer').hide();
				  	$('#exhibit_holder_arc').parent('.jScrollPaneContainer').show();
				  }//end
				  
			  } else {
				
				  if (cs.isIpad() || cs.isIphone()) {
				  	$('#exhibitionsBoxInner').hide();
				  	$('#exhibit_holder_arc').hide();
				  	$('#exhibit_holder').show();
				  } else {
				  	$('#exhibitionsBoxInner').parent('.jScrollPaneContainer').hide();
				  	$('#exhibit_holder_arc').parent('.jScrollPaneContainer').hide();
				  	$('#exhibit_holder').parent('.jScrollPaneContainer').show();
				  }//end
				  
			  }
			  
			}
			
			return false;
											
		});// End click
		
		// Show our current exhibitions
		$('#exhibit_current').live('click', function() {
			$('#exhibition_options a').removeClass('current');
			$(this).addClass('current');
			
			if (cs.isIpad() || cs.isIphone()) {
				$('#exhibit_holder_arc').hide();	
				$('#exhibit_holder').hide();
				$('#exhibitionsBoxInner').show();
			} else {
				$('#exhibit_holder_arc').parent('.jScrollPaneContainer').hide();	
				$('#exhibit_holder').parent('.jScrollPaneContainer').hide();
				$('#exhibitionsBoxInner').parent('.jScrollPaneContainer').show();
			}//end
			
			return false;
			
		});// End click
		
	}// End else

}//end


/**
 * Init About
 *
 * @version $Revision: 0.1
 */
cs.about = function() {

	// Add our scrollpane
	$('#body_text_about, #fair_scroll').jScrollPane({
		showArrows:false,
		scrollbarWidth: 6
	});
	
	// Cycle about images
	$('#aboutImageList').cycle({ 
		fx:      'fade', 
		speed:    2000, 
		timeout:  6000,
		pause: 	0
	});

}//end


/**
 * Disable the menu
 *
 * @version $Revision: 0.1
 */
cs.menu_disabled = function() {
	
	if ($('#disabled').length === 1) {
		// Do nothing
	} else {
		$('<div id="disabled">Menu is disabled in Editing Mode</div>').prependTo('#headerHolderSub');
		
		setTimeout(function() {
			$('#disabled').remove();
				},
		5000);
	}
	
}//end


/**
 * Load the artists menu
 *
 * @version $Revision: 0.1
 */
cs.load_artist_menu = function() {
	
	// ----- Artists Menu: Create Columns -----
	var total_artists = $('#artistsColumns p').length;
	var total_artists_mod = total_artists % 3;
	var total_artists_col = total_artists / 3;
	$('#artistsColumns p').slice(0 , total_artists_col).addClass('first');
	$('#artistsColumns p').slice(total_artists_col , total_artists_col * 2).addClass('second');
	$('#artistsColumns p').slice(total_artists_col * 2 , (total_artists_col * 3) + total_artists_mod).addClass('third');
	
	// Now lets wrap those in some divs
	$('p.first').wrapAll('<div class="colFirst"></div>');
	$('p.second').wrapAll('<div class="colSecond"></div>');
	$('p.third').wrapAll('<div class="colThird"></div>');
	
	// ----- Show Artists Menu When Link moused over ------
	var onMenu = false;
	var onImg = false;
	$('a#Artists').hover(
		 function() {
		// Show Our Artists Box
		var onImg = true;
		$('#artistsBox').fadeIn('fast');
		 },
		 function() {
		// Show Our Artists Box
		var onImg = false;
			setTimeout(function() {
				if (!onMenu) $('#artistsBox').fadeOut('fast');
			},
			50);
		});
		$('#artistsBox, #artistsThumbs a, #artistsThumbs img').hover(function() {
			onMenu = true;
		},
		function() {
			onMenu = false;
			setTimeout(function() {
				if (!onImg) $('#artistsBox').fadeOut('fast');
			},
			50);
	});// End Hover
		
	// ----- Artists Menu: Show Artist Preview Image -----
	var $links = []; 
	$.each($('#artistsColumns a'), function() { 
		$links.push($(this).attr('rel')); 
	}); 
	var $preview = $('#artist_menu_artwork');
	
	$.preload($links, 
		{ 
			threshold: 2
		} 
	);
	
	// Set first preview image and text
	$('#artist_menu_artwork').attr('src', $('#artistsColumns a:first').attr('rel'));
	$('#artistsBoxHeader span').text($('#artistsColumns a:first').text());
	
	// Change on mouse over
	$('#artistsColumns a').mouseover(function(){
		$preview.attr('src', $(this).attr('rel'));
		// Set artist name
		$('#artistsBoxHeader span').text($(this).text());
		
	});
	
}//end

