
$(function(){
	var left = $('#left');
	var right = $('#right');
	
	if (left.length && right.length) {
	
		left.before('<img src="/images/grad_tl.png" id="grad_tl"><div id="grad_top"></div><img src="/images/grad_tr.png" id="grad_tr"><br class="clear"><div id="grad_left"></div>');
		right.after('<div id="grad_right"></div><img src="/images/grad_bl.png" id="grad_bl"><div id="grad_bottom"></div><img src="/images/grad_br.png" id="grad_br">');
	}
	
	fixHeight();
		
	function fixHeight() {
		
		if (left.length && right.length) {
			h = left.height() > right.height() ? left.height() : right.height();
			right.css('height', h + 'px');
			left.css('height', h + 'px');

			$('#grad_left, #grad_right').css('height', h + 'px');
			$('#grad_top, #grad_bottom').css('width', left.width() + right.width() + 'px');

		}
	}
	
	$('#nav ul').each(function(){
		$(this).css('width', $(this.parentNode).width() + 'px');
	})

	$('#nav li').hover(
		function(){
			$(this).find('ul').show();
		}, function() {
			$(this).find('ul').hide();
		}
	);
		
	// $('#nav li').hover(
	// 	function(){
	// 		$(this).find('ul').show();
	// 		$(this).data('shown', true);
	// 	}, function() {
	// 		var e = $(this);
	// 		e.data('shown', false);
	// 		
	// 		setTimeout(function(){
	// 			if (e.data('shown') !== true) {
	// 				e.find('ul').hide();
	// 			}
	// 		}, 250)
	// 	}
	// );
	
	$('.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 = right.height();
	heightArray = new Array(); 
	
	if ($('.accordian').length >0 ) {
		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').click(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);
		} else {
			$(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];
    }
  }
  
})