$( document ).ready( function(){
	$('.slides ul').jcarousel({
		scroll: 1,
		wrap: 'both',
		manual: 10,
		initCallback: _init_carousel,
		itemFirstInCallback:_first_callback,
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
	
	$('#navigation li').hover(
		function(){ $(this).find('a').addClass('hover') },
		function(){ $(this).find('a').removeClass('hover') }
	);


	$("ul.subnav").parent().append("<span />"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav

	$("ul.topnav li span").hover(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
});

function _init_carousel(carousel) {
	$('#slider-navigation a').bind('click', function() {
		var index = $(this).parent().parent().find('a').index(this) + 1;
		carousel.scroll( index );
		return false;
	});
};

function _first_callback(carousel, item, idx, state) {
	var index = idx - 1;
	$('#slider-navigation a').removeClass('active');
	$('#slider-navigation a').eq(index).addClass('active');
};

function chkDuplicate() {

 $("#results").empty().html('<div style="text-align: center"><img src="images/loading.gif" /></div>');

 var content = 'contenta='+$('#contenta').val()+'&contentb='+$('#contentb').val()+'&ajax=1';

 $.post('php/duplicate.php', content, function(data) {
  $('#results').html(data);
 });

 return false;
}
