
// AISPIRE LIGHTBOX SIMPLE GALLERY

var currSlideNumber=0;
var numberOfSlides=0;
var intervalHandle="";

function advanceSlide() {
	// Hide old slide and, asynchronously...
	$('#slideshowPage'+currSlideNumber).css({opacity:1}).stop().animate(
		{ opacity:0.0 },
		2000,
		function() { $(this).hide(); }
	).css({'z-index':'0'});
	currSlideNumber+=1;
	// ... show new slide
	currSlideNumber%=numberOfSlides;
	$('#slideshowPage'+currSlideNumber).css({opacity:0}).show().stop().animate(
		{ opacity:1.0 },
		2000,
		function() { }
	).css({'z-index':'2000'});
	// show position on dots
	$('.homePageBullet').removeClass('homePageBulletHighlight').each(function(){
		if ( $(this).attr('title')==currSlideNumber+1 ) {
			$(this).addClass('homePageBulletHighlight');
		}
	});
	// show correct key text
	$('.homePageKeyPhrase').hide().each(function(){
		if ( $(this).attr('title')==currSlideNumber+1 ) {
			$(this).show();
		}
	});
	
}

function gotoSlide(slideNum) {
	clearInterval(intervalHandle);
	// show correct key text
	$('.homePageKeyPhrase').hide().each(function(){
		if ( $(this).attr('title')==slideNum+1 ) {
			$(this).show();
		}
	});
	// show position on dots
	$('.homePageBullet').removeClass('homePageBulletHighlight').each(function(){
		if ( $(this).attr('title')==slideNum+1 ) {
			$(this).addClass('homePageBulletHighlight');
		}
	});
	// Hide old slide and, asynchronously...
	$('#slideshowPage'+currSlideNumber).css({opacity:1}).stop().animate(
		{ opacity:0.0 },
		2000,
		function() { $(this).hide(); }
	).css({'z-index':'0'});
	currSlideNumber=slideNum; // no checking you need to get this right -- !!!
	$('#slideshowPage'+currSlideNumber).css({opacity:0}).show().stop().animate(
		{ opacity:1.0 },
		2000,
		function() { }
	).css({'z-index':'2000'});
}

function startSlides(numberOfSlides) {
	$('div.slideshowPage').hide(); // initially hide all slides
	currSlideNumber = numberOfSlides-1; // last slide, so we'll start by advancing to first slide
	advanceSlide();
	intervalHandle = setInterval(advanceSlide,7000);
}


//========================//




function clearOverlays()     { 
	$('img.houseBlueprintOverlay').hide(); 
	$('img.businessBlueprintOverlay').hide(); 
	$('img.securityBlueprintOverlay').hide(); 
}

function showBathroom()      { clearOverlays(); $('#blueprintBathrooms').show(); }
function showBed()           { clearOverlays(); $('#blueprintBedrooms').show(); }
function showCloset()        { /* no closet img */ }
function showEntrancePorch() { clearOverlays(); $('#blueprintEntrance').show(); }
function showFamilyRoom()    { clearOverlays(); $('#blueprintFamilyRoom').show(); }
function showHomeOffice()    { clearOverlays(); $('#blueprintHomeOffice').show(); }
function showHomeTheater()   { clearOverlays(); $('#blueprintHomeTheater').show(); }
function showKitchen()       { clearOverlays(); $('#blueprintKitchen').show(); }
function showDiningRoom()    { clearOverlays(); $('#blueprintDiningRoom').show(); }
function showPantry()        { clearOverlays(); $('#blueprintPantry').show(); }
function showPool()          { clearOverlays(); $('#blueprintPool').show(); }
function showSpa()           { clearOverlays(); $('#blueprintPool').show(); }
function showWineCellar()    { clearOverlays(); $('#blueprintWineCellar').show(); }

function showPresentationRoom() { clearOverlays(); $('#blueprintPresentationRoom').show(); }
function showMeetingRoom()      { clearOverlays(); $('#blueprintMeetingRoom').show(); }
function showReception()        { clearOverlays(); $('#blueprintReception').show(); }
function showOffice()           { clearOverlays(); $('#blueprintOffices').show(); }
function showConferenceRoom()   { clearOverlays(); $('#blueprintConferenceRoom').show(); }

