function changemap(color){
	var filename='factory_merchant_map_'+color+".gif";
	//alert (filename);
	$('#MainMap').css('background', 'url(/images/'+filename+')');
}

function changelist(color){
	var filename='factory_merchant_map_'+color+".gif";
	//alert (filename);
	$("#blue").slideUp(500);
	$("#green").slideUp(500);
	$("#gold").slideUp(500);
	$("#red").slideUp(500);
	$("#"+color).slideDown(500);
	$('#MainMap').css('background', 'url(/images/'+filename+')');
}

$(document).ready(function(){
  var currentPosition = 0;
  var slideWidth = 672;
  var slides = $('.slide');
  var numberOfSlides = slides.length;
  var sam;
  var doslides ="yes";
  
  /* do the next 2 lines on the merchant page*/
  $(".Category_Description").slideUp(500);
  $("#antiques_description_main").slideDown(500);
  /* do the next 6 lines for map page*/
  	//var filename='factory_merchant_map.gif';
	/*$('#MainMap').css('background', 'url(/sb_media/factory_merchant_map.png)');*/
	$("#blue").slideUp(500);
	$("#green").slideUp(500);
	$("#gold").slideUp(500);
	$("#red").slideUp(500);
	


$("img.change_map").click(function(){
								  var color=$(this).attr("title");
								  //alert("red has been clicked" + color);
								  
								  changelist(color);
								  });
$("img.change_map").mouseover(function(){
								  var color=$(this).attr("title");
								  //alert("red has been clicked" + color);
								  
								  changemap(color);
								  });

$("a.Sum").click(function () {
			 	var content_show = $(this).attr("title");
				//alert("found a thingy Sum" );
				//alert(content_show );
				$("#"+content_show+"_Main").slideDown(500);
				$("#"+content_show+"_Sum").slideUp(500);
			//
			//changeItems(content_show);
		});
$("a.Main").click(function () {
				var content_show = $(this).attr("title");
			 	//alert("found a thingy main" );
				//alert(content_show );

				$("#"+content_show+"_Main").slideUp(500);
				$("#"+content_show+"_Sum").slideDown(500);
		});


$("a.Category").click(function () {
			 	var content_show = $(this).attr("title");
				//alert("found a thingy Sum "  + content_show );
				//alert(content_show );
				$(".Category_Description").slideUp(500);
				$("#"+content_show+"_main").slideDown(500);
			//
			//changeItems(content_show);
		});

  //var links='<div class="permannetlist"> <ul class="picturejump" >';
//<div class="permannetlist"> <ul class="picturejump" ><li class="picturejump" title="1" id="1">1</li> <li class="picturejump" title="2" id="2">2</li>  </ul></div>  
/*  var i =1;
  for( i=1;i<= numberOfSlides;i++){
  	links= links + '<li class="picturejump links'+i+'" title="'+i+'" id="'+i+'"> '+i+' </li>';
	//links=links;
  }
  links= links + '</ul></div>';
*/	//alert (links);
 // Remove scrollbar in JS
  $('#slidesContainer').css('overflow', 'hidden');



 
  // Wrap all .slides with #slideInner div
  slides
  .wrapAll('<div id="slideInner"></div>')
  // Float left to display horizontally, readjust .slides width
  .css({
    'float' : 'left',
    'width' : slideWidth
  });


  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert left and right arrow controls in the DOM
  $('#slideshow')
    .prepend('<span class="control" id="leftControl">Move left</span>')
    .append('<span class="control" id="rightControl">Move right</span>');
  manageControls(currentPosition);
  //$('#content').append(links);
  //$('.content').append(links);
  //alert("hmm");
  
//  	$("li.picturejump").css('text-decoration', 'none');

  //alert("hello! " + numberOfSlides + " " + currentPosition + " " +  doslides);
  //$sam=setInterval('gallery()',6000);
  // Hide left arrow control on first load
  //var $sams=window.setInterval('gallery()',6000);
  if(numberOfSlides>1 && doslides =="yes"){
	  
	$sam=$.timer(6000, function (timer) {
	//alert ("started timer");
	gallery();
/*	$("li.picturejump")
    .bind('click', function(){
    // Determine new position
	var jump;
	jump =$(this).attr("title");
	//alert("we want to jump to " +jump);
//      currentPosition = ($(this).attr('id')=='rightControl')
 //   ? currentPosition+1 : currentPosition-1;

      // Hide / show controls
      manageControls(jump);
	  slideshowjump(jump);
	  timer.stop();
      // Move slideInner using margin-left
//      $('#slideInner').animate({
 //       'marginLeft' : slideWidth*(-currentPosition)
  //    });
   });*/
	//timer.stop();
  /* end timer  function*/
  });
	
  }
/*							


  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){
    // Determine new position
      currentPosition = ($(this).attr('id')=='rightControl')
    ? currentPosition+1 : currentPosition-1;

      // Hide / show controls
      manageControls(currentPosition);
      // Move slideInner using margin-left
      $('#slideInner').animate({
        'marginLeft' : slideWidth*(-currentPosition)
      });
   });
*/ 
function gallery(){
	if(doslides =="yes"){//alert("attempting to run gallery");
	currentPosition = (currentPosition==(numberOfSlides-1)) ? 0 : currentPosition+1;

    //alert("hello! " + numberOfSlides + " " + currentPosition);
	
	$('#slideInner').animate({
        'marginLeft' : slideWidth*(-currentPosition)
    });
	}
}
$("li.picturejump").click(function(){
	//alert ("found a sub nav");								   	
	var jump;
	doslides ="no";
	//timer.stop();
	jump =$(this).attr("title");
	//alert ("found a sub nav with title: " + URL);
	//alert ("found a sub nav " + jump);
	//if(jump == currentPosition){
		slideshowjump(jump);
	//}
	
	//$sam=0;
	
/*	//alert ("Clicked on an attorney link test " + URL + " 2");

*/

});

 // manageControls: Hides and shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
    if(position==0){ $('#leftControl').hide() }
    else{ $('#leftControl').show() }
    // Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#rightControl').hide() }
    else{ $('#rightControl').show() }
    }
function slideshowjump(step){
/*	var newstep;
	currentPosition=currentPosition+1;
	if(currentPosition>step){
		newstep=step-currentPosition;
//		newstep=newstep-1;
	}else{
		newstep=step-currentPosition;
//		newstep=newstep+1;
	}
	//alert(newstep + " stp: " +step + " " + currentPosition);
*/	
	var teststep=step-1;
	if(teststep >-1){
		$('#slideInner').animate({
        'marginLeft' : slideWidth*(-teststep)
    	});
	}else{
	}
	currentPosition=teststep;

/*	$('#slideInner').animate({
        'marginLeft' : slideWidth*(-0)
    });
//  :underline;
	//  text-decoration:none;

    
	//alert ("request to go to " + step);

	if(step>1){
		step=step-1;
		$('#slideInner').animate({
        'marginLeft' : slideWidth*(-step)
    	});
	}
	*///$("li.picturejump").css('text-decoration', 'none');
	//$("#"+step).css('text-decoration', 'underline');
	//$('.links'+i).css('text-decoration', 'underline');
	

/*	baseslideshow();
		for (i=1;i<step;i++){
			gallery();
		}
*/	}
  
/* end document ready */
  });  

