$(document).ready(
function() {

$('#nav2').cycle({
	fx:     'fade', 
	speed:  500,
	timeout: 6500,
	randomizeEffects: 1});

$('#s7').cycle({
    fx:    'scrollVert',
	timeout: 0,
	next: '#btnprev',
	prev: '#btnsig',
	randomizeEffects: 1});

$("a#iframe2").fancybox({
    'width': 650,
    'height': 600,
    'transitionIn': 'fade',
    'transitionOut': 'fade',
    'type': 'iframe'});

$("a#iframe").fancybox({
    'width': 650,
    'height': 600,
    'transitionIn': 'fade',
    'transitionOut': 'fade',
    'type': 'iframe'});
            
});

function showSlidingDiv(){
$("#slidingDiv").animate({"height": "toggle"}, { duration: 500 });
}

function setVisibility(id1,id2) {
document.getElementById(id1).style.display = 'inline';
document.getElementById(id2).style.display = 'none';
} 

function bannerRotator(selector, scrollTime, pauseTime, nav){
  
  $(selector+" li:first").css("display", "block"); //show the first list item
  var count = $(selector+" li").size(); //get total number of list items
  if(count > 1){ //dont do anything if there is only one list item.  
	
	  if(scrollTime == null){ var scrollTime=1500; } //default scroll time (length of transition)
    if(pauseTime== null){ var pauseTime=8000; } //default pause time (how long to hold the image between transitions)
    
    $(selector+" li").each(function( intIndex ){ $(this).attr('rel', (intIndex+1)); }); //add the list position to the each of the items

    if(nav != null){
      var i = 1;
      $(selector).append("<div id='bannerNav'></div>"); //create navigation buttons
      while(i <= count){
	      if(i == $(selector+" li:visible").attr('rel')){  //if its the nav item that belongs to the visible image, mark it as the active nav item
          $('#bannerNav').append("<a class='active' rel='"+i+"' href='#'></a> ");
	      } 
	      else{
	        $('#bannerNav').append("<a rel='"+i+"' href='#'></a> ");
	      }
	      i++;
   	  }
   //   $('#bannerNav').append("<span class='pause'></span> "); //pause button
   //   $('#bannerNav').append("<span href='#' class='play' style='display:none;'></span> "); //play button

      $("#bannerNav a").click(function () { //handle navigation by clicking nav items
        $("#bannerNav a.active").removeClass('active');									
	      $(this).addClass('active'); //move the active nav item to this item
	      var currentClassName = $(selector+" li:visible").attr('rel');
	      var nextClassName = $(this).attr('rel');
	      var storedTimeoutID = $("#bannerNav").attr('timeoutID');

	      clearTimeout(storedTimeoutID);//stop the images from looping when a nav button is pressed
	      clearTimeout(storedTimeoutID - 1);//stop the images from looping when a nav button is pressed
	
	      if( nextClassName != currentClassName ){ //only change images if they clicked on a new item (not the one they are viewing)
		    $(selector+" li:visible").fadeOut(scrollTime);
	        $(selector+" li[rel="+nextClassName+"]").fadeIn(scrollTime);
	      }
	      
	      setTimeout(function(){ scrollImages(count, selector, scrollTime, pauseTime);}, 8000);
	      
	      return false;
      });
        }
    
    var timeout = setTimeout(function(){ 
      scrollImages(count, selector, scrollTime, pauseTime);
    }, pauseTime);
    
    $("#bannerNav").attr('timeoutID', timeout); //save the timeout id so we can cancel the loop later if a nav button is pressed
  }
}

function scrollImages(count, selector, scrollTime, pauseTime){
  currentClass = $(selector+" li:visible").attr('rel'); //get the list position of the current image
  nextClass = $(selector+" li:visible").attr('rel'); //open a new variable for the next class
  if (currentClass == count ){ nextClass=1; } //if you've reached the end of the images... start from number 1 again
  else{ nextClass++; } //if not just add one to the last number
    
  $(selector+" li[rel="+currentClass+"]").fadeOut(scrollTime); //fade out old image
  $("#bannerNav a.active").removeClass('active'); //remove active class from our nav
	
  $(selector+" li[rel="+nextClass+"]").fadeIn(scrollTime); //fade in new image
  $("#bannerNav a[rel="+nextClass+"]").addClass('active'); //add new active class to the next nav item
  
  var timeout = setTimeout(function(){ scrollImages(count, selector, scrollTime, pauseTime); }, pauseTime); //scroll the banners again after waiting for pauseTime  
  $("#bannerNav").attr('timeoutID', timeout); //save the timeout id so we can cancel the loop later if a nav button is pressed
}


