/* set up the header */

jQuery(document).ready( function() { 
    showHeader(); 
    jQuery(window).scroll(showHeader);
    jQuery("#floatingheader .closeheader a").bind("click", function(event) {
      event.preventDefault();
      headerOff();
      });
});

var headerIsVisible = false;
var headerIsActive  = true;

function showHeader() {
  var windowPosition = parseInt(jQuery(window).scrollTop());  
  if (headerIsActive && !headerIsVisible && windowPosition > 150) {
    headerIsVisible = true;
    jQuery('#floatingheader').slideDown(300); 
  } 
  else if ( headerIsActive && headerIsVisible && windowPosition == 0 ) {
    headerIsVisible = false;
    jQuery('#floatingheader').fadeOut(300);  
  }
}

function headerOff() {
  headerIsActive = false;
  jQuery('#floatingheader').fadeOut(300);
}
  

/* set up the mailto link */

String.prototype.rot13 = function(){
  return this.replace(/[a-zA-Z]/g, function(c){
    return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
  });
};

jQuery(document).ready(function () {
  var html = '<c><n uers="znvygb:vna@vnaylanz.pbz">vna@vnaylanz.pbz</n></c>';
  jQuery('#ian_at').replaceWith(html.rot13());
});



/* works with the slide gallery */

function galleryButtons() { 
  if( 0 == galleryData.position ) { 
    jQuery('#gallery_prev').css('backgroundColor', '#aaaaaa');
    jQuery('#gallery_next').css('background-color', '#000000'); 
  } else if ( galleryData.count == galleryData.position ) { 
    jQuery('#gallery_next').css('background-color', '#aaaaaa');
    jQuery('#gallery_prev').css('background-color', '#000000'); 
  } else { jQuery('#gallery_next').css('background-color', '#000000'); jQuery('#gallery_prev').css('background-color', '#000000'); }
}


function indicatorColor(moving) {
  if(moving) document.getElementById('indicator').style.backgroundColor = '#cccccc';
  else if(0 == galleryData.position) document.getElementById('indicator').style.backgroundColor = '#a60067';
  else if(galleryData.count == galleryData.position) document.getElementById('indicator').style.backgroundColor = '#97e900';
  else  document.getElementById('indicator').style.backgroundColor = '#cccccc';
}

function indicatorMove() {
  indicatorColor(1);
  if( 0 == galleryData.position ) var indicatorPosition = galleryData.indicatorStartCss;
  else if(galleryData.position == galleryData.count) var indicatorPosition = '0px';
  else {
    // yes, there's a div/0 potential here but the conditional will prevent position = 1 from happening.
    var indicatorPositionPx = galleryData.indicatorStart - Math.round( (galleryData.position / galleryData.count) * (galleryData.indicatorStart ) );
    var indicatorPosition = indicatorPositionPx + 'px' ;
  }
  jQuery('#indicator').clearQueue();
  jQuery('#indicator').animate({ right: indicatorPosition }, galleryData.slideSpeed , indicatorColor);
}

function galleryLeft() { 
  if(galleryData.position < galleryData.count ) galleryData.position += 1; 
  else galleryData.position = 0;
  galleryMove();
  galleryButtons(); 
}

function galleryRight() {
  if(galleryData.position > 0) galleryData.position -= 1;
  else galleryData.position = galleryData.count;
  galleryMove();
  galleryButtons(); 
}

function galleryMove() {
    jQuery(galleryData.slider).clearQueue();
    var moveTo = -1 * galleryData.slideWidth * galleryData.position;
    jQuery(galleryData.slider).animate({ left: moveTo }, galleryData.slideSpeed ); 
    indicatorMove();
    galleryButtons(); 
}


function galleryInit() {
  jQuery(galleryData.container).css("overflow", "hidden");
  jQuery(galleryData.container).css("height", galleryData.galleryHeight);
  var html = '<div id="gallerycontrol" style="display: none;"><div id="indicator">' 
    + '</div><a id="gallery_prev" href="#">Previous</a><a id="gallery_next" href="#">Next</a></div>';
  jQuery(galleryData.container).after(html);

  jQuery("#gallery_prev").click( function(event) { event.preventDefault(); galleryRight(); });
  jQuery("#gallery_next").click( function(event) { event.preventDefault(); galleryLeft(); });

  galleryData.indicatorStart = galleryData.buttonWidth - galleryData.indicatorWidth;
  galleryData.indicatorStartCss = galleryData.indicatorStart + 'px';
  galleryData.indicatorWidthCss = galleryData.indicatorWidth + 'px';

  jQuery("#indicator").css({"width": galleryData.indicatorWidthCss, "right": '-' + galleryData.indicatorWidthCss } );
  galleryButtons();
  
  jQuery(window).load(function () { 
    jQuery("#gallerycontrol").slideDown(800, function() { 
        jQuery("#indicator").animate({ right: galleryData.indicatorStartCss }, 800, function(){ galleryButtons(); indicatorColor(); }); 
      } );
  });

}




/* end works with the slide gallery */