function showVideo()             { clearOverlays(); $('#blueprintVideo').show(); }
function showLighting()          { clearOverlays(); $('#blueprintLighting').show(); }
function showHeatingAndCooling() { clearOverlays(); $('#blueprintHeatingAndCooling').show(); }
function showEnergy()            { clearOverlays(); $('#blueprintEnergy').show(); }

/*
function FadeMainImages() {
		$('#loading').hide();
		$('#mainImageBW').fadeIn(1500, function() {
			$('#mainImageCol').fadeIn(1500, function() {
			});
		});

}
*/

$(document).ready(function() {

	// Activate mega-menu-button
/*
	$('#mega-menu').hover(
		function() {
*/
			$('#mega-menu-button').css({'border':'1px solid #a33', 'top':'99px', 'right':'19px'});
			$('#hidden-mega-menu-sections').fadeIn(500);
/*
		},
		function() {
			$('#hidden-mega-menu-sections').fadeOut(400);
			$('#mega-menu-button').css({'border':'none', 'top':'100px', 'right':'20px'});
		}
	);
*/
	
	// Activate business hover
/*
	$('#businessBuilding').hover(
		function() {
			$(this).css({'border':'1px #888 solid', 'top':'19px', 'left':'-1px'});
		},
		function() {
			$(this).css({'border':'none', 'top':'20px', 'left':'0px'});
		}
	);
*/
	// Activate all control Images
/*
	$('.controlImg').hover(
		function() {
			$(this).css({'border':'1px #888 solid', 'top':'-1px', 'left':'-1px'});
		},
		function() {
			$(this).css({'border':'none', 'top':'0px', 'left':'0px'});
		}
	);
	$('.controlh3').hover(
		function() {
			$(this).next().css({'border':'1px #888 solid', 'top':'-1px', 'left':'-1px'});
		},
		function() {
			$(this).next().css({'border':'none', 'top':'0px', 'left':'0px'});
		} 
	);
*/
	
	// Setup email link (to minimise spam)
	$('.emailLink').html("sales@soundworksny.com").attr('href','mailto:sales@soundworksny.com');
	
/*
	// Load main images
	if ( $('#mainImageBW').length>0 ) {
		if ( $('#mainImageBW')[0].complete===true ) { FadeMainImages(); }
		$('#mainImageBW').load(function() {
			FadeMainImages();
		});
	}
*/
	

	// get caption for this image
	$('img.houseBlueprintOverlay').hover(
		function(){
			var text = $(this).attr('alt');
			var bits1 = text.split("-");
			var heading = $.trim(bits1[0]);
			var liElems = $.trim(bits1[1]);
			var bits2   = liElems.split(",");
			var i=0;
			var html = "<span id='heading'>"+heading+"</span><ul>";
			for (;i<bits2.length;i+=1) {
				html += "<li>"+$.trim(bits2[i])+"</li>";
			}
			// put the text into the caption code
			$('#hoverCaption').html(html);
		},
		function(){
			// if text==caption code text, remove the text from the caption code
			// (if not we've already overwritten it via another img calling this code)
//			var text = $(this).attr('alt');
//			if ( text === $('#hoverCaption').html() ) {
				$('#hoverCaption').html("");
//			}	
	});

	// track mouse for HOUSE blueprint hovers
	$('#blueprint, img.houseBlueprintOverlay').mousemove(function(e){
		var offset = $(this).offset();
		var x = e.pageX - offset.left;
		var y = e.pageY - offset.top;
		//$('#status').html(x +', '+ y); // DEBUG
		
		if (x>=15 && x<127) {
			if      (y>=110 && y<197 ) { showBed(); }
			else if (y>=197 && y<245 ) { showBathroom(); }
			else if (y>=245 && y<271 ) { showBathroom(); } // was showCloset
			else                       { clearOverlays(); }
		}
		else if (x>=127 && x<213) {
			if      (y>=61  && y<110 ) { showSpa(); }
			else if (y>=148 && y<231 ) { showFamilyRoom(); }
			else if (y>=232 && y<291 ) { showHomeOffice(); }
			else if (y>=292          ) { showEntrancePorch(); }
			else                       { clearOverlays(); }
		}
		else if (x>=213 && x<267) {
			if      (y>=61  && y<110 ) { showPool(); }
			else if (y>=148 && y<231 ) { showFamilyRoom(); }
			else if (y>=231          ) { showEntrancePorch(); }
			else                       { clearOverlays(); }
		}
		else if (x>=267 && x<349) {
			if      (y>=104 && y<131 ) { showWineCellar(); } 
			else if (y>=131 && y<181 ) { showFamilyRoom(); }
			else if (y>=181 && y<230 ) { showKitchen(); }
			else if (y>=230 && y<290 ) { showKitchen(); }
			else if (y>=290          ) { showEntrancePorch(); }
			else                       { clearOverlays(); }
		}
		else if (x>=349 && x<372) {
			if      (y>=104 && y<131 ) { showWineCellar(); }
			else if (y>=131 && y<194 ) { showFamilyRoom(); }
			else if (y>=194 && y<210 ) { showPantry(); }
			else if (y>=210 && y<290 ) { showBed(); }
			else                       { clearOverlays(); }
		}
		else if (x>=372 && x<422) {
			if      (y>=40  && y<146 ) { showHomeTheater(); }
			else if (y>=146 && y<181 ) { showBathroom(); }
			else if (y>=181 && y<209 ) { showFamilyRoom(); }
			else if (y>=209 && y<290 ) { showBed(); }
			else                       { clearOverlays(); }
		}
		else if (x>=422 && x<527) {
			if      (y>=40  && y<146 ) { showHomeTheater(); }
			else if (y>=146 && y<260 ) { showBed(); }
			else if (y>=260 && y<290 ) { showBathroom(); } 
			else                       { clearOverlays(); }
		}
		else {
			clearOverlays();
		}
	});

	// track mouse for BUSINESS blueprint hovers
/*
	$('#blueprintBusiness, img.businessBlueprintOverlay').mousemove(function(e){
		var offset = $(this).offset();
		var x = e.pageX - offset.left;
		var y = e.pageY - offset.top;
		//$('#status').html(x +', '+ y); // DEBUG
		
		if (x>=9 && x<132) {
			if      (y>=110 && y<205 ) { showPresentationRoom(); }
			else if (y>=205 && y<310 ) { showMeetingRoom(); }
			else                       { clearOverlays(); }
		}
		else if (x>=132 && x<280) {
			if      (y>=150 && y<337 ) { showReception(); }
			else                       { clearOverlays(); }
		}
		else if (x>=280 && x<426) {
			if      (y>=80  && y<185 ) { showOffice(); }
			else if (y>=185 && y<337 ) { showConferenceRoom(); }
			else                       { clearOverlays(); }
		}
		else {
			clearOverlays();
		}
	});

*/
	// track mouse for SECURITY blueprint hovers
/*
	$('#blueprintSecurity, img.securityBlueprintOverlay').mousemove(function(e){
		var offset = $(this).offset();
		var x = e.pageX - offset.left;
		var y = e.pageY - offset.top;
		//$('#status').html(x +', '+ y); // DEBUG
		
		if (x>=0 && x<130) {
			if      (y>=120 && y<250 ) { showVideo(); }
			else                       { clearOverlays(); }
		}
		else if (x>=130 && x<285) {
			if      (y>=0   && y<160 ) { showLighting(); }
			else if (y>=225 && y<375 ) { showHeatingAndCooling(); }
			else                       { clearOverlays(); }
		}
		else if (x>=285 && x<431) {
			if      (y>=2   && y<250 ) { showEnergy(); }
			else                       { clearOverlays(); }
		}
		else {
			clearOverlays();
		}
	});
*/

	
	// Make the Soundwork logo clickable => homepage
	$('#soundworks-logo, #control-your-world').css({'cursor':'pointer'}).click(function(){ location.href = "/"; });
	
	
	// HOME PAGE SLIDESHOW
	numberOfSlides = $('div.slideshowPage').length;
	if (numberOfSlides>0) {
		startSlides(numberOfSlides);
	}	
	// goto a particular slide in the slideshow
	$('.homePageBullet').click(function(){
		var slideNum = parseInt($(this).attr('title'), 10) - 1;
		gotoSlide(slideNum);
	});
	
	// 9-SQUARE MENU
	$('.left-floated-item').hover(
		function() {
			var t = $(this).attr("title");
			$(this).append("<span class='nine-square-caption'>"+t+"</span>");
		},
		function() {
			$(".nine-square-caption").remove();
		}
	);
	
	
		
}); // end doc load

