jQuery(function($) {
	/*
		Slider Code
		Executed only if there are
		elements for it
	*/
	if( $("#slider li").size() ) {
		$("#slider .slider-holder").jCarouselLite({
			btnNext: ".arrow-next",
			btnPrev: ".arrow-prev",
			visible: 1,
			easing: "easeinout",
			auto: 3000,
			speed: 1000
		});

		$("#slider li").each(function() {
			$(".data p:last", this).addClass("last");
		});
	}

	/*
		Bottom Nav Code
		This code removes secondary items
		and splits the ul to two ul's for 
		two columns
	*/

	// A quick function for conditions
	function getEq( itemsCount ) {
		return Math.floor(itemsCount/2);
	}

	// Get a handle for quick access
	var $fm = $("#footer-menu");

	// Remove secondary items and home link
	$fm.find("li ul").remove();
	$fm.find("li:eq(0)").remove();

	// if there are still more than three items
	if( $fm.find("li").size()>3 ) {
		// Get handles for the lists
		var $ul1 = $fm.find("ul");
		var $ul2 = $("<ul class='menu' />").appendTo($fm);

		// Get Items Count
		var itemsCount = $ul1.find("li").size();

		// While there is a fourth element in the first ul, 
		// send it to the second one.
		while( $ul1.find("li").eq( getEq(itemsCount) ).size() ) {
			$ul1.find("li").eq( getEq(itemsCount) ).appendTo($ul2);
		}
	}

	/* 
		End of bottom nav code
	*/

	/*
		Image Widget Rows
	*/
	$(".image-widget h3").each(function() {
		if( $(this).height() == parseInt($(this).css("line-height")) )
			$(this).addClass("single-row");
	});

	$(".gform_body").prepend('<h5 class="all-required">All fields are required</h5>');

	var maxH = 0;
	$(".gb_mini_page p").each(function() {
		maxH = Math.max(maxH, $(this).height());
	}).css({ height: maxH });

	$(".flashForm").click(function() {
		confirm('You have to fill the form in the sidebar in order to download files!');
		var $el = $(".theme-widget-files");
		for(i=0; i<4; i++) {
			$el.animate({ opacity: i%2 });
		}
		return false;
	});
});
