/*--- IE6 hover ---*/
function ieHover(h_list, h_class){
	if($.browser.msie && $.browser.version < 7){
		if(!h_class) var h_class = 'hover';
		$(h_list).mouseenter(function(){
			$(this).addClass(h_class);
		}).mouseleave(function(){
			$(this).removeClass(h_class);
		});
	}
}
jQuery.fn.crawlLine = function(_options){
	// defaults options
	var _options = jQuery.extend({
		speed:2,
		crawElement:'div',
		textElement:'span',
		hoverClass:'viewText'
	},_options);
	
	return this.each(function(){
		var _THIS = jQuery(this);
		var _el = $(_options.crawElement, _THIS).css('position','relative');
		var _text = $(_options.textElement, _THIS);
		var _clone = _text.css('whiteSpace','nowrap').clone();
		var _elWidth = 0;
		var _k = 1;
		
		// set parametrs *******************************************************
		var _textWidth = 0;
		_text.each(function(){
			_textWidth += $(this).outerWidth(true);
		});
		var _duration = _textWidth*50 / _options.speed;
		_el.append(_clone);
		_el.css('width',_textWidth*2);
		
	    var animate = function() {
			_el.animate({left:-_textWidth}, {queue:false, duration:_duration*_k, easing:'linear', complete:function(){
				_el.css('left','0');
				_k=1;
				animate();
			}})
	    }
	    animate();
		
	    _THIS.hover(function() {
			_el.stop();
			_THIS.addClass(_options.hoverClass);
	    }, function(){
			_THIS.removeClass(_options.hoverClass);
			_k = (_textWidth + parseInt(_el.css('left')))/_textWidth;
			animate();
	    })
		_THIS.bind('wheel',function(event,delta){
			var _marginScroll;
			if (delta<0) {
				_marginScroll = parseInt(_el.css('left')) - 20;
				_el.animate({left:_marginScroll}, {queue:false, duration:100, easing:'linear', complete:function(){
					_k = (_textWidth + parseInt(_el.css('left')))/_textWidth;
				}});
			} else {
				_marginScroll = parseInt(_el.css('left')) + 20;
				if (_marginScroll > 0) _marginScroll = 0;
				_el.animate({left:_marginScroll}, {queue:false, duration:100, easing:'linear', complete:function(){
					_k = (_textWidth + parseInt(_el.css('left')))/_textWidth;
				}});
			}
			return false;
		});
	});
}
/*
function cicleDrop(){
	var holder = $('.cycle');
	var _duration = 300;
	holder.each(function(){
		var $this = $(this);
		var opener = $this.find('.btn-cycle');
		var drop = $this.find('.cycle-drop');
		var dropHeight = drop.outerHeight();
		drop.css({
			height:0,
			left:0
		});
		opener.mouseenter(function(){
			drop.animate({
				height:dropHeight
			},{
				queue:false,
				duration:_duration
			});
		});
		$this.mouseleave(function(){
			drop.animate({
				height:0
			},{
				queue:false,
				duration:_duration
			});
		});
		_opt.click(function (){
			var _link = jQuery(this);
			curValue1.html(_link.find('>strong>span').html());
			curValue21.html(_link.find('>em .big').html());
			curValue22.html(_link.find('>em .small').html());
			drop.hide().css({height:0});
			return false;
		});
	});
}
*/
function cicleDrop()
{
	var holder = $('.cycle');
	var _duration = 300;
	holder.each(function(){
		var $this = $(this);
		var curValue1 = $this.find('>a>strong>span');
		var curValue21 = $this.find('>a>em .big');
		var curValue22 = $this.find('>a>em .small');
		var opener = $this.find('.btn-box');
		var drop = $this.find('.cycle-drop');
		var _opt = drop.find('a');
		var dropHeight = drop.outerHeight();
		drop.css({
			height:0,
			left:0
		});
		opener.mouseenter(function(){
			drop.animate({
				height:dropHeight
			},{
				queue:false,
				duration:_duration
			});
		});
		$this.mouseleave(function(){
			drop.animate({
				height:0
			},{
				queue:false,
				duration:_duration
			});
		});
		_opt.click(function ()
		{
			var _link = jQuery(this);
			curValue1.html(_link.find('>strong>span').html());
			curValue21.html(_link.find('>em .big').html());
			curValue22.html(_link.find('>em .small').html());
			drop.hide().css({height:0});
			
			var newValue = curValue1.html().toLowerCase().split("<em>");
			
			switch(newValue[0].trim())
			{
				case '1 month':
					$("#billing_cycle").val("1");
					break;
				case "3 month":
					$("#billing_cycle").val("3");
					break;
				case "6 month":
					$("#billing_cycle").val("6");
					break;
				case "12 month":
					$("#billing_cycle").val("12");
					break;
				case "24 month":
					$("#billing_cycle").val("24");
					break;
				case "lifetime":
					$("#billing_cycle").val("36");
					break;
			}
			
			updatePrice();			
			return false;
		});
	});
}
function initLocationTabs() {
	var _tabset = $('.location-tabset');
	_tabset.each(function(){
		var _tabsetEl = $(this).find('a');
		hideTabs();
		_tabsetEl.each(function(){
			if ($(this).parent().hasClass('active'))
			$($(this).attr('href')).show();

			$(this).click(function(){
				if (!$(this).parent().hasClass('active')) {
					hideTabs();
					_tabsetEl.parent().removeClass('active');
					$(this).parent().addClass('active');
					$($(this).attr('href')).show();
				}
				return false;
			});
		});
		
		function hideTabs() {
			_tabsetEl.each(function(){
				$($(this).attr('href')).hide();
			});
		}
	});
}
function initLocation()
{
	
	var place = $('.location-place');
	var ind = $('.location-place-ind');
	var activeClass = 'hover';
	
	place.mouseenter(function()
	{
		var curr = $(this).attr('title');
		$('.location-place[title='+curr+']').addClass(activeClass);
	}).mouseleave(function()
	{
		var curr = $(this).attr('title');
		$('.location-place[title='+curr+']').removeClass(activeClass);
	});
	
	place.click(function()
	{
		$(this).parents('.location-popup').eq(0).find('.close').trigger('click');
		ind.text($(this).attr('title'))
		updatePrice();
	});
	
}
$('document').ready(function(){
	ieHover('.package-list .holder, .locations ul li, .free-server, .demo-server, .blog-update .holder, .start-up .box, .chat-holder, .payment-method, .login, .submit','hover')
	$('.scroll-holder').crawlLine({crawElement:'.scroll-block'});
	cicleDrop();
	initLocationTabs();
	initLocation();
}); 


$("a.livechatlink").live("click", function(event)
{
	var myWindow = window.open(this.href, 'myWindow', 'width=525,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	
	_gaq.push(['_trackEvent', 'Live Chat', 'Open', 'User Opened Live Chat']);
	event.preventDefault();
});
