/* Author: 
Andrew Volovyk

*/


	


$(function() {

	if ($.browser.msie){
		$('.nav-item-link').css({ 'opacity': '0.01' });			
	};

	var nav_items = $('.nav-item');

	 var top_vals = [ {"pos": -3}, {"pos": 34}, {"pos": 71}, {"pos": 108}, {"pos": 145}, {"pos": 182}, {"pos": 219}, {"pos": 256}],             
		
		
		unactive_ind  =   $('.unactive-indicator'), 
		vps_select_ind    =   $('.select-indicator', '#vps' ),
		dedicated_select_ind = $('.select-indicator', '#dedicated'),
	 	select_ind_plan = $('div', vps_select_ind),
	 	vps_plans = $('.plans','#vps').find('a'),
		autoscrolling = true,
		permanentscrolling = true,
		items = vps_plans,
		i = items.length-1;
	 
/* Switch between 1st level sections ---------------------------------------------------------------------------------*/

	$('.tab-nav a').live('click', function() {
	
        var cur_item = $(this).parent(),
        	hash = this.hash,
        	cur_page = $('.tabs').filter(hash);
        	
        	
        nav_items.addClass('invisible');
        cur_item.removeClass('invisible');
		
	
		if ($.browser.msie  && parseInt($.browser.version) < 9){
				$('.tabs').not(cur_page).hide();			
				cur_page.show();	
		}
		else
		{
	        $('.tabs').not(cur_page).animate({opacity: 0}, 300, function(){
    	    	$(this).hide();
        	});
		
	   		cur_page.show().animate({opacity: 1}, 600); 	
		}

		$('html, body').animate({ scrollTop : 350 }, 600);

		return false;
	});	
	
	
/* Switch between 2nd level sections ---------------------------------------------------------------------------------*/
	
	vps_plans.live('click', function() {
	
        var cur_item = $(this),
        	hash = this.hash,
        	cur_page = $('.vps-tabs').filter(hash);
        	
			if ($.browser.msie  && parseInt($.browser.version) < 9){
		        $('.vps-tabs').not(cur_page).hide();
	       		cur_page.show(); 
			}
			else
			{
		        $('.vps-tabs').not(cur_page).animate({opacity: 0}, 300, function(){
		        	$(this).hide();
		        });
		       	cur_page.show().animate({opacity: 1}, 600);			
			} 

		return false;
	});	
	
	
	
/* Select indicator ---------------------------------------------------------------------------------*/
	
	vps_plans.each( function(i) {
		   $(this).data("top_position", top_vals[i]); 
		}); 
	
	
	vps_plans.click(function(){
	
		var current_top = $(this).data("top_position").pos;
			
		vps_select_ind.stop().animate({top: current_top},300, 
			function(){
			});
		
		vps_plans.removeClass('selected-plan');	
		$(this).addClass('selected-plan');

		i = $(this).index()-2;
	
	}); 

	vps_plans.hover(function(){

		var current_top = $(this).data("top_position").pos + 2;
			unactive_ind.css({"top" : current_top}).show();	
		}, 
		function(){
			unactive_ind.hide();
	}); 
	
	
/* Auto switch VPS ---------------------------------------------------------------------------------*/
	

    setInterval(function () {
        if (autoscrolling && permanentscrolling) {
        	i--; 
            $(items[i]).click();
            	if(i<=0){
            		i = items.length;
            	}
        }
        
    }, 1000);
    
    $(items).mouseover(function () {
        autoscrolling = false;
        vps_plans.click(function(){
        	permanentscrolling = false;
        });
        	
    });
	
	
/* Checkbox ---------------------------------------------------------------------------------*/
	
	
	$('#dedicated').find('input').attr('checked', false);

	
	$('.input-bg').click(function(){

			$(this).toggleClass('checked').next().click();
			
			
	});
	
/*
	var	dedicated_smart_links = { 
	
		newbie : '/hosting/order?form[type]=dedicated_smart&form[term]=1', 
		pro : '/hosting/order?form[type]=dedicated_smart_pro&form[term]=1', 
		expert : '/hosting/order?form[type]=dedicated_smart_exp&form[term]=1', 
		mega : '/hosting/order?form[type]=dedicated_smart_mega&form[term]=1' 
	};
*/

	$('#dedicated').find('input').click(function(){
	
		var dedicated_input = $(this),
			clicked_cbox_term = dedicated_input.attr('class'),
			clicked_cbox = '.' + clicked_cbox_term;
			cur_price =	$('.prices').filter(clicked_cbox).find('.number');
			


		if(!this.checked){
		
			cur_price.text(parseInt(cur_price.text()) + 225);		
			dedicated_input.parent().removeClass('grey');
			
			$('.prices').filter(clicked_cbox).find('.offer-button').hide();
			$('.offer-button').filter(clicked_cbox).show().css('display','block');
			
			$('.os').filter(clicked_cbox).find('span').hide();	
			$(clicked_cbox,'.os').show().animate({ color: "#CF1333" }, 1000).delay(3000).animate({ color: "#1F1B1C" }, 2000);
			$(clicked_cbox, 'thead').show();
			
		}
		
		else
		{
			cur_price.text(parseInt(cur_price.text()) - 225);		
			dedicated_input.parent().addClass('grey');	
			
			$('.prices').filter(clicked_cbox).find('.offer-button').hide();
			$('.offer-button').filter(clicked_cbox).next().show().css('display','block');
						
			$('.os').filter(clicked_cbox).find(clicked_cbox).hide();
			$(clicked_cbox,'.os').next().show();	
			$(clicked_cbox, 'thead').hide();
		}
		
	});
	
	
	
	


/* Question hover  ---------------------------------------------------------------------------------*/
	
/*
	$('.question-icon').hover(function(){
	
		$('#info-tab').stop(true, true).fadeOut(600);
		$('#question-tab').fadeIn(600);	
	},
	
	function(){
		$('#info-tab').fadeIn(600);
		$('#question-tab').stop(true, true).fadeOut(600);	
	});
	
*/
	
	

/* Table Zebra  ---------------------------------------------------------------------------------*/

	$("#hosting tr:odd").addClass("odd");
	$("#basic tr:odd").addClass("odd");
	$("#root tr:odd").addClass("odd");
/* 	$('#terms_table_data tr:odd').addClass("odd"); */
	

/* Page header size ---------------------------------------------------------------------------------*/
	
	var sl_nav_height = $('.sidebar').height();
		
		$('#page-title').height(sl_nav_height); 
		
/* Hint ---------------------------------------------------------------------------------*/

	$('.question-icon').hint();

	
	
/* Navigate to Top ---------------------------------------------------------------------------------*/

/*
	$('.top-button').click(function() {
		$('html, body').animate({ scrollTop : 0 }, 800);
	});	
*/
	

/* Top button Fixed position ---------------------------------------------------------------------------------*/
	
/*
	button_position = Math.round(parseInt($('.page').offset().left));
	$('.top-button').css({'right' : button_position}).show();

console.log(button_position);

	$(window).scroll(function(e){ 
		$el = $('.top-button'); 

		if ($(this).scrollTop() > 660 && $el.css('position') != 'fixed'){ 
			$('.top-button').css({'position': 'fixed', 'top' : 0, 'right' : button_position}); 
		}; 
		
		if ($(this).scrollTop() < 660 && $el.css('position') == 'fixed'){ 
			$('.top-button').css({'position': 'absolute', 'right' : button_position, 'top':'660px'}); 
		}; 
		
	}); 
*/
});
	
	






















