 
var openFlag = false;
function moveMicrosites(rows)
{
  
	if(!openFlag)
	{
    jQuery('#micrositesCont').css( 'bottom', '68px' );
    document.getElementById('microsites').style.display = 'block';
    
    jQuery('#micrositesCont').animate({ 
        height: rows+"px"
        
      }, 1500, function(){
          
          
      } );
		openFlag = true;
		//
	}
	else
	{
    //document.getElementById('microsites').style.display = 'none';
      
      jQuery('#micrositesCont').animate({ 
        height: "30px"
      }, 1500 , function(){
       document.getElementById('microsites').style.display = 'none';
      });
		openFlag = false;
		//
	}
}
/*----------------------------*/

var oldIndex = 1;	// tracks the previous element shown

// sets up the image switch animation
function startImgSwitch(linkage)
{
	var rel = linkage.getAttribute("rel");
	if(rel != "prev" && rel != "next")
		var index = parseInt(rel.replace("prod",""));
	else
		var index = advanceImg(rel);
	// if number clicked is already shown or navigation is at the ends we return
	alert( index );
	if(oldIndex == index || index == false)
		return false;
	// remove the old id and add it to the button that we are moving to
	document.getElementById("selectedShot").setAttribute("id","");
	document.getElementsByClassName("photoNavBtn")[index-1].setAttribute("id","selectedShot");
	alert( imgNames.length  );
	if( imgNames.length > 10 )
	{
    if( index > 3 && index < (imgNames.length -4) )
    {
      document.getElementsByClassName("photoNavBtn")[index-1].style.display = 'block';
    }
    
    if( oldIndex > 3 && oldIndex < (imgNames.length -4) )
    {
      document.getElementsByClassName("photoNavBtn")[oldIndex-1].style.display = 'none';
    }
	}
	
	// create the  image object.
	// the onload has to come before we actually assign a src to the image because of a bug in IE
	var img = new Image();
	img.onload = function()
	{
		
		$('fullProdImage').fade({duration:.250,afterFinish:function(){ finishImgSwitch(img.src); }});
	}
	img.src = imgNames[index-1].src;
	oldIndex = index;	// remember the element that is currently shown
}
/*----------------------------*/

// advnaces the index back or foward when the prev/next buttons are clicked.
function advanceImg(rel)
{
	
	var index = (rel == "prev") ? oldIndex-1 : oldIndex+1;
	if(index > 0 && index < imgNames.length+1)
		return index;
	return false;
}
/*----------------------------*/

// adds the new element to the page and fades it in.
function finishImgSwitch(imgSrc)
{
	// console.log(imgSrc)
	document.getElementById("fullProdImage").src = imgSrc;
	$('fullProdImage').appear({duration:.5});
}
/*----------------------------*/

// preload the images so there is no delay for the user
function preloadProdShots()
{
	for(var i=0,z=arguments.length;i<z;i++)
	{
		imgNames.push(new Image());
		imgNames[i].onload = function()
		{
			// console.log(this.src)
		}
		imgNames[i].src = imgPath + arguments[i];
	}
}
/*----------------------------*/

function expandFilter(linkage,id)
{
	var el = $(id);
	if(el.className.match(/\bclosed\b/))
	{
		linkage.innerHTML = "Open";
		linkage.setAttribute("title","Open");
		el.className = el.className.replace(/\bclosed\b/,"opened");
		// Effect.BlindDown(id);
	}
	else if(el.className.match(/\bopened\b/))
	{
		linkage.innerHTML = "Close";
		linkage.setAttribute("title","Close");
		el.className = el.className.replace(/\bopened\b/,"closed");
	}
}
/*----------------------------*/


