

function nextImage(){
	$("#image1 #theimage").clearQueue();
	
	if(imglock==0){
	$('.middle .display').css('visibility','hidden');
	imglock=1;

	var nextimg = 0;
	if(currentimg==imgs.length-1){
		nextimg = 0;
	}
	else{
		nextimg = currentimg + 1;	
	}
	
	$('#image1 #theimage').fadeTo(1000, 0, function() {
		$('#theimage').attr('src','/_elements/thumb.php?i='+imgs[nextimg][0]+'&x='+imgwidth+'&y='+imgheight+'');
		$('#photodesc').html(imgs[nextimg][1]);
		$('#image1 #theimage').load(function() {
			$('#image1 #theimage').fadeTo(1500, 1, function() {
			  
			});
			

		});
	});
	
	imglock=0;
	
	currentimg = nextimg;
	
	loadPotential(currentimg);
		$('#photodesc').fadeTo(1000, 0, function() {
			  
	});
	$('#photodesc').removeClass('nobg');
	$('#photodesc').fadeTo(1500, 1, function() {
			  
	});

	}

	return false;
}
function prevImage(){
	$("#image1 #theimage").clearQueue();
	
	if(imglock==0){
	$('.middle .display').css('visibility','hidden');
	imglock=1;
	var nextimg = 0;
	if(currentimg-1 <= 0){
		nextimg = imgs.length-1;
	}
	else{
		nextimg = currentimg -1;	
	}
	
	$('#image1 #theimage').fadeTo(1000, 0, function() {
		$('#theimage').attr('src','/_elements/thumb.php?i='+imgs[nextimg][0]+'&x='+imgwidth+'&y='+imgheight+'');
		$('#photodesc').html(imgs[nextimg][1]);
		$('#image1 #theimage').load(function() {
			$('#image1 #theimage').fadeTo(1500, 1, function() {
			  
			  
			});
			

		});
	});
	
	imglock=0;
	
	currentimg = nextimg;
	
	loadPotential(currentimg);
		$('#photodesc').fadeTo(1000, 0, function() {
			  
	});
	$('#photodesc').removeClass('nobg');
	$('#photodesc').fadeTo(1500, 1, function() {
			  
	});

	}
	$('#photodesc').removeClass('nobg');
	return false;
}

function loadPotential(num){
	
	potnextimg = 0;
	potnextimg = num + 1;
	if(potnextimg>=imgs.length){
		potnextimg=0;
	}
	
	potprevimg = 0;
	potprevimg = num -1;
	if(potprevimg<0){
		potprevimg=imgs.length-1;
	}
		imgload[potnextimg]=new Image();
		imgload[potnextimg].src='http://'+window.location.host+'/_elements/thumb.php?i='+imgs[potnextimg][0]+'&x='+imgwidth+'&y='+imgheight;	

		
		imgload[potprevimg]=new Image();
		imgload[potprevimg].src='http://'+window.location.host+'/_elements/thumb.php?i='+imgs[potprevimg][0]+'&x='+imgwidth+'&y='+imgheight;	
	
}

function showHelp() {
	$('#help').css('display','block');
	$('#help').fadeTo(1500, 1, function() {
		// Animation complete.
	});
}


function displayNav(displayid){
	clearInterval(helpTimer);
	$('#help').css('display','none');
	
	$('.displaybrand').hide();
	$('.customScrollBox .content a').removeClass('current');

	$('.customScrollBox .content a#selector'+displayid).addClass('current');
	$('#display'+displayid).fadeIn(600, 'linear', function() {
        // Animation complete
	});

	$('#display'+displayid).show(); //incase animation fails

	
	
	$('#photodesc').addClass('nobg');  
	
	
	
	
	if($('.middle .display').css('visibility')=='hidden'){
		
		
		$('.middle .display').css('visibility','visible');
		
		$('#image1').fadeTo(1000, 1, function() {
		  // Animation complete.
		});
		
	}
}


function nextTB(nextLink){
tb_show(null, $('#'+nextLink).attr('href'), false);
}
function prevTB(prevLink){
tb_show(null, $('#'+prevLink).attr('href'), false);
}

   function dumpObj(obj, name, indent, depth) {

              if (depth > MAX_DUMP_DEPTH) {

                     return indent + name + ": <Maximum Depth Reached>\n";

              }

              if (typeof obj == "object") {

                     var child = null;

                     var output = indent + name + "\n";

                     indent += "\t";

                     for (var item in obj)

                     {

                           try {

                                  child = obj[item];

                           } catch (e) {

                                  child = "<Unable to Evaluate>";

                           }

                           if (typeof child == "object") {

                                  output += dumpObj(child, item, indent, depth + 1);

                           } else {

                                  output += indent + item + ": " + child + "\n";

                           }

                     }

                     return output;

              } else {

                     return obj;

              }

       }
	   
	   function setCompare(obj){
		   var cval=0;
			if(obj.checked===true){
				cval=1;
			}
			setCookie('rv'+obj.value,cval,365);
			
			showComparisonLinks();
	   }
	   function showComparisonLinks(){
		   cookiecount=0;
		   cookies = document.cookie.split(";");
		   
		   for(i=0;i<cookies.length;i++){
			   cookies[i]=cookies[i].split("=");
			   cookies[i][0] = ltrim(cookies[i][0]);
			   cookies[i][1] = ltrim(cookies[i][1]);
			   
			   if(cookies[i][0].substr(0,2)=='rv'){
				if(cookies[i][1]=='1'){
					cookiecount = cookiecount + 1;
				}
					   
			   }
		   }
		   
		   if(cookiecount>0){
			   
			   $('#numselected').html(cookiecount);
			   $('#numselected2').html(cookiecount);
			   
			   if(cookiecount>0){
				   $('#viewcomp').css('display', 'block');
  				   $('#viewcomp2').css('display', 'inline');

			   }
			   else{
				   $('#viewcomp').css('display', 'none');
  				   $('#viewcomp2').css('display', 'none');
			   }
		   }
	   }
	   
	function ltrim(str) { 
		for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
		return str.substring(k, str.length);
	}
	function rtrim(str) {
		for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
		return str.substring(0,j+1);
	}
	function trim(str) {
		return ltrim(rtrim(str));
	}
	function isWhitespace(charToCheck) {
		var whitespaceChars = " \t\n\r\f";
		return (whitespaceChars.indexOf(charToCheck) != -1);
	}
	   
	   function setCookie(c_name,value,exdays)
		{
		var exdate=new Date();
		exdate.setDate(exdate.getDate() + exdays);
		var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString())+'; path=/';
		document.cookie=c_name + "=" + c_value;
		}
		
function clearComparisons()
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x.substr(0,2)=='rv')
    {
    	setCookie(x,0,0);
    }
  }
  window.location=window.location;
}
