/*
	   _____ ______
	  / ___// ____/
	  \__ \/ /_
	 ___/ / __/ (c) 2011
	/____/_/ sasaforic.com

*/

$(document).ready(function() {

	// slider
	$('#slider-code').tinycarousel({ pager: true, start: 2 });

	// hostings
	$('#hostings').tinycarousel({ controls: false, pager: true, animation: false });

	var prices = ['24.95', '34.95', '49.95', '74.95', '99.95'];
	var links = ['https://secure.hostnine.com/billing/cart.php?a=add&pid=61', 'https://secure.hostnine.com/billing/cart.php?a=add&pid=62', 'https://secure.hostnine.com/billing/cart.php?a=add&pid=63', 'https://secure.hostnine.com/billing/cart.php?a=add&pid=64', 'https://secure.hostnine.com/billing/cart.php?a=add&pid=65'];

	// radio
	$('#checkbox input[type="radio"]').click(function() {
		var index = $(this).closest('ul')
			.find('span')
			.index($(this).closest('span'));

		$('#checkbox ul').each(function() {
			$('input[type="radio"]:eq(' + index + ')', $(this)).attr('checked', 'checked');
		});

		$('#plan-price').text(prices[index]);
		$('#signup-tour').attr('href', links[index]);

		$('input[type="radio"]:not(:checked)').parent().removeClass('active');
		$('input[type="radio"]:checked').parent().addClass('active');
	});

	// clear inputs on focus
	$.fn.clearDefault = function(){
		return this.each(function(){
			var default_value = $(this).val();
			$(this).focus(function(){
				if ($(this).val() == default_value) $(this).val('');
			});
			$(this).blur(function(){
				if ($(this).val() == '') $(this).val(default_value);
			});
		});
	};

	$('input.text').clearDefault();
	
	// sale fade
	function sale() {
		$(".sale")
		.fadeTo(1500, 0.60)
		.fadeTo(1500, 1, function() {sale()});
	}
	$(function(){
		sale();
	});

	// hosting
	$('#hosting-icons a').click(function() {
		var $li = $(this).parent();

		if ($li.hasClass('active')) {
			// fade out current
			$li.removeClass('active');
			$('#' +  $li.attr('id').replace('icon-', '')).slideUp(500);

			// show default
			$('#default').fadeIn(1000);
		} else {
			var $currActive = $('#hosting-icons li.active');

			// if active then fadeIn otherwise slideDown
			if ($currActive.length) {
				$currActive.removeClass('active');
				$('#' + $currActive.attr('id').replace('icon-', '')).hide();
				$('#' +  $li.attr('id').replace('icon-', '')).fadeIn(1000);
			} else {
				$('#' +  $li.attr('id').replace('icon-', '')).slideDown(500);
			}

			// add active class
			$li.addClass('active');

			// hide default
			$('#default').hide();
		}

		return false;
	});

	// return to tour
	$('.return-to-tour').click(function() {
		$('#default').fadeIn(1000);

		var $li = $('#hosting-icons li.active');
		$li.removeClass('active');
		$('#' +  $li.attr('id').replace('icon-', '')).slideUp(500);

		return false;
	});

	// login slide
	$('#login-slide').click(function() {
		$('#enter').slideToggle(200);
		return false;
	});

	// lightbox
	$("a[rel='gallery']").colorbox();

	// tooltip
	$(".tooltip").tooltip({ track: true });
});
