function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

$(document).ready(function(){
/* Change imgs */
var imgArr = new Array(
 './images/topbg.jpg',
 './images/topbg2.jpg',
 './images/topbg3.jpg',
 './images/topbg4.jpg',
 './images/topbg5.jpg'
 );
 
var preloadArr = new Array();
var i;
 
for(i=0; i < imgArr.length; i++){
 preloadArr[i] = new Image();
 preloadArr[i].src = imgArr[i];
}

var currImg = 1;
var intID = setInterval(changeImg, 7000);
 
function changeImg(){
 $('#headerbg').animate({opacity: 0}, 1000, function(){
 $(this).css('background','url(' + preloadArr[currImg++%preloadArr.length].src +') center top no-repeat');
 }).animate({opacity: 1}, 1000);
}

/* FADE LABEL INPUTS */
	$('.maila').dwFadingLinks({
		color: '#009FEC',
		duration: 700
	});
	$('.mail, .name, .email, .phone, .message').dwFadingLinks({
		color: '#fff',
		duration: 700
	});
	
/* FADE IMAGES */
	$('.button, .mapimg').append('<span class="hover"></span>').each(function () {
		var $span = $('> span.hover', this).css('opacity', 0);
	 	$(this).hover(function () {
	    $span.stop().fadeTo(500, 1);
	 	}, function () {
	   		$span.stop().fadeTo(500, 0);
	  	});
	});
	
/* OVERLAY GOOGLE MAPS */
	$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'dark_square',slideshow:5000});
	$("#map a[rel^='prettyPhoto']:first").prettyPhoto({
		custom_markup: '<div id="map_canvas" style="width:800px; height:500px"></div>',
		changepicturecallback: function(){ initialize(); }
	});

/* ASSIGN DEFAULT VALUES */
		$("#name").DefaultValue("Your Name");
		$("#email").DefaultValue("Your Email");
		$("#phone").DefaultValue("Your Phone");
		$("#message").DefaultValue("Your message or question");
});


/* Home page building tabs */
$(document).ready(function(){
	$(".menu li").click(function(e){
		switch(e.target.id){
			case "building1":
				//change status &amp;amp;amp; style menu
				$("#building1").addClass("active");
				$("#building2").removeClass("active");
				$("#building3").removeClass("active");
				//display selected division, hide others
				$("div.building1").fadeIn(2500);
				$("div.building2").css("display", "none");
				$("div.building3").css("display", "none");
			break;
			case "building2":
				//change status &amp;amp;amp; style menu
				$("#building1").removeClass("active");
				$("#building2").addClass("active");
				$("#building3").removeClass("active");
				//display selected division, hide others
				$("div.building2").fadeIn(2500);
				$("div.building1").css("display", "none");
				$("div.building3").css("display", "none");
			break;
			case "building3":
				//change status &amp;amp;amp; style menu
				$("#building1").removeClass("active");
				$("#building2").removeClass("active");
				$("#building3").addClass("active");
				//display selected division, hide others
				$("div.building3").fadeIn(2500);
				$("div.building1").css("display", "none");
				$("div.building2").css("display", "none");
			break;
		}
		//alert(e.target.id);
		return false;
	});
});

/* Top slider*/

$(document).ready(function() {
	
	$("#open, #tmcontact, #tmcontactview").click(function(){
		$("div#topslide").slideDown("slow");
	});	
		
	$("#close, #tmcontact2, #tmcontact2view").click(function(){
		$("div#topslide").slideUp("slow");
	});		
	
	// Switch buttons from "open" to "close" on click
	$("#toggle a, #tmc a, #tmcview a").click(function(){
		$("#toggle a, #tmc a, #tmcview a").toggle();
	});
	
});
