$(function(){

/* Roll Over Image */
  var postfix = '_o';
  $('.rollover a img').not('[src*="'+ postfix +'."]').each(function() {
    var img = $(this);
    var src = img.attr('src');
    var src_on = src.substr(0, src.lastIndexOf('.'))
               + postfix
               + src.substring(src.lastIndexOf('.'));
    $('<img>').attr('src', src_on);
    img.hover(
      function() {
        img.attr('src', src_on);
      },
      function() {
        img.attr('src', src);
      }
    );
  });

/* Scroll Up */
  $('.scrollup a').click(function(){
    window.scrollTo(0,0);
    return false;
  });

/* Flat Heights */
  var sets = [], temp = [];
  $('div.flat-height-2 > div').each(function(i) {
    temp.push(this);
    if (i % 2 == 1) {
      sets.push(temp);
      temp = [];
    }
  });
  if (temp.length) sets.push(temp);
  $.each(sets, function() {
    $(this).flatHeights();
  });

/* Slide Show */
  var count=0;
  var num=$('.photos img').length;
  var ck=true;
  $('.photos').css('position', 'relative');
  $('.photos img').css('position', 'absolute');
  $('.photos img').click(function(){
    var ck=false;
    imageSwap();
  });
  var timer=setInterval(imageSwap, 3000);
  function imageSwap(){
    var ph1=num-1-count%num;
    var ph2=num-1-(count+1)%num;
    $('.photos img').eq(ph1).fadeOut('3000');
    $('.photos img').eq(ph2).fadeIn('3000');
    count++;
    if(count>num-2 && ck){
      clearInterval(timer);
    }
  }
  
/* Google Map */
	$.fn.gMap = function gMap(cLat,cLng,mLat,mLng,zm) {
		var mapdiv = $(this).get(0);
		var mapOptions = {
			zoom: zm,
			size: new google.maps.Size(600, 400),
			center: new google.maps.LatLng(cLat,cLng),
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			mapTypeControl: false,
			scaleControl: true,
			navigationControl: true,
			scrollwheel: false
		};
		var map = new google.maps.Map(mapdiv, mapOptions);
		var markerOptions = {
			map: map,
			position: new google.maps.LatLng(mLat,mLng)
		};
		var marker = new google.maps.Marker(markerOptions);
	}


/* Unaccessed Link */
  $('ul.sitemap a[href^="#"]').css('color', '#B3B3B3');

});

