
$(document).ready(function() {
	
	// UNIT PNG FIX
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		fixPng();
	}
	
	// SUPERFISH
	$('ul.sf-menu').superfish({
		dropShadows: false, 
		autoArrows: false,
		disableHI: false,  
		speed: 0
	});

	// FANCYBOX
	$("a.iframe").fancybox({
		transitionIn: "elastic",
		transitionOut: "elastic",
		speedIn: 400,
		overlayColor: "#000",
		overlayOpacity: 0.8,
		width: 600,
		height: 563,
		titleShow: false,
		padding: 0,
		scrolling: "auto"
	});
	$("a.gallery").fancybox({
		transitionIn: "elastic",
		transitionOut: "elastic",
		speedIn: 400,
		overlayColor: "#000",
		overlayOpacity: 0.8,
		titleShow: false,
		padding: 0,
		scrolling: "no"
	});
	$("a.popup").fancybox({
		overlayColor: "#000",
		overlayOpacity: 0.7,
		autoDimensions: false,
		width: 519,
		height: 288,
		padding: 0
	}).trigger('click');
	
	// EMAIL CLOAKING
	$(".emailCloak").each(function(){
		var ats, dots, address, i, foundDots;
		ats = [ ' at ', ' (at) ', ' [at] ' ];
		dots = [ ' dot ', ' (dot) ', ' [dot] ' ];
		address = $(this).html();
		for ( i = 0; i < ats.length; i++ ) {
			address = address.replace(ats[i], '@');
		}
		for ( i = 0; i < dots.length; i++ ) {
			foundDots = [];
			foundDots = address.split(dots[i]);
			for(var j=1; j<foundDots.length; j++) {
				address = address.replace(dots[i], '.');
			}
		}
		$(this).html('<a href="mailto:' + address + '">' + address + '</a>');
	});
	
	//ZEBRA TABLES	
	$('.zebra tr:even').addClass("even");
		
	//TABS
	jQuery(".tabs").tabs();
	
	//Randomnize Homepage Slide
	var slide=(Math.floor(Math.random()*3)) + 1;
	$("#home-flash-replace").removeClass('home-flash-replace-slide01')
	$("#home-flash-replace").addClass('home-flash-replace-slide0' + slide)
	
});

function stopTimer(){
	$("#link-02").trigger('click');
}

var currentSlide = 1;	
var nextSlide = 2;
var autoPlay = true;
var mode = "autoPlay";
var slideTimer
var mobileDevice
	 
 $(function() {
			
	// Redirect iPhone/iPod visitors
	var iOS_Device = false;
	var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
	if (agentID) {
		mobileDevice = true;
	}
	
				
	//slideTimer = setInterval("rotateImages()", 4000);

	$('a.thumb-button').click(function(){
		mode = "manualSelect"
		pause();								 					
		nextSlide = $(this).attr('button')
		rotateImages()					
	});
	
	//rotateImages()

});
 
//the following function is called form the homepage swf

function switchSlide(slide){
	nextSlide = slide;
	rotateImages()
	//alert(slide);
}



function rotateImages() {
	
	if(nextSlide != currentSlide){
		
		var oCurPhoto = $('#background-container div:nth-child('+currentSlide+')');
		var oNxtPhoto =  $('#background-container div:nth-child('+nextSlide+')');
		oCurPhoto.removeClass('current').addClass('previous');
		
		if(mobileDevice == true){
			oNxtPhoto.css({ display:'none' }).addClass('current').fadeIn("fast",
				function() {
					oCurPhoto.removeClass('previous');
				});
		}else{
			oNxtPhoto.css({ opacity: 0.0 }).addClass('current').animate({ opacity: 1.0 }, 300,
				function() {
					oCurPhoto.removeClass('previous');
				});	
		}
		
		currentSlide = nextSlide;	
	}
}
			


