/*
Tasveer Core JavaScript
By: Junaid Bhura
www.junaidbhura.com
*/

var $_GET = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
    function decode(s) { return decodeURIComponent(s.split("+").join(" ")); }
    $_GET[decode(arguments[1])] = decode(arguments[2]);
});
var totalImages = 0;
var currentImage = 0;
var imageRotatorDelay = 4000;
var sliderWidth = 0;
var imageData;


$(document).ready(function(){
	// Simple Search
	if($('#simple-search-box').attr('value') == '')
		$('#simple-search-box').attr('value', 'search');
	$('#simple-search-box').focus(function(){
		if($('#simple-search-box').attr('value') == 'search')
			$('#simple-search-box').attr('value', '');
	});
	$('#simple-search-box').blur(function(){
		if($('#simple-search-box').attr('value') == '')
			$('#simple-search-box').attr('value', 'search');
	});
	
	$('#back-link').click(function(){
		history.go(-1);
		return false;
	});
	
	// Home page slider
	if($('#home-slider').length != 0) {
		$('#home-slider').nivoSlider({
			effect:'fade',
			controlNav:false,
			animSpeed:500,
			pauseTime:5000,
			directionNav:false
		});
	}
	
	// Photographers image hover
	$('.photo-hover').mouseover(function(){
		var list = $(this).attr('class').split(/\s+/);
		$('.' + list[1]).addClass('active');
	});
	$('.photo-hover').mouseout(function(){
		var list = $(this).attr('class').split(/\s+/);
		$('.' + list[1]).removeClass('active');
	});
	
	// Image rotator
	/*if($('.image-rotator').length != 0) {
		totalImages = $(this).find('.total-images').attr('value');
		rotateImages();
		setInterval('rotateImages()', imageRotatorDelay);
	}*/
	
	// Filter dropdowns
	$('.select-filter').change(function(){
		switch($(this).attr('id')) {
			case 'series-filter':
				var pos = location.href.indexOf('?');
				var href;
				
				if(pos != -1)
					href = location.href.substr(0, pos) + ($(this).val() != 'All'? '?s=' + $(this).val(): '');
				else
					href = location.href + ($(this).val() != 'All'? '?s=' + $(this).val(): '');
				
				location.href = href;
				break;
			case 'view-indi-photographer-filter':
				location.href = $(this).find('option:selected').attr('rel');
				break;
			case 'view-all-photographer-filter':
				location.href = $(this).find('option:selected').attr('rel');
				break;
			case 'view-indi-series-filter':
				if($(this).attr('value') != '' && $(this).attr('value') != undefined)
					location.href = $(this).find('option:selected').attr('rel') + '?s=' + $(this).attr('value');
				else
					location.href = $(this).find('option:selected').attr('rel');
				break;
			case 'exhibition-city-filter':
				// Get URL
				var query = location.href.substring(0, location.href.lastIndexOf('?'));
				
				// Create query string
				var queryString = '?' + ($(this).attr('value') != ''? '_city=' + $(this).attr('value') + '&': '') + ($_GET['_season'] != undefined? '_season=' + $_GET['_season'] + '&': '') + ($_GET['_photographer'] != undefined? '_photographer=' + $_GET['_photographer']: '');
				if(queryString.charAt(queryString.length - 1) == '&')
					queryString = queryString.substring(0, queryString.length - 1);
				if(queryString == '?')
					queryString = '';
				
				// Redirect
				location.href = query + queryString;
				break;
			case 'exhibition-season-filter':
				// Get URL
				var query = location.href.substring(0, location.href.lastIndexOf('?'));
				
				// Create query string
				var queryString = '?' + ($_GET['_city'] != undefined? '_city=' + $_GET['_city'] + '&': '') + ($(this).attr('value') != ''? '_season=' + $(this).attr('value') + '&': '') + ($_GET['_photographer'] != undefined? '_photographer=' + $_GET['_photographer']: '');
				if(queryString.charAt(queryString.length - 1) == '&')
					queryString = queryString.substring(0, queryString.length - 1);
				if(queryString == '?')
					queryString = '';
				
				// Redirect
				location.href = query + queryString;
				break;
			case 'exhibition-photographer-filter':
				// Get URL
				var query = location.href.substring(0, location.href.lastIndexOf('?'));
				
				// Create query string
				var queryString = '?' + ($_GET['_city'] != undefined? '_city=' + $_GET['_city'] + '&': '') + ($_GET['_season'] != undefined? '_season=' + $_GET['_season'] + '&': '') + ($(this).attr('value') != ''? '_photographer=' + $(this).attr('value'): '');
				if(queryString.charAt(queryString.length - 1) == '&')
					queryString = queryString.substring(0, queryString.length - 1);
				if(queryString == '?')
					queryString = '';
				
				// Redirect
				location.href = query + queryString;
				break;
			case 'publication-photographer-filter':
				// Get URL
				var query = location.href.substring(0, location.href.lastIndexOf('?'));
				
				// Create query string
				var queryString = '?' + ($_GET['_season'] != undefined? '_season=' + $_GET['_season'] + '&': '') + ($(this).attr('value') != ''? '_photographer=' + $(this).attr('value'): '');
				if(queryString.charAt(queryString.length - 1) == '&')
					queryString = queryString.substring(0, queryString.length - 1);
				if(queryString == '?')
					queryString = '';
				
				// Redirect
				location.href = query + queryString;
				break;
			case 'publication-season-filter':
				// Get URL
				var query = location.href.substring(0, location.href.lastIndexOf('?'));
				
				// Create query string
				var queryString = '?' + ($(this).attr('value') != ''? '_season=' + $(this).attr('value') + '&': '') + ($_GET['_photographer'] != undefined? '_photographer=' + $_GET['_photographer']: '');
				if(queryString.charAt(queryString.length - 1) == '&')
					queryString = queryString.substring(0, queryString.length - 1);
				if(queryString == '?')
					queryString = '';
				
				// Redirect
				location.href = query + queryString;
				break;
			case 'press-photographer-filter':
				// Get URL
				var query = location.href.substring(0, location.href.lastIndexOf('?'));
				
				// Create query string
				var queryString = '?' + ($_GET['_season'] != undefined? '_season=' + $_GET['_season'] + '&': '') + ($(this).attr('value') != ''? '_photographer=' + $(this).attr('value'): '');
				if(queryString.charAt(queryString.length - 1) == '&')
					queryString = queryString.substring(0, queryString.length - 1);
				if(queryString == '?')
					queryString = '';
				
				// Redirect
				location.href = query + queryString;
				break;
			case 'press-season-filter':
				// Get URL
				var query = location.href.substring(0, location.href.lastIndexOf('?'));
				
				// Create query string
				var queryString = '?' + ($(this).attr('value') != ''? '_season=' + $(this).attr('value') + '&': '') + ($_GET['_photographer'] != undefined? '_photographer=' + $_GET['_photographer']: '');
				if(queryString.charAt(queryString.length - 1) == '&')
					queryString = queryString.substring(0, queryString.length - 1);
				if(queryString == '?')
					queryString = '';
				
				// Redirect
				location.href = query + queryString;
				break;
			case 'lightbox-filter':
				// Get URL
				var query = location.href.substring(0, location.href.lastIndexOf('?'));
				
				// Create query string
				var queryString = '?' + ($(this).attr('value') != ''? '_lightbox=' + $(this).attr('value'): '');
				if(queryString.charAt(queryString.length - 1) == '&')
					queryString = queryString.substring(0, queryString.length - 1);
				if(queryString == '?')
					queryString = '';
				
				// Redirect
				location.href = query + queryString;
				break;
		}
	});
	
	// Exhibition hover
	$('.exhibition-list img').mouseover(function() {
		$(this).parent().parent().parent().find('span').addClass('active');
	});
	$('.exhibition-list img').mouseout(function() {
		$('.exhibition-list span').removeClass('active');
	});
	
	// Glossary accordion
	$('.glossary-link').click(function(){
		var id = $(this).attr('id').replace('glossary-link-', '');
		$('.glossary-description').slideUp('fast');
		$('#glossary-description-' + id).slideDown('slow');
		
		return false;
	});
	
	// Publication slider
	if($("#publication-image-container").length != 0) {
		$("#publication-image-container").easySlider({
			auto: false, 
			continuous: true,
			controlsShow: true,
			pause: 5000,
			nextText: 'Next >',
			prevText: '< Previous'
		});
	}
	
	// Lightbox sort
	if($('.lightboxes').length != 0) {
		$('ol.lightboxes').nestedSortable({
			disableNesting: 'no-nest',
			forcePlaceholderSize: true,
			handle: '.handle',
			items: 'li',
			opacity: .6,
			placeholder: 'placeholder',
			tabSize: 0,
			tolerance: 'pointer',
			toleranceElement: '> div',
			update: function() {
				var arraied = $('ol.lightboxes').nestedSortable('toArray', {startDepthCount: 0});
				var parent;
				var grandparent;
				var orderString;
				
				// Find grandpappy and make it it's direct parent
				for(i=1; i < arraied.length; i++) {
					if(arraied[i].depth > 2) {
						parent = arraied[i].parent_id;
						continueFlag = true;
						
						while(continueFlag) {
							for(j=0; j < arraied.length; j++) {
								if(arraied[j].item_id == parent) {
									grandparent = arraied[j].parent_id;
									
									if(grandparent == 'root') {
										continueFlag = false;
									}
										
									break;
								}
							}
							
							if(continueFlag)
								parent = grandparent;
						}
						arraied[i].parent_id = parent;
						arraied[i].depth = 2;
					}
				}
				
				// Create order string for AJAX
				orderString = '';
				for(i=1; i < arraied.length; i++) {
					orderString += $('#lightbox-' + arraied[i].item_id).attr('class').replace('lightbox-','') + ':' + (arraied[i].parent_id != 'root'? $('#lightbox-' + arraied[i].parent_id).attr('class').replace('lightbox-',''): 0) + ':' + arraied[i].left + ',';
				}
				
				// Block UI
				$.blockUI({ css: { backgroundColor: '#fff', color: '#000', border: '2px solid #ccc'}, message: "<p><strong>... Updating Lightboxes ...</strong></p>", overlayCSS: { backgroundColor: '#ccc', opacity: 0.2 } });
				
				// Send AJAX request to save lightboxes
				$.ajax({
				  url: template_url + "ajax/update_lightboxes.php",
				  cache: false,
				  type: "POST",
				  data: "order=" + orderString,
				  success: function(html) {
					$.unblockUI();
				  },
				  error: function() {
					  $.unblockUI();
				  }
				});
			}
		});
	}

	// Send lightbox to Tasveer
	$('.send-lightbox').click(function(){
		var newLightboxForm = '<div class="lightbox-form" style="padding-top:20px; padding-bottom:20px;">\
		<table border="0" cellpadding="0" cellspacing="0">\
		<tr>\
		<td width="100" style="padding-bottom:10px;" valign="top">Your Comments</td>\
		<td style="padding-bottom:10px;"><textarea id="lightbox-message" style="width:250px; height:80px;"></textarea></td>\
		</tr>\
		<tr>\
		<td>&nbsp;</td>\
		<td><input type="button" id="send-lightbox-button" value="Send Lightbox to Tasveer" /></td>\
		</tr>\
		</table></div>';
		$.facebox(newLightboxForm);
		
		var id = $(this).parent().parent().parent().attr('class').replace('lightbox-', '');
		
		$('#send-lightbox-button').click(function(){
			var message = $('#lightbox-message').attr('value');
			
			if(message != '') {
				$.facebox(function(){
					$.ajax({
					  url: template_url + "ajax/send_lightbox.php",
					  cache: false,
					  type: "POST",
					  data: "message=" + message + "&id=" + id,
					  success: function(data) {
						if(data == 'SUCCESS') {
							$.facebox.close();
							alert('Thank you for sending us your Lightbox.\nWe will review it and get back to you as soon as possible.');
						}
						else if(data == 'LOGIN') {
							alert('You must be logged in to use this function.');
							$.facebox.close();
						}
						else if(data == 'EMAIL') {
							$.facebox.close();
							alert('Thank you for sending us your Lightbox.\nHowever, there was a problem notifying the administrator.\nIt might take some time before we get back to you.');
						}
						else {
							alert('There was a problem sending the lightbox. Please try after some time.');
							$('.send-lightbox').click();
						}
					  },
					  error: function() {
						  alert('There was a problem with this action. Please try after some time.');
					  }
					});
				});
			}
			else {
				alert('Please enter a message to help us review this Lightbox.');
				$('#lightbox-message').focus();
			}
		});
		
		$('#lightbox-message').focus();
		
		return false;
	});
	
	// Add new lightbox
	$('.add-new-lightbox').click(function(){
		var newLightboxForm = '<div class="lightbox-form" style="padding-top:20px; padding-bottom:20px;">\
		<table border="0" cellpadding="0" cellspacing="0">\
		<tr>\
		<td width="100" style="padding-bottom:10px;">Lightbox Name</td>\
		<td style="padding-bottom:10px;"><input id="lightbox-name" value="" style="width:270px;" /></td>\
		</tr>\
		<tr>\
		<td>&nbsp;</td>\
		<td><input type="button" id="save-lightbox-button" value="Save" /></td>\
		</tr>\
		</table></div>';
		$.facebox(newLightboxForm);
		
		$('#save-lightbox-button').click(function(){
			var name = $('#lightbox-name').attr('value');
			
			if(name != '') {
				$.facebox(function(){
					$.ajax({
					  url: template_url + "ajax/new_lightbox.php",
					  cache: false,
					  type: "POST",
					  data: "name=" + name,
					  success: function(data) {
						if(data == 'SUCCESS') {
							$.facebox.close();
							location.reload(true);
						}
						else if(data == 'LOGIN') {
							alert('You must be logged in to use this function.');
							$.facebox.close();
						}
						else {
							alert('There was a problem saving the lightbox. Please try after some time.');
							$('.add-new-lightbox').click();
						}
					  },
					  error: function() {
						  alert('There was a problem with this action. Please try after some time.');
					  }
					});
				});
			}
			else {
				alert('Please enter a name for your Lightbox');
				$('#lightbox-name').focus();
			}
		});
		
		return false;
	});
	
	// Rename lightbox
	$('.rename-lightbox').click(function(){
		var newLightboxForm = '<div class="lightbox-form" style="padding-top:20px; padding-bottom:20px;">\
		<table border="0" cellpadding="0" cellspacing="0">\
		<tr>\
		<td width="100" style="padding-bottom:10px;">Lightbox Name</td>\
		<td style="padding-bottom:10px;"><input id="lightbox-name" value="" style="width:270px;" /></td>\
		</tr>\
		<tr>\
		<td>&nbsp;</td>\
		<td><input type="button" id="save-lightbox-button" value="Update" /></td>\
		</tr>\
		</table></div>';
		
		$.facebox(newLightboxForm);
		
		var id = $(this).parent().parent().parent().attr('id');
		var value;
		var i = 0;
		$('#' + id + ' .lightbox-title').each(function(){
			if(i == 0)
				value = $(this).text();
			i++;
		});
		
		$('#lightbox-name').attr('value', value);
		$('#lightbox-name').focus();
		
		$('#save-lightbox-button').click(function(){
			var name = $('#lightbox-name').attr('value');
			
			if(name != '') {
				$.facebox(function(){
					$.ajax({
					  url: template_url + "ajax/update_lightbox.php",
					  cache: false,
					  type: "POST",
					  data: "name=" + name + "&id=" + $('#' + id).attr('class').replace('lightbox-', ''),
					  success: function(data) {
						if(data == 'SUCCESS') {
							$.facebox.close();
							location.reload(true);
						}
						else if(data == 'LOGIN') {
							alert('You must be logged in to use this function.');
							$.facebox.close();
						}
						else {
							alert('There was a problem saving the lightbox. Please try after some time.');
							$('.add-new-lightbox').click();
						}
					  },
					  error: function() {
						  alert('There was a problem with this action. Please try after some time.');
					  }
					});
				});
			}
			else {
				alert('Please enter a name for your Lightbox');
				$('#lightbox-name').focus();
			}
		});
		
		return false;
	});
	
	// Empty lightbox
	$('.empty-lightbox').click(function(){
		if(confirm('Are you sure you want to empty this lightbox?')) {
			var id = $(this).parent().parent().parent().attr('class').replace('lightbox-', '');
			
			$.facebox(function(){
				$.ajax({
				  url: template_url + "ajax/empty_lightbox.php",
				  cache: false,
				  type: "POST",
				  data: "id=" + id,
				  success: function(data) {
					if(data == 'SUCCESS') {
						$.facebox.close();
						location.reload(true);
					}
					else if(data == 'LOGIN') {
						alert('You must be logged in to use this function.');
						$.facebox.close();
					}
					else if(data == 'FAIL') {
						alert('Lightbox already empty.');
						$.facebox.close();
					}
				  },
				  error: function() {
					  alert('There was a problem with this action. Please try after some time.');
				  }
				});
			});
		}
		
		return false;
	});
	
	// Delete lightbox
	$('.delete-lightbox').click(function(){
		if(confirm('Are you sure you want to delete this lightbox?')) {
			var id = $(this).parent().parent().parent().attr('class').replace('lightbox-', '');
			
			$.facebox(function(){
				$.ajax({
				  url: template_url + "ajax/delete_lightbox.php",
				  cache: false,
				  type: "POST",
				  data: "id=" + id,
				  success: function(data) {
					if(data == 'SUCCESS') {
						$.facebox.close();
						location.reload(true);
					}
					else if(data == 'LOGIN') {
						alert('You must be logged in to use this function.');
						$.facebox.close();
					}
					else if(data == 'FAIL') {
						alert('There was a problem deleting this lightbox. Please try after some time.');
						$.facebox.close();
					}
				  },
				  error: function() {
					  alert('There was a problem with this action. Please try after some time.');
				  }
				});
			});
		}
		
		return false;
	});
	
	// Add to lightbox
	$('.add-to-lightbox').bind('click', addToLightbox);
	
	// Edit / remove from lightbox
	$('.remove-from-lightbox').bind('click', removeFromLightbox);
	
	function addToLightbox(){
		var realid = $(this).attr('id');
		var pid = $(this).attr('id').replace('pic-id-', '');
		
		// Get lightboxes
		$.facebox(function() { 
			$.ajax({
			  url: template_url + "ajax/get_lightboxes.php",
			  cache: false,
			  success: function(html) {
				  if(html == 'LOGIN') {
					  alert('You need to login to use this function.');
					  $.facebox.close();
				  }
				$.facebox(html);
				
				$('#save-lightbox-button').click(function(){
					var id = $('#lightbox-name').attr('value');
					
					if(id != '') {
						$.facebox(function(){
							$.ajax({
							  url: template_url + "ajax/save_to_lightbox.php",
							  cache: false,
							  type: "POST",
							  data: "id=" + id + "&pid=" + pid,
							  success: function(data) {
								if(data == 'SUCCESS') {
									$.facebox.close();
									//location.reload(true);
									$('#' + realid).attr('rel', id);
									$('#' + realid).text('- Remove from Lightbox');
									$('#' + realid).unbind('click');
									$('#' + realid).bind('click', removeFromLightbox);
								}
								else if(data == 'LOGIN') {
									alert('You must be logged in to use this function.');
									$.facebox.close();
								}
								else {
									alert('There was a problem saving to the lightbox. Please try after some time.');
									$('.add-new-lightbox').click();
								}
							  },
							  error: function() {
								  alert('There was a problem with this action. Please try after some time.');
							  }
							});
						});
					}
					else {
						alert('You do not have any lightboxes!');
						$('#lightbox-name').focus();
					}
				});
			  },
			  error: function() {
				  alert('There was a problem with this action. Please try after some time.');
			  }
			});
		});
		
		return false;
	}
	
	function removeFromLightbox(){
		var realid = $(this).attr('id');
		var pid = $(this).attr('id').replace('pic-id-', '');
		var lid = $(this).attr('rel');
		
		// Get lightboxes
		$.facebox(function() { 
			$.ajax({
			  url: template_url + "ajax/edit_lightboxes.php",
			  cache: false,
			  type: "POST",
			  data: "id=" + lid,
			  success: function(html) {
				  if(html == 'LOGIN') {
					  alert('You need to login to use this function.');
					  $.facebox.close();
				  }
				$.facebox(html);
				
				$('#save-lightbox-button').click(function(){
					var id = $('#lightbox-name').attr('value');
					
					if(id != '') {
						$.facebox(function(){
							$.ajax({
							  url: template_url + "ajax/update_to_lightbox.php",
							  cache: false,
							  type: "POST",
							  data: "lid=" + id + "&pid=" + pid,
							  success: function(data) {
								if(data == 'SUCCESS') {
									$.facebox.close();
									location.reload(true);
								}
								else if(data == 'LOGIN') {
									alert('You must be logged in to use this function.');
									$.facebox.close();
								}
								else {
									alert('There was a problem saving to the lightbox. Please try after some time.');
									$('.add-new-lightbox').click();
								}
							  },
							  error: function() {
								  alert('There was a problem with this action. Please try after some time.');
							  }
							});
						});
					}
					else {
						alert('You do not have any lightboxes!');
						$('#lightbox-name').focus();
					}
				});
				$('#remove-lightbox-button').click(function(){
					if(confirm('Are you sure you want to remove this image from your lightbox?')) {
						$.ajax({
						  url: template_url + "ajax/remove_from_lightbox.php",
						  cache: false,
						  type: "POST",
						  data: "lid=" + lid + "&pid=" + pid,
						  success: function(data) {
							if(data == 'SUCCESS') {
								$.facebox.close();
								//location.reload(true);
								// Refresh for Lightbox page
								if($('#' + realid).attr('title') == 'Remove from this Lightbox')
									location.reload(true);
								else if($('#' + realid).attr('title') == 'Remove') {
									location.href = $('#remove-redirect').attr('value');
									return;
								}
								$('#' + realid).attr('rel', '');
								$('#' + realid).text('+ Add to Lightbox');
								$('#' + realid).unbind('click');
								$('#' + realid).bind('click', addToLightbox);
							}
							else if(data == 'LOGIN') {
								alert('You must be logged in to use this function.');
								$.facebox.close();
							}
							else {
								alert('There was a problem removing from the lightbox. Please try after some time.');
								$('.add-new-lightbox').click();
							}
						  },
						  error: function() {
							  alert('There was a problem with this action. Please try after some time.');
						  }
						});
					}
				});
			  },
			  error: function() {
				  alert('There was a problem with this action. Please try after some time.');
			  }
			});
		});
		
		return false;
	}
	
	// Individual images slider
	if($('#individual-slider').length != 0) {
		$('#individual-slider').nivoSlider({
			effect: 'fade',
			startSlide: $('#individual-slider-index').attr('value'),
			manualAdvance: true,
			controlNav: false,
			afterChange: function(){
				$('.nivoSlider').css('background-image', '');
			}
		});
		
		$('.individual-slider-prev').click(function(){
			$('a.nivo-prevNav').click();
			
			changeImageData();
			
			return false;
		});
		
		$('.individual-slider-next').click(function(){
			$('a.nivo-nextNav').click();
			
			changeImageData();
			
			return false;
		});
		
		function changeImageData() {
			var currentSlideIndex = parseInt($('#individual-slider').data('nivo:vars').currentSlide);
			var currentSlide = currentSlideIndex + 1;
			var pid = imageData[currentSlideIndex].pid;
			
			$('.individual-slider-count').html(currentSlide);
			$('.remove-from-lightbox').attr('id', 'pic-id-' + pid);
			$('.add-to-lightbox').attr('id', 'pic-id-' + pid);
			
			$('#pic-item-code').html(imageData[currentSlideIndex].item_code);
			$('#pic-medium').html(imageData[currentSlideIndex].medium);
			$('#pic-edition').html(imageData[currentSlideIndex].edition);
			$('#pic-dimensions').html(imageData[currentSlideIndex].dimensions);
			$('#pic-date').html(imageData[currentSlideIndex].date);
			$('#pic-description').html(imageData[currentSlideIndex].description.replace(/\\\'/g, "'").replace(/\\\"/g, '"'));
			$('#pic-extra-info').html(imageData[currentSlideIndex].extra_info.replace(/\\\'/g, "'").replace(/\\\"/g, '"'));
			
			if($('#pic-id-' + pid).length != 0) {
				if(imageData[currentSlideIndex].in_lightbox) {
					$('#pic-id-' + pid).text('- Remove from Lightbox');
					$('#pic-id-' + pid).removeClass('add-to-lightbox');
					$('#pic-id-' + pid).attr('rel', imageData[currentSlideIndex].lightbox_id);
					$('#pic-id-' + pid).addClass('remove-from-lightbox');
					
					$('#pic-id-' + pid).unbind('click');
					$('#pic-id-' + pid).bind('click', removeFromLightbox);
				}
				else {
					$('#pic-id-' + pid).text('+ Add to Lightbox');
					$('#pic-id-' + pid).removeClass('remove-from-lightbox');
					$('#pic-id-' + pid).attr('rel', '');
					$('#pic-id-' + pid).addClass('add-to-lightbox');
					
					$('#pic-id-' + pid).unbind('click');
					$('#pic-id-' + pid).bind('click', addToLightbox);
				}
			}
		}
	}
});

function validateSearch() {
	if($('#simple-search-box').attr('value') == '' || $('#simple-search-box').attr('value') == 'search' || $('#simple-search-box').attr('value').length < 3) {
		alert('Please enter a search term of at least 3 characters');
		$('#simple-search-box').focus();
		return false;
	}
	return true;
}

function rotateImages() {
	if(currentImage == 0 || currentImage >= totalImages)
		currentImage = 1;
	
	$('.rotate-image').fadeOut();
	$('#img-' + currentImage).fadeIn();
	
	currentImage++;
}
