/* Overlay */
$(function() { 	
	$("a[rel]").overlay({mask: {
		color: '#000',opacity: 0.5},closeOnClick: false,
		onBeforeLoad: function() {
			var wrap = this.getOverlay().find(".contentWrap");
			wrap.load(this.getTrigger().attr("href"));
		}
	});
});

/* Display Details */
function show(what) {
	$('.hideMe').fadeOut('fast');
	$(what).fadeIn('fast');
}  
function hide() {
	$('.hideMe').fadeOut('fast');
}

/* Show Map */
function showMap(a) {
	clearInterval(interval);
	$('#currentPicture img').stop().fadeOut();
	$('#map').html("<iframe name='tour-map' src='/rec/newTourMap.da?" + a + "' scrolling='no' frameborder='no' width='923' height='534' marginheight='0 marginwidth='0'></iframe>");
	$('#pictureTitle').html('Property Map');
	$('#startSlideShow').attr({onClick: "startSlideShow('go');"});
}

/* Music */
function play() {
	$("body").append('<div ID="playerContainer" style="margin-left: -1000px;"><a href="/new-tour.mp3" style="display:block;width:425px;height:300px;" id="player"></a><script language="JavaScript"> flowplayer("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.4.swf",{clip: {onFinish: function () {this.play();}}});</script></div>');
	if (navigator.appName == 'Netscape') {
	}
	else {
		$("#playerContainer").css({'position': 'absolute', 'margin-left': '-500px'});
	}
	$("#soundOnOff").attr({src: "/skins/hta/images/Sound.png",onClick: "stop();",rel: "Stop Music"});
}
function stop() {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		document.execCommand('Stop');
	}
	$('#playerContainer').remove();
	$("#soundOnOff").attr({src: "/skins/hta/images/noSound.png",onClick: "play();",rel: "Play Music"});
}

/* Minimize/Max Scrollable */
function minScrollable() {
	$('.hideMe').fadeOut('fast');
	$(".items").fadeOut('fast',function() {
		$(".rightArrow").fadeOut('fast');
		$(".leftArrow").fadeOut('fast');
		$("#nav").animate({"height": "0px"}, "slow");
		$("#navContainer").animate({"margin-top": "101px"}, "slow");
		$("#nav").css({height: '0px'});
		$("#nav").css({'border-top': '0px'});
		$("#nav").slideDown("fast");
	});
	$("#minMaxButton").attr({src: "/skins/hta/images/upBox.png",onClick: "maxScrollable();",rel: "Show Pictures"});
}
function maxScrollable() {
	$("#navContainer").animate({"margin-top": "0px"}, "fast", 
	function() {
		$(".rightArrow").fadeIn('fast');
		$(".leftArrow").fadeIn('fast');
		$("#nav").fadeIn('fast');
		$(".items").fadeIn('fast');
		$("#nav").css({'border-top': 'solid 1px #12376D'});
		$("#minMaxButton").attr({src: "/skins/hta/images/downBox.png",onClick: "minScrollable();",rel: "Hide Pictures"});
	});
	$("#nav").animate({"height": "100px"}, "fast");
}

/* Slide Show */
var active = '#first';	// variable so the .next() function knows which element to get next
var current = 1;		// variable to keep track of the current picture
function slideSwitch(go){
	$('iframe').remove();
	$('#currentPicture img').css('display','none');
	
	// check to see if we are at the end of the slide show
	// if we are at the end, start over
	// else just keep going
	if (current == $("#currentPicture > img").size()) {
		active = '#first';
		$(active).fadeIn('slow');
		current = 0;
	}
	else {
		if (go != "go") {
			active = $(active).next();
		}
		else {
			interval = setInterval('slideSwitch()', 12000);
		}
		$(active).fadeIn('slow');
		if ($(active).hasClass('pano')) {
			var howFar = $(active).width()-916;
			$(active).animate({'margin-left': -howFar+'px'}, 12000);
		 	$(active).css('margin-left','0px');
		}
	}
	if (go != "go") {
		current += 1; // get ready to fire the next slide
	}
	/* Change the Picture Title */
	$('#pictureTitle').html($(active).attr('rel'));
}

// use for Photo Slide Show link and to start the slide show			
function startSlideShow(go) {
	$('.simple_overlay').css('top','0px');
	if (go == "go") {
		slideSwitch('go');
	}
	else {
		$('#pictureTitle').html($(active).attr('rel'));
		$('#first').show();
		play();
		interval = setInterval('slideSwitch()', 12000);
	}
}
