// JavaScript Document
$(function() {

if ($('#pt01btn').length) { 
	var activePt = '#pt01';
	var activeBn = "";
	$('#pt01btn').css('color', '#ED1E29');
	$('#pt01btn').click(function() {
		if (activePt != '#pt01') {
			switchContent('#pt01');
		}
	});
	if ($('#pt02btn').length) { 
		$('#pt02btn').click(function() {
			if (activePt != '#pt02') {
				switchContent('#pt02');
			}
		});
	}
	if ($('#pt03btn').length) { 
		$('#pt03btn').click(function() {
			if (activePt != '#pt03') {
				switchContent('#pt03');
			}
		});
	}
	if ($('#pt04btn').length) { 
		$('#pt04btn').click(function() {
			if (activePt != '#pt04') {
				switchContent('#pt04');
			}
		});
	}
	if ($('#pt05btn').length) { 
		$('#pt05btn').click(function() {
			if (activePt != '#pt05') {
				switchContent('#pt05');
			}
		});
	}
	if ($('#pt06btn').length) { 
		$('#pt06btn').click(function() {
			if (activePt != '#pt06') {
				switchContent('#pt06');
			}
		});
	}
	if ($('#bn01').is(":visible")) {
		activeBn = "#bn01";
	};
	function switchContent(argPt) {
		$(activePt + "btn").animate({color:"#ffffff"}, 'fast');
		$(argPt + "btn").animate({color:"#ED1E29"}, 'fast');
		
		$(activePt).hide('normal');
		$(argPt).show('normal');
		
		$(activePt + "text").hide()
		$(argPt + "text").show();
		
		if (activeBn != "") {
			$(activeBn).hide();
			activeBn = '#bn' + argPt.slice(3)
			$(activeBn).show();
		}

		activePt = argPt;
	}
}

var id = $("#meeker-slider-widget").attr('class'); // becomes for example "#chesapeake" which matches the active a element.
var sliderIncrement = 106;
var sliderMax = Math.max($('.inner-wrap a').length - 6, 0);

var currentSlide = parseInt( $("#"+id).css('left') )/sliderIncrement;
$('.sliderNumDisplay').html(currentSlide + 1);

// Get or set sliderPosition
var sliderPosition;
if (location.hash.substr(2) == "") {
	sliderPosition = currentSlide;
	if (sliderPosition > sliderMax) {
		sliderPosition = sliderMax;
	}
} else {
	sliderPosition = location.hash.substr(2);
}

// Hack 
sliderPosition -= 1;
sliderPosition += 1;

// modify href of links in widget to add hash positioning
$('#meeker-slider-widget a').each(function() {this.href = this.href.split('#')[0] + "#p" + sliderPosition});

var intervalID;
var isMouseDown;
if (sliderPosition == 0) {
	$(".slideleft").hide();
}
if (sliderPosition == sliderMax) {
	$(".slideright").hide();
}

// set the slider to position
$(".slider div").css("left", (sliderPosition * -sliderIncrement ) +"px");

// fade out thumbs
$("#meeker-slider-widget a img").fadeTo( 0, .3);

// reactivate active
$("#"+id + " img").fadeTo( 0, 1);

// change title
var targetTitle = $(".title-area").children(".ardsleypark");
targetTitle.hide()
var defaultTitle = $(".title-area").children("."+ id);
defaultTitle.show();
// change title on rollover
//$("#meeker-slider-widget").children("."+ id).

// add hover behaivor
/*$("#meeker-slider-widget a").hover(function() {
}, function() {
});*/

// change hover to chaser
var defaultMarkerPosition = $('.sliderMarker').css('left');
var targetMarker;
var sliderOff;
$("#meeker-slider-widget a").hover(function() {
	targetMarker = parseInt($(this).css('left'))+40;
	if ($('.sliderMarker').css('display') == 'none' || $('.sliderMarker').css('opacity') == 0) { 
		$('.sliderMarker').css('opacity', 0); 
		$('.sliderMarker').css('display', 'inline'); 
		$('.sliderMarker').css('left', targetMarker + 'px'); 
		$('.sliderMarker').stop().animate({opacity: 1}, 'fast');
	} else {
		$('.sliderMarker').stop().animate({left: targetMarker +"px", opacity: 1 }, "fast" );
	}
	
	if ($(this).attr('id') != id) {
		targetTitle = $(".title-area").children('.' + $(this).attr('id'))
		defaultTitle.hide();
		targetTitle.show();
	}
	if ($(this).attr('id') != id) $(this).children('img').stop().fadeTo("fast", 1)
}, function() {
	$('.sliderMarker').stop().fadeOut('fast');
		
	if ($(this).attr('id') != id) {
		targetTitle.hide();
		defaultTitle.show();
	}
	if ($(this).attr('id') != id) $(this).children('img').stop().fadeTo("fast", .3)
});



/*					*
 * Slider functions	*
 *					*/
 
function slideright() {
	if (isMouseDown && sliderPosition < sliderMax) {
		sliderPosition = sliderPosition.valueOf() + 1;
		$(".slider div").animate( {left: (sliderPosition * -sliderIncrement ) +"px"}, "fast", "linear", slideright);
		$('#meeker-slider-widget a').each(function() {this.href = this.href.split('#')[0] + "#p" + sliderPosition});
	}
	if (sliderPosition >= sliderMax) {
		$(".slideright").fadeOut('normal');
	}
	if (sliderPosition > 0) {
		$(".slideleft").fadeIn('normal');
	}
}
function slideleft() {
	if (isMouseDown && sliderPosition > 0) {
		sliderPosition -= 1;
		$(".slider div").animate( {left: (sliderPosition * -sliderIncrement) +"px"}, "fast", "linear", slideleft);
		$('#meeker-slider-widget a').each(function() {this.href = this.href.split('#')[0] + "#p" + sliderPosition});
	}
	if (sliderPosition <= 0) {
		$(".slideleft").fadeOut('normal');
	}
	if (sliderPosition < sliderMax) {
		$(".slideright").fadeIn('normal');
	}
}

$(".slideright").hover(function() {
	isMouseDown = true;
	slideright();
}, function() {
	isMouseDown = false
});
$(".slideleft").hover(function() {
	isMouseDown = true;
	slideleft();
}, function () {
	isMouseDown = false
});

/*$(".slideright").mouseup(function() {
	isMouseDown = false
}).mousedown(function() {
	isMouseDown = true;
	slideright();
});
$(".slideleft").mouseup(function() {
	isMouseDown = false
}).mousedown(function () {
	isMouseDown = true;
	slideleft();
});*/
	 
});

