// Tabs
function extendTabs() {
	var $tabs = $('.ui-tabs').tabs();
	var tabAmount	= $('.ui-tabs ul li').length - 1;
	var strHtmlSwitcher	= "<div class=\"switcher\"><a href='#' class='prev-tab switch'>&#171; Prev Page</a><a href='#' class='next-tab switch'>Next Page &#187;</a></div>";
	$('.ui-tabs').append(strHtmlSwitcher);
	
	$('.next-tab').click(function(){
		var selected = $tabs.tabs('option', 'selected');
		
		var newActiveIndex	= selected + 1;
		if (newActiveIndex > tabAmount) {
			var newActiveIndex	= 0;
		}
		$tabs.tabs('select', newActiveIndex);
	});
	$('.prev-tab').click(function(){
		var selected = $tabs.tabs('option', 'selected');
		
		var newActiveIndex	= selected - 1;
		if (newActiveIndex < 0) {
			var newActiveIndex	= tabAmount;
		}
		$tabs.tabs('select', newActiveIndex);
	});
}

// datepicker
$(document).bind('afterRequest', function() {
	// add classes to different form elements
	$('body').find('input:text').addClass('textfield');
	$('body').find('textarea').addClass('textarea');
	$('body').find('select').addClass('dropdown');
	$('body').find('input:radio').addClass('radiobutton');
	$('body').find('input:checkbox').addClass('checkbox');
});

$(document).ready(function() {

	/*
	$("div.roundedblock").each(function(index){
		$(this).html('<div class="roundme"><div class="roundmecontent"><div class="t"></div>'+$(this).html()+'</div><div class="b"><div></div></div></div>');
	});	
	$("div.roundedblock.listitem").each(function(index){
		$(this).html('<div class="roundme"><div class="roundmecontent"><div class="t"></div>'+$(this).html()+'</div><div class="b"><div></div></div></div>');
	});
	*/
	
	extendTabs();
	$(document).trigger('afterRequest');
	
	// tooltips
	function enableAllTooltips(){
		$('.tooltip').cluetip({
			splitTitle: '|',
			cluezIndex: 99,
			width: 275,
			height: 'auto',
			arrows: true,
			dropShadow: true,
			dropShadowSteps: 2,
			showTitle: true,
			waitImage: true,
			sticky: false,
			bgiframe: true,
	
			fx: {
				open: 'fadeIn',
				openSpeed: 'normal'
	    	},
	
			hoverIntent: {
				sensitivity: 3,
				interval: 50,
				timeout: 0
			}
	
		});
	}
	
	enableAllTooltips();
	$(document).bind('ajaxComplete',function(){
		enableAllTooltips();
	});

	// ajax tooltips
	$('.tooltipajax').cluetip({
		cluezIndex: 99,
		width: 275,
		height: 'auto',
		arrows: true,
		dropShadow: true,
		dropShadowSteps: 1,
		showTitle: true,
		waitImage: true,
		bgiframe: true,

		fx: {
			open: 'fadeIn',
			openSpeed: 'normal'
    	},

		hoverIntent: {    
			sensitivity: 3,
			interval: 500,
			timeout: 0
		}		
	
	});

	// foldout panels
	$(".foldout .content").hide(); // hide all content within foldout panels
	$(".foldout .header").click(function(){	
		if ($(this).hasClass("expanded")) {
			$(this).removeClass("expanded").next().slideUp();
		} else {
			$(this).addClass("expanded").next().slideDown();
		}	
	});
	
	// alerts
	$(window).load(function () {	
		  // $(".alertbox").effect("pulsate", { times:2 }, 500);
	});
	
	$("a.close-alert").click(function(){
		$(".alertbox").fadeOut("slow");
		return false;
	});	
	
	// ajax loader
	//	setTimeout(function() { $('.ajaxloader').fadeOut("slow"); }, 5000);
	
	// highlight priceblock if updated
/*	$(".inverted.expanded").click(function(){
		$(".priceblock").effect("highlight", {}, 3000);
		$(".priceblock .totalprice").effect("pulsate", { times:2 }, 250);
	});
*/
	// form transformation
	//	$('.sqillsforms').jqTransform({imgPath:'static/gfx/img/'});

	// bgiframe
	$('.ac_results').bgiframe();
});