// JavaScript Document
menu = '';
pos = '';
touch = false;

function is_touch_device() {  
  try {  
    document.createEvent("TouchEvent");  
    return true;  
  } catch (e) {  
    return false;  
  }  
}
function makeTall() {
	menu = $(this).attr('class').split(' ', 1);
	pos = $(this).position();
	touch = false;
	open_menu(menu, pos.left, touch);
}
function makeShort() {
	// do nothing
}
function open_menu(menu, posLeft, touch) {
	
	$(".menu").hide();
	
	if (menu == 'm7') {
		$('#' + menu).css({"right" : 0 , "marginRight" : "16px"});
	}
	else {
		$('#' + menu).css("left", posLeft );
	}

	$('#' + menu).slideDown();
	
	if (touch) {
		 $('body').click(function() {
			$(".menu").slideUp();
		 });
		 $('#menu').click(function(event){
			 event.stopPropagation();
		 });
	}
	else{
		$('.menu').mouseleave(function () {
			$('.menu').slideUp();
		});
	}
}

var config = {    
     over: makeTall, // function = onMouseOver callback (REQUIRED)    
     timeout: 500, // number = milliseconds delay before onMouseOut    
     out: makeShort // function = onMouseOut callback (REQUIRED)    
};

var menulist = '/m1|m2|m4|m7/';

$(document).ready(function(){
	if (is_touch_device()) {
		$('#menu a').click(function (e) {
			menu = $(this).attr('class').split(' ', 1);			
			hasMenu = menulist.indexOf(menu);
			if ( hasMenu != -1 ) {
				e.preventDefault();
				pos = $(this).position();
				touch = true;
				open_menu(menu, pos.left, touch);
			}
			else {
				// do nothing, let the <a> link work by default
			}
		});  
	}
	else {
		$("#menu a").hoverIntent( config );
	}
	
	$('#header_jc, #content_jc').mouseenter(function () {
		$('.menu').slideUp();
	});
	$('#wrapper_jc').mouseleave(function () {
		$('.menu').slideUp();
	});
	

});



// home page script

t1 = 0;
/*t2 = 0;
rotate = 0;
*/
win = 2;
winLast = 2;

interval = 4000;
delay = 500;

function rotateWindows() {
	t1 = setTimeout( "rotateWindow()" , interval );
/*	t2 = setTimeout( "rotateWindow()" , interval * 2);
*/}
function rotateWindow() {
	$("#pane li").removeClass("activepane");
	$(".window").fadeOut("slow");
	if (win > 7) {
		$("#win" + winLast).fadeIn("slow");
		$(".win" + winLast).parent().addClass("activepane");
		win = 0;
	}
	else {
		$("#win" + win).fadeIn("slow");
		$(".win" + win).parent().addClass("activepane");
		if (win == 2) {
			$('.galleries').show();
		}
	}
	win++;
}
function clearTimeouts() {
	clearTimeout(t1);
}
function startSliderJandC() {
	$('#slider-jandc').fadeIn();
	$('#slider-jandc').nivoSlider({
		controlNav:false,
		pauseOnHover:false
	});
}
function startSlider(gallery) {
	$('.galleryboxes div').hide();
	$('#slider-wrapper div').hide();
	$('#slider-' + gallery).fadeIn();
	$('#slider-' + gallery).nivoSlider({
		controlNav:false,
		pauseOnHover:false
	});
	$('#galleries .' + gallery).addClass("activegallery");
	//$('#slider-' + gallery).data('nivoslider').play();	
	
}
function stopSliders() {
	
/*	$('#slider-traditional').data('nivoslider').stop();	
	$('#slider-contemporary').data('nivoslider').stop();	
	$('#slider-closet').data('nivoslider').stop();	
	$('#slider-hospitality').data('nivoslider').stop();	
*/}

function postLoad() {
	$('.postload').each( function(me) {
		$(this).attr('src', $(this).attr('longdesc'));
		$(this).removeClass('postload');
	});
	//rotateWindows();
}
lastproject = null;
$(document).ready(function(){
	postLoad();
	$("a.grouped_elements").fancybox(
		{
			'width'		:	600, 
			'height'	:	400								 
		}
	);
	
	$("#win1").fadeIn("slow");
	$("span.win1").parent().addClass("activepane");
	startSliderJandC();
	
	$('#pane span').click(function () {
		$('.menu').slideUp();
		if ( $(this).parent().attr("class") != 'activepane' ) {
			$('#galleries li').removeClass("activegallery");
			$("#pane li").removeClass('activepane');
			$(this).parent().addClass('activepane');
			clearTimeouts();
			var theWindow = $(this).attr("class");
			$('.window').hide();
			$('#' + theWindow).fadeIn();
						
			if (theWindow == ('win' + winLast) ) {
				$('#slider-wrapper').hide();
				$('.galleries').show();
				$('.galleryboxes div').fadeTo("fast", 1);
/*					$('#slider').nivoSlider({
						controlNav:false
					});
*/					
			}
			else if (theWindow == 'win3' ) {
				$('#lastproject').flash(
					{
						//swf: 'http://www.youtube.com/v/h9iYigZOYzk?rel=0&autoplay=1',
						//width: 480,
						//height: 390
						swf: 'http://www.youtube.com/v/reIl615SBIo?rel=0&modestbranding=1&showinfo=0&autoplay=1',
						width: 560,
						height: 315
					}
				);
			}
			else if (theWindow == 'win4') {
				
				$('#video-interview').flash(
					{
						swf: 'http://www.viddler.com/player/a0c4d68/',
						width: 500,
						height: 314,
						flashVars: {
							autoplay: 't'
						}, 
					}
				);
				
			}
			
		}
	}); 
	
	$('#galleries li').click(function () {
		$('#slider-wrapper').show();
		$('#galleries li').removeClass("activegallery");
		
		gallery = $(this).attr("class");
		$(this).addClass("activegallery");
		startSlider(gallery);
	});
	$('.galleryboxes div').click(function () {
		$('.galleryboxes').hide();
		$('#slider-wrapper').show();
		
		gallery = $(this).attr("class");
		$(this).addClass("activegallery");
		startSlider(gallery);
	});
	
	
	$('.galleryboxes div').mouseenter(function () {
		$('.galleryboxes div').fadeTo("fast", 1);
		$(this).fadeTo("fast", 0.33);
											
	});
	$('.galleryboxes div').mouseleave(function () {
		$('.galleryboxes div').fadeTo("fast", 1);
	});

											

	$('#window').mouseenter(function () {
		clearTimeouts();
	});
	
	$('#window').mouseleave(function () {
		//rotate = setTimeout("rotateWindows()", 10000);
	});  
		  
  

});           
// end home page script
