function addToComparisons($camera_id) {
	$.get('ajax.php', { action: "CompareLimit"}, function(data) {
		if(data == 1) alert('You already have four cameras in your comparisons. You need to remove one before adding any more.');
	 });
	$.post("/comparebox.php", {camera_id: $camera_id},
		function(data) {
			$("#CompareBox").html(data);
		}
	);
	var cookiestr = document.cookie;
	if(cookiestr.indexOf("ShowCompareConfirm=0") != -1) {
		// Essentially do nothing
	} else {
		$('#CompareConfirm').css('top', ($(window).height()/2 - $('#CompareConfirm').height()/2) + $(window).scrollTop());
		$('#CompareConfirm').css('left', $(window).width()/2 - $('#CompareConfirm').width()/2);
		$("#CompareConfirm").fadeIn('medium');
	}
}

function removeFromComparisons($camera_id) {
	$.post("/comparebox.php", {remove: $camera_id},
		function(data) {
			$("#CompareBox").html(data);
		}
	);
}

function printElement(queryString) {
	$('#PrintArea').html('<img src="/images/dcb_print_logo.jpg" style="margin: 10px;" /><br />');
	$(queryString).clone().appendTo('#PrintArea');
	window.print();
}

		$(document).ready(function () {

			
			$("#ButtonQuickSearch").click(function() {
				$("#PriceSearchPanel").slideUp("slow", function() {
					$("#SearchTabs").css("background-position", "0px -100px");
					$("#QuickSearchPanel").slideToggle("slow", function() {
						if($("#QuickSearchPanel").css("display") == "none") {
							$("#SearchTabs").css("background-position", "0px -50px");
						}
					});
				});
			});
			
			$("#ButtonPriceSearch").click(function() {
				$("#QuickSearchPanel").slideUp("slow", function() {
					$("#SearchTabs").css("background-position", "0px -0px");
					$("#PriceSearchPanel").slideToggle("slow", function() {
						if($("#PriceSearchPanel").css("display") == "none") {
							$("#SearchTabs").css("background-position", "0px -50px");
						}
					});
				});
			});
			
			$("#ArchiveSearch").focus(function() {
				if($("#ArchiveSearch").val() == "Search the archive...") {
					$("#ArchiveSearch").css("color", "#333333");
					$("#ArchiveSearch").val("");
				}
			});
			$("#ArchiveSearch").keypress(function(event) {
				$value = $("#ArchiveSearch").val();
				if(event.which == 8) $value = $value.substr(0, $value.length - 1);
				else $value += String.fromCharCode(event.which);
				$value = $value.replace(' ', '+');
				if($value.length >= 3) {
					$("#AjaxSearchResults").load('/ajaxsearch.php?search='+$value, "", function() {
						$("#AjaxSearchResults").slideDown('medium');
					});
				}
			});
			$("#ArchiveSearch").blur(function() {
				var DropTimer = setTimeout(function() {
					$("#AjaxSearchResults").slideUp('slow');
					}, 250);
				if($("#ArchiveSearch").val() == "") {
					$("#ArchiveSearch").css("color", "#999999");
					$("#ArchiveSearch").val("Search the archive...");
				}
			});
			
			/* FEATURED LINKS */
			
			var linkindex = 0;
			var featurestopped = 0;
			
			var t = window.setInterval(function() {
				if(featurestopped == 0) {
					linkindex = linkindex + 1;
					if(linkindex == 5) {
						linkindex = 0;
					}
					changeFeaturePage();
				}
				return true;
			}, 5000);
			
			function changeFeaturePage() {		
				$("a.featured").removeClass("active");
				$("a.featured").eq(linkindex).addClass("active");
				if($("#FeaturedSlider > #Background").css("background-image") != $(".FeaturePage").eq(linkindex).css("background-image")) {
					$("#FeaturedSlider td").not(".NoFade").animate({opacity: 0}, 500);
					$("#FeaturedSlider > #Background").fadeOut('medium', function() {
						$("#FeaturedSlider > #Background").css("background-image", $(".FeaturePage").eq(linkindex).css("background-image"));
						$("#FeatureTitle").html($(".FeatureTitle").eq(linkindex).html());
						$("#FeatureText").html($(".FeatureText").eq(linkindex).html());
						$("#FeaturedSlider td").not(".NoFade").animate({opacity: 1}, 250);
						$("#FeaturedSlider > #Background").fadeIn('slow');
					});
				}
			}
			
			$("a.featured").mouseenter(function(event) {
				linkindex = $("a.featured").index(this);
				changeFeaturePage();
			});
			
			$("#FeaturedSlider").mouseenter(function(event) {
				featurestopped = 1;
			});
			
			$("#FeaturedSlider").mouseleave(function(event) {
				featurestopped = 0;
			});
			
			/* SEARCH BUTTONS */
			
			$("#ManufacturerSearch").change(function(event) {
				if($(this).val() == "") $("#ModelSearch").html('<option value="">select model');
				else $("#ModelSearch").load('/ajax.php?action=ModelSearch&manufacturer='+$(this).val());
			});
			$("#QuickSearchSubmit").click(function(event) {
				if($("#ModelSearch").val() == 0) {
					if($("#ManufacturerSearch").val() == 0) {
						return false;
					} else {
						return true;
					}
				} else {
					window.location = $("#ModelSearch").val();
					return false;
				}
			});
			
			/* Turns shots on camera pages into lightbox images */
			$('#ProductShots a').lightBox({fixedNavigation: true});
			$('#FeatureShots a').lightBox({fixedNavigation: true});
			$('#TestShots a').lightBox({fixedNavigation: true});
			
			/* Ajax form options for searching - this can be reduced */
			var AjaxFormOptions = {
				beforeSubmit: ajaxSearchPreSubmit,
				target: '#CamSearchResults',
				success: ajaxSearchSuccess
			};
			
			$("#CamSearchForm").ajaxForm(AjaxFormOptions);
			
			$("#CamSearchForm").submit(function() {
				$(this).ajaxSubmit(AjaxFormOptions);
				return false;
			});
			
			function ajaxSearchPreSubmit(formData, jqForm, options) {
				$("#SearchDialog").fadeIn('fast');
			}
			
			function ajaxSearchSuccess(responseText, statusText) {
				$("#SearchDialog").css('display', 'none');
				var top = $('#CamSearchResults').offset().top;
				$('html,body').animate({scrollTop: top }, 200);
			}
			
			/* Comparison confirmation dialog */
			
			$("#CompareClose").click(function() {
				var date = new Date();
				date.setTime(date.getTime()+(30*24*60*60*1000));
				if($("#CompareShowAgain:checked").val() != null) {
					document.cookie = 'ShowCompareConfirm=0; expires='+date.toGMTString()+'; path=/';
				}
				$("#CompareConfirm").fadeOut('medium');
			});

		});