function bannerRotator2(selector, scrollTime, pauseTime, nav){
  
  $(selector+" li:first").css("display", "block"); //show the first list item
  var count = $(selector+" li").size(); //get total number of list items
  if(count > 1){ //dont do anything if there is only one list item.  
	
	  if(scrollTime == null){ var scrollTime=1500; } //default scroll time (length of transition)
    if(pauseTime== null){ var pauseTime=8000; } //default pause time (how long to hold the image between transitions)
    
    $(selector+" li").each(function( intIndex ){ $(this).attr('rel', (intIndex+1)); }); //add the list position to the each of the items

    if(nav != null){
      var i = 1;
      $(selector).append("<div id='bannerNav2'></div>"); //create navigation buttons
      while(i <= count){
	      if(i == $(selector+" li:visible").attr('rel')){  //if its the nav item that belongs to the visible image, mark it as the active nav item
          $('#bannerNav2').append("<a class='active2' rel='"+i+"' href='#'></a> ");
	      } 
	      else{
	        $('#bannerNav2').append("<a rel='"+i+"' href='#'></a> ");
	      }
	      i++;
   	  }
     // $('#bannerNav2').append("<span class='pause2'></span> "); //pause button
     // $('#bannerNav2').append("<span href='#' class='play2' style='display:none;'></span> "); //play button

      $("#bannerNav2 a").click(function () { //handle navigation by clicking nav items
        $("#bannerNav2 a.active2").removeClass('active2');									
	      $(this).addClass('active2'); //move the active nav item to this item
	      var currentClassName = $(selector+" li:visible").attr('rel');
	      var nextClassName = $(this).attr('rel');
	      var storedTimeoutID = $("#bannerNav2").attr('timeoutID');

	      clearTimeout(storedTimeoutID);//stop the images from looping when a nav button is pressed
	      clearTimeout(storedTimeoutID - 1);//stop the images from looping when a nav button is pressed
	
	      if( nextClassName != currentClassName ){ //only change images if they clicked on a new item (not the one they are viewing)
		    $(selector+" li:visible").fadeOut(scrollTime);
	        $(selector+" li[rel="+nextClassName+"]").fadeIn(scrollTime);
	      }
	      setTimeout(function(){ scrollImages2(count, selector, scrollTime, pauseTime);}, 8000);
	      return false;
      });
    
 //     $("span.pause2").click(function () { //stop the images looping on pause click
 //       var storedTimeoutID = $("#bannerNav2").attr('timeoutID');
//	      clearTimeout(storedTimeoutID);
//	      $("span.pause2").hide();
//	      $("span.play2").show();
//      });
    
//      $("span.play2").click(function () { //start the images looping on play click
//        scrollImages2(count, selector, scrollTime, pauseTime);
//	      $("span.play2").hide();
//	      $("span.pause2").show();
//      });
    }
    
    var timeout = setTimeout(function(){ 
      scrollImages2(count, selector, scrollTime, pauseTime);
    }, pauseTime);
    
    $("#bannerNav2").attr('timeoutID', timeout); //save the timeout id so we can cancel the loop later if a nav button is pressed
  }
}

function scrollImages2(count, selector, scrollTime, pauseTime){
  currentClass = $(selector+" li:visible").attr('rel'); //get the list position of the current image
  nextClass = $(selector+" li:visible").attr('rel'); //open a new variable for the next class
  if (currentClass == count ){ nextClass=1; } //if you've reached the end of the images... start from number 1 again
  else{ nextClass++; } //if not just add one to the last number
    
  $(selector+" li[rel="+currentClass+"]").fadeOut(scrollTime); //fade out old image
  $("#bannerNav2 a.active2").removeClass('active2'); //remove active class from our nav
	
  $(selector+" li[rel="+nextClass+"]").fadeIn(scrollTime); //fade in new image
  $("#bannerNav2 a[rel="+nextClass+"]").addClass('active2'); //add new active class to the next nav item
  
  var timeout = setTimeout(function(){ scrollImages2(count, selector, scrollTime, pauseTime); }, pauseTime); //scroll the banners again after waiting for pauseTime  
  $("#bannerNav2").attr('timeoutID', timeout); //save the timeout id so we can cancel the loop later if a nav button is pressed
}




