$(document).ready(function(){

	$('#offers-list').tabs();
	$('#hosting-list').tabs();
	
	generateSlider('#slider1');
	generateSlider('#slider2');
	generateSlider('#slider3');
	generateSlider('#slider4');
	generateSlider('#slider5');
	
	$('a', '.widget-admin-panel').each(function() {
		$(this).tooltip({ content: $(this).attr('title') });
	});
	
	var table = $('.widget-host-packs');
	var size = table.find('th').size();
	
	$('td', table).mouseenter(function() {
		var index = $(this).index() % size;
		var title = $(this).closest('table').find('th').eq(index).text();
		$(this).tooltip({content: title});
	});
	
	$('#products').jcarousel({
		scroll: 1,
		auto: 3,
		visible: 4,
		animation: 'slow',
		wrap: 'circular',
		initCallback: mycarousel_initCallback
	});
	
	var box = ($("#float-window-box").offset() || 0);
	var topPadding = 15;
	$(window).scroll(function() {
		if ($(window).scrollTop() > box.top) {
			$("#float-window-box").stop().animate({ marginTop: $(window).scrollTop() - box.top + topPadding });
		} else {
			$("#float-window-box").stop().animate({ marginTop: 0 });
		}
	});
});

function generateSlider(slider) {
	var menu = $(slider).children('.widget-offers-slider-menu').append('<ul>');
	$(slider).children('ul').cycle({
		speed: 500,
		pager: menu.children('ul'),
		pause: 1,
		pauseOnPagerHover: 1,
		cleartypeNoBg: true,
		pagerAnchorBuilder: function(id, slide) { 
			return '<li><a href="#">' + (id + 1) + '</a></li>';
    }
	});
}

function mycarousel_initCallback(carousel) {
   carousel.clip.hover(function() {
      carousel.stopAuto();
   }, function() {
      carousel.startAuto();
   });
};
