/*******************************************************************************

	CSS on Sails Framework
	Title: FDG - Stagecoach
	Author: XHTMLized (http://www.xhtmlized.com/)
	Date: April 2011

*******************************************************************************/

$(document).ready(function() {

	//
	$('.colorbox').colorbox({maxHeight:'80%', scrolling: true});
	$(".colorboxInline").colorbox({maxHeight:'80%', scrolling: false, inline:true, href: '#table1'});
	$(".colorboxInline2").colorbox({maxHeight:'80%', scrolling: false, inline:true, href: '#table2'});
  $(".map-popup").colorbox({innerWidth:957,innerHeight:525,iframe:true});                                                                  	

	//
	$(document).bind('cbox_complete', function(){
		var colorBoxHeight = $('#cboxContent').height();
		if($('#cboxContent #table1').length) {
			$('#table1').tableScroll({height:colorBoxHeight-158});
		}
		if($('#cboxContent #table2').length) {
			$('#table2').tableScroll({height:colorBoxHeight-158});
		}
		//$('#table1').fixedHeaderTable({ height: colorBoxHeight-138, footer: false });
	});

	//
	//$( "#content .drawers .accordion" ).accordion();
	$('#content .drawers .accordion h3').click(function() {
		$(this).next().slideToggle('slow');
		$(this).toggleClass('active');
		return false;
	}).next().hide();
	//
	$('#content .drawers .accordion h3').each( function() {
		if ( $(this).hasClass('active') ) {
			$(this).next().slideToggle('slow');
		}
	});
	//
	$('#content .drawers nav ul li.expand a').click(function() {
		$('#content .drawers .accordion h3').addClass('active');
		$('#content .drawers .accordion div.slide').slideDown('slow');
		return false;
	});
	//
	$('#content .drawers nav ul li.collapse a').click(function() {
		$('#content .drawers .accordion h3').removeClass('active');
		$('#content .drawers .accordion div.slide').slideUp('slow');
		return false;
	});

	// slideshow
	var slides = $('#content .slideshow div img').size();
	if (slides > 1) {
		$('#content .slideshow nav').addClass('active');
	}
	$('#content .slideshow div').cycle({
		timeout: 0,
		fx: 'fade',
		speed: 'slow',
		prev: '#content .slideshow nav ul li:first-child a',
		next: '#content .slideshow nav ul li:last-child a',
		after: onAfter
	});
	function onAfter(curr,next,opts) {
		var caption = (opts.currSlide + 1) + ' of ' + opts.slideCount;
		$('#content .slideshow nav p').html(caption);
	}
	
	$(document).bind('keypress', function(e) {
      if (e.keyCode == 37)
          $('#content .slideshow div').cycle('prev');
       else if (e.keyCode == 39)
          $('#content .slideshow div').cycle('next');
  });

	// slideshow
	$('#content .slideshow2 .slides').cycle({
		timeout: 6000,
		pause: 1,
		fx: 'fade',
		pager: '#content .slideshow2 nav',
		pagerAnchorBuilder: function(idx, slide) {
			return '<a href="#"></a>';
		}
	});

	//
	$("#navigation li:has(ul)").addClass("with-sub");

	//
	var navContentWidth = $('.nav-content ul').width();
	$('.nav-content ul').css({'float':'none', 'width':navContentWidth+'px'});

	//
	if (($.browser.webkit) ){
		$('html').addClass('webkit');
	}

	//
	if (($.browser.mozilla) ){
		$('html').addClass('firefox');
	}

	if (($.browser.msie) && ($.browser.version <= "8.0")){

		// CSS3PIE
		var CSS3PIE_selectors = [
			'#content .slideshow2 nav a',
			'#content'
		];
		$( CSS3PIE_selectors.join(',') ).each(function() {
			PIE.attach(this);
		});
	}

	//
	if (($.browser.msie) && ($.browser.version == "8.0")){
	}

	//
	if (($.browser.msie) && ($.browser.version == "7.0")){
	}

});


$(window).load(function() {

	//
	if (($.browser.msie) && ($.browser.version == "7.0")){

		//
		var maxWidth = 0;
		$('#navigation > ul > li ul li').each(function(){
			if(this.offsetWidth > maxWidth) {
				maxWidth = this.offsetWidth;
			}
			$(this).parent().children('li').css({'width': maxWidth+'px'})
		});

	}


});
