$(function(){
	
	var right;
	function fixHeight() {
  	var left = $('#left');
  	right = $('#right');
		
		if (right != null) {
  		if (left.length && right.length) {
  			h = left.height() > right.height() ? left.height() : right.height();
  			right.css('height', h + 'px');
  			left.css('height', h + 'px');
  		}
		}
	}
	
	$(document).ready(function() { setTimeout(fixHeight,1000); });
	
	$('#nav ul').each(function(){
		$(this).css('width', $(this.parentNode).width() + 'px');
	});

	$('#nav li').hover(
		function(){
			$(this).find('ul').show();
		}, function() {
			$(this).find('ul').hide();
		}
	);
		
	$('.tt').qtip({
		content: {
			text: false
		},
		style: {
			name: 'light',
			tip: false,
			width:550
		},
		position: {
			corner: {
		  	target: 'bottomLeft',
		    tooltip: 'topLeft'
			},
			adjust: {
				x: 20
			}
		},
		show: {
			delay: 0
		}
	});
	
	var initial_height = 0;
	if (right != null && right.length) {
  	initial_height = right.height();
	}
	heightArray = new Array(); 
	
	if ($('.accordian').length >0 && right != null) {
		right.css('height','auto');
				somediv = $('.accordian div:last');
				right.css('height',initial_height + somediv.height() + 'px');
				fixHeight();
		$('.accordian div').each(function() {
			$(this).show().css('height', $(this).height()).hide();
		});
	}
	
	$('.accordian').hover(function(){
		right.css('height',initial_height + $(this).find('div').height() + 'px');
		fixHeight();
		if ($(this).find('div').css('display')=='none') {
			$('.accordian div').slideUp(500, fixHeight);
			$(this).find('div').slideToggle(500, fixHeight);
		}
		return false;
	});
	
	var quotes = $('#quotes_holder blockquote');
	
	if (quotes.length) {
	  setInterval(change_slide,8000);
	  var current = quotes[0];
	  var next = quotes[1];
	  var i=2;
	  $(quotes[0]).fadeIn();
	}
	
	function change_slide() {
    $(current).fadeOut(800);
    $(next).fadeIn(1000);
    current = next;
    if (quotes[i]) {
      next = quotes[i];
      i++;
    } else {
      i=1;
      next = quotes[0];
    }
  }
  
  // open external links in a new window
  $('a').each(function() {
     var a = new RegExp('/' + window.location.host + '/');
     if(!a.test(this.href)) {
         $(this).click(function(event) {
             event.preventDefault();
             event.stopPropagation();
             window.open(this.href, '_blank');
         });
     }
  });
  
});

