WebFontConfig = {
	google: { families: [ 'Droid Sans', 'Crimson Text:bold' ] }
};
(function() {
	var wf = document.createElement('script');
	wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
    	'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
	wf.type = 'text/javascript';
	wf.async = 'true';
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(wf, s);
})();

$( document ).ready( function(){
	$('#navigation ul li').hover(function () {
		$(this).find('.dropdown').show();
	}, function () {
		$(this).find('.dropdown').hide();
	});
	$('#navigation ul li .dropdown ul li a').click(function () {
		$(this).parents('.dropdown').hide();
	});
	
	$('#slider').jcarousel({
		auto: 6,
		scroll: 1,
		wrap: 'both',
		initCallback: mycarousel_initCallback,
		itemVisibleInCallback: mycarousel_itemVisibleInCallback
	})
	
	// menus
	var stateDropDown = $('.stateDropDown');
	stateDropDown.each(function (index) {
		$(this).css({ zIndex : stateDropDown.length - index });
	});
	stateDropDown.find('.selected').click(function () {
		$(this).parents('.stateDropDown').find('.stateDropDownMenu').show();
		return false;
	});
	stateDropDown.find('.stateDropDownMenu').hover(function () {
		$(this).show();
	}, function () {
		$(this).hide();
	});
	stateDropDown.find('.selected').hover(function () {
		
	}, function () {
		$(this).next().hide();
	});
	stateDropDown.hover(function () {
		
	}, function () {
		$(this).find('.stateDropDownMenu').hide();
	});
	stateDropDown.find('.stateDropDownMenu ul li a').click(function () {
		//$(this).parents('.dropdown').find('p').html($(this).html());
		$(this).parents('.stateDropDownMenu').hide();
		//return false;
	});	
	
});

function mycarousel_initCallback(jc, state) {
  	if (state == 'init') {
	    jc.startAutoOrig = jc.startAuto;
	    jc.startAuto = function() {
	      if (!jc.paused) {
	        jc.startAutoOrig();
	      }
	    }
	    jc.pause = function() {
	      jc.paused = true;
	      jc.stopAuto();
	    };
	    jc.play = function() {
	      jc.paused = false;
	      jc.startAuto();
	    };
	    $('#slider-nav a.pause').live('click', function() {
	       $(this).toggleClass('active');
	    	if ($(this).hasClass('active')) {
				jc.pause();
				return false;
			} else {
				jc.play();
				return false;
			};
	    });
	  }
	$("#slider-nav p a").bind("click", function() {
		var index = $(this).attr("id").split("_");
		jc.scroll(jQuery.jcarousel.intval($(this).attr('rel')));
		$("#slider-nav a").removeClass("active"); //Remove any "active" class
		$(this).addClass("active");
        return false;
	});
	
};
function mycarousel_itemVisibleInCallback(carousel, item, index, state) { 
	$('#slider-nav a').removeClass('active');
	$('#slider-nav a').each(function() {
		var rel = $(this).attr('rel');
		if (rel == index) {
			$(this).addClass('active');
		};
	})
 }
