// JavaScript Document
var accordion;
	
function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
};


function submitNewsletter(){
	
	if ($('#newsletter-name').val() == ''){
		alert('Please enter your name.');
		return;
	}
	
	if ($('#newsletter-email').val() == ''){
		alert('Please enter your email address.');
		return;
	} else if (!isValidEmailAddress($('#newsletter-email').val())){
		alert('Please enter a valid email address.');
		return;
	}
	
	$('#newsletter-form').submit();
}
	
var accordion;
var MENU_CHILDREN;
$(document).ready(function(){
	
	$('#title #menu-main-menu').superfish({
		speed: 'fast',
		delay: 500,
		onShow: function() {
			//console.debug('show');
			MENU_CHILDREN = $(this).parents('.sub-menu').children('li:not(.sfHover)').children('a');
			MENU_CHILDREN.animate({opacity: .3}, 500);
		},
		onHide: function() {	
			//console.debug('hide');
			if(MENU_CHILDREN) {
				MENU_CHILDREN.stop(true,true).animate({opacity: 1}, 200);
			}
		}
	});
		
	// watermarks
	$('#login-name').watermark('Username');
	$('#login-password').watermark('Password');
	 
	 
	$('#slidingbox-ul').hover(
		function(){  
			$(".cover", this).stop().animate({bottom:'0px'},{queue:false,duration:300});  
		}, 
		function() {  
			$(".cover", this).stop().animate({bottom:'-317px'},{queue:false,duration:300});  
			});   
	
	$('#slidingbox-ur').hover(
		function(){  
			$(".cover", this).stop().animate({bottom:'0px'},{queue:false,duration:300});  
		}, 
		function() {  
			$(".cover", this).stop().animate({bottom:'-317px'},{queue:false,duration:300}
		);  
			}); 

	$('#slidingbox-ll').hover(
		function(){  
			$(".cover", this).stop().animate({bottom:'0px'},{queue:false,duration:300});  
		}, 
		function() {  
			$(".cover", this).stop().animate({bottom:'-196px'},{queue:false,duration:300});  
		}
	); 
	
	$('#slidingbox-lr').hover(
		function(){  
			$(".cover", this).stop().animate({bottom:'0px'},{queue:false,duration:300});  
		}, 
		function() {  
			$(".cover", this).stop().animate({bottom:'-196px'},{queue:false,duration:300}
		);  
			}); 
			
	$('#projects_overview li').hover(
		function(){  
			$(".cover", this).stop().animate({bottom:'0'},{queue:false,duration:300});  
		}, 
		function() {  
			$(".cover", this).stop().animate({bottom:'-120px'},{queue:false,duration:300}
		);  
	});
	
	$('.bio_closed').click(function() {
		$(this).hide();
		var id = $(this).attr('id').substring(11);
		$('#bio-'+id).slideToggle();
	});
	
	$('.bio_closable').click(function() {
		$(this).hide();
		var id = $(this).attr('id').substring(4);
		$('#bio_closed-'+id).slideToggle();
	});
	
	var sHeight = $("#sidebar").height();
	var cHeight = $("#content").height();
	if(sHeight>=cHeight) {
		$("#sidebar").css('borderRight','2px solid #343434');
	} else {
		if (!$('#content').hasClass('home'))
			$("#content").css('borderLeft','2px solid #343434');		
	}
	
	if($("#sidebar-right").length>0) {
		var srHeight = $("#sidebar-right").height();
		if(srHeight>=cHeight) {
			$("#sidebar-right").css('borderLeft','2px solid #343434');
		} else {
			if (!$('#content').hasClass('home'))
				$("#content").css('borderRight','2px solid #343434');		
		}
	}
	//if(height >$("#sidebar-right").height() ) { $("#sidebar-right").height(height); }
	
	if ($('.slideshow').length > 0){
		$('#slideshow1').cycle({
			fx:      'scrollLeft', 
			speed:    300, 
			timeout:  10000,
			width:450,
			height:300,
			next: $("#slideshow_controls1 .btn_next"),
			prev: $("#slideshow_controls1 .btn_back"),
			after : function(currSlideElement, nextSlideElement, options) {
				var caption = $(nextSlideElement).children().attr('alt');
				$("#slideshow_controls1 .caption").html(caption);
			}
		});
		
		$('#slideshow2').cycle({
			fx:      'scrollLeft', 
			speed:    300, 
			timeout:  10000,
			width:800,
			height:500,
			next: $("#slideshow_controls2 .btn_next"),
			prev: $("#slideshow_controls2 .btn_back"),
			after : function(currSlideElement, nextSlideElement, options) {
				var caption = $(nextSlideElement).find('img').attr('alt');
				$("#slideshow_controls2 .caption").html(caption);
			}
		});
	}
	
	$('.modal_window').each(function(){  

		var window_width = $(window).width();  
		var window_height = $(window).height();  	
		
		//get the height and width of the modal  
		var modal_height = $(this).outerHeight();  
		var modal_width = $(this).outerWidth();  
		
		//calculate top and left offset needed for centering  
		var top = (window_height-modal_height)/2;  
		var left = (window_width-modal_width)/2;  

		//apply new top and left css values  
		$(this).css({'top' :170 , 'left' : left});  
		
	});  
	
	$('h5').each(function(){
		this.innerHTML = this.innerHTML.replace('“', '"');
	});
	
	  var bucket_height = 0;
	  $(".content-region").each(function() {
		if($(this).height()>bucket_height) {
			bucket_height = $(this).height();
		}
	  }).each(function() {
		$(this).height(bucket_height);
	  });

	
});

$(window).load(function() {
	accordion = $('.accordion').classicAccordion({
		width:960, 
		height:527, 
		slideshowDelay: 12000,
		preloadPanels:false, 
		slideshow:true, 
		distance:0, 
		shadow:true, 
		orientation:'horizontal', 
		closePanelOnMouseOut:false, 
		openPanelOnMouseOver: false,
		stopSlideshowOnHover: false,
		closedPanelSize:20,
		captionWidth: 380,
		captionHeight: 480,
		captionTop: 20,
		captionLeft: 24,
		openPanelOnClick: true,
		panelClick: function() {
			accordion.stopSlideshow();
			accordion.settings.slideshow=false;
		},
		panelProperties:{
			1:{captionWidth:390},
			4:{captionWidth:420}
		}
	});												
});
	
openPanel = function(id) {
	accordion.openPanel(id);
};

showSlideshowModal = function(){	

	//Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
     
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect
		$('#mask').css({'top' :0 , 'left' : 0});  
      // $('#mask').fadeIn(500);    
        $('#mask').fadeTo("fast",0.8);  
		

	$('#slideshow2-wrapper').show();
};

hideSlideshowModal = function(){	
	$('#slideshow2-wrapper').hide();
	$('#mask').hide();    
};
