jQuery(function() {

	/* --- CUFON start --- */
	
	Cufon( '.cufon-bold', { fontFamily: 'Myriad Pro Bold' } );
	Cufon( '.cufon-reg', { fontFamily: 'Myriad Pro Regular' } );
	Cufon( 'table thead th, table thead td, table tr.subtitle td', { fontFamily: 'Myriad Pro Regular' } );
	
	/* --- CUFON end --- */
	
	/* --- MAP SETTINGS start --- */
	
	var mapZoom = 14;
	
	var miniMap = true;
	var miniMapValue = 3;
	var mapZoomControl = true;
	
	var iconUrl = 'http://hostink.ru/images/map_icon.png'; /* <<<<<------ */
	
	var balloonName = '<h3 id="map-balloon-title" class="cufon-bold">HOST<b>INK</b></h3>';
	var balloonDescr = '<div id="map-balloon-descr"><p>Москва, ул. Большая Полянка, д. 44/2</p><p>тел.: 8 800 505 4678</p></div>';

	/* --- MAP SETTINGS end --- */
	
	/* --- Homepage HOSTING PLANS start --- */
	
	jQuery('#hosting-plans .plan').hover(function(){
		jQuery('#hosting-plans .plan').removeClass('selected');
		jQuery(this).addClass('selected');
	});
	
	/* --- Homepage HOSTING PLANS end --- */
	
	/* --- Homepage FEATURES STYLE start --- */
	
	var features_height = parseInt(jQuery('#features-content').css('height')) + parseInt(jQuery('#features-content').css('paddingTop')) + parseInt(jQuery('#features-content').css('paddingBottom'));
	var corner_height = (features_height / 2) - 39;
	var features_corners = '<div class="corner tl"></div><div class="corner tr"></div><div class="corner br"></div><div class="corner bl"></div>';
	var features_holes = '<div class="hole hole-left"></div><div class="hole hole-right"></div>';
	jQuery('#features-content').css({ 'border-radius':0, '-moz-border-radius':0, '-webkit-border-radius':0 });
	jQuery('#features').prepend(features_corners).prepend(features_holes);
	jQuery('.corner').css('height', corner_height);
	
	jQuery('table.striped').each(function(){
		var cols = jQuery(this).find('thead tr').find('td').length;
		var td_width = (100 - 20) / cols;
		jQuery(this).find('thead tr').find('td').css('width', td_width + '%');
		jQuery(this).find('tr').find('td:even').addClass('odd');
		jQuery('table tr.subtitle').prev('tr').addClass('noborder');	
	});
	
	/* --- Homepage FEATURES STYLE start --- */

	/* --- LOGIN FORM STYLE start --- */
	
	jQuery('#login-form input').val('');
	
	jQuery('#login-form input').live('focus', function(){
		label = jQuery(this).siblings('label');
		if(label.is(':visible')){
			label.fadeOut('fast');
		}
	});
	
	jQuery('#login-form input').live('blur', function(){
		label = jQuery(this).siblings('label');
		if(!(jQuery(this).val().length)){
			label.fadeIn('fast');
		}
	});
	
	jQuery('.submit').live('click', function(){
		jQuery(this).closest('form').submit();
	});
	
	/* --- LOGIN FORM STYLE end --- */
	
	/* --- MODAL LOGIN start --- */
	
	jQuery('#login-link').colorbox({
		inline:true,
		href:'#modal-login',
		onOpen: function(){ jQuery('#cboxContent').prepend('<div class="icon icon-lock"></div>'); },
		onClosed: function(){
			jQuery('#cboxContent').find('.icon').remove();
		}
	});
	
	/* --- MODAL LOGIN end --- */
	
	/* --- MODAL MAP start --- */
	
	jQuery('#map-link').colorbox({
		inline:true,
		href:'#modal-map',
		onOpen: function(){
			jQuery('#cboxContent').prepend('<div class="icon icon-marker"></div>');
		},
		onComplete: function(){
			
			var iconWidth = 54;
			var iconHeight = 79;
			var iconOffsetX = -27;
			var iconOffsetY = -79;
			
			var balloonPadding = 24;
			var balloonTailHeight = 26;
				
			function hostinkBalloonLayout() {
				this.element = YMaps.jQuery( '<div id="map-balloon"><div id="map-balloon-content" class="content"></div><div id="map-balloon-close"></div><div id="map-balloon-tail"></div></div>');

				this.close = this.element.find('#map-balloon-close');
				this.content = this.element.find('#map-balloon-content');
				this.disableClose = function(){ this.close.unbind("click").css("display", "none"); };
				this.enableClose = function(callback){
					this.close.bind("click", callback).css("display", "");
					return false;
				};
				this.onAddToParent = function (parentNode) {
					YMaps.jQuery(parentNode).append(this.element);
					this.element.css('marginTop', '-' + (this.content.height() + balloonTailHeight + balloonPadding * 2 ) + 'px').css('marginLeft', '-' + ((this.content.width() + balloonPadding * 2) / 2) + 'px');
				};
				this.onRemoveFromParent = function () { this.element.remove(); };
				this.setContent = function (content) { content.onAddToParent(this.content[0]); };
				this.update = function() {
					this.element.css('marginTop', '-' + (this.content.height() + balloonTailHeight + balloonPadding * 2 ) + 'px').css('marginLeft', '-' + ((this.content.width() + balloonPadding * 2) / 2) + 'px'); 
				};
			}
			var hostinkBalloonTemplate = new YMaps.LayoutTemplate(hostinkBalloonLayout);
				var style = new YMaps.Style();
					
			style.iconStyle = new YMaps.IconStyle();
			style.iconStyle.href = iconUrl;
			style.iconStyle.size = new YMaps.Point(iconWidth, iconHeight);
			style.iconStyle.offset = new YMaps.Point(iconOffsetX, iconOffsetY);

			style.balloonStyle = { template: hostinkBalloonTemplate };
			
			var placemark = new YMaps.Placemark(new YMaps.GeoPoint(37.619414,55.732408), {style: style});
			var map = new YMaps.Map(YMaps.jQuery("#map")[0]);
			map.setCenter(new YMaps.GeoPoint(37.619414,55.733), mapZoom);
			placemark.name = balloonName;
			placemark.description = balloonDescr;
			map.addOverlay(placemark);
			
			if(miniMap){
				var miniMapPositive = new YMaps.MiniMap(miniMapValue);
				map.addControl(miniMapPositive);
			}
			
			if(mapZoomControl){
				var zoomControl = new YMaps.SmallZoom({noTips: true});
				map.addControl(zoomControl);
			}
			
			YMaps.Events.observe(map, map.Events.BalloonOpen, function(){
				Cufon.refresh();
			});
		},
		onClosed: function(){
			jQuery('#cboxContent').find('.icon').remove();
		}
	});
	
	/* --- MODAL MAP end --- */
	
	jQuery('.image-modal').colorbox({
		top: '2%',
		onOpen: function(){ jQuery('#cboxContent').prepend('<div class="icon icon-medal"></div>'); },
		onClosed: function(){
			jQuery('#cboxContent').find('.icon').remove();
		}
	});
	
	/* --- TOGGLE start --- */
	
	jQuery('.fade-toggle').toggle(function(){
		jQuery(this).addClass('expanded');
		var target = jQuery(this).attr('rel');
		jQuery('#' + target).fadeIn('fast');
	}, function(){
		jQuery(this).removeClass('expanded');
		var target = jQuery(this).attr('rel');
		jQuery('#' + target).fadeOut('fast');
	});
	
	jQuery('.slide-toggle').toggle(function(){
		var target = jQuery(this).attr('rel');
		jQuery('#' + target).slideDown('slow');
	}, function(){
		var target = jQuery(this).attr('rel');
		jQuery('#' + target).slideUp('slow');
	});
	
	/* --- TOGGLE end --- */
	
	/* --- About BUTTON CODE start --- */
	
	jQuery('#button-code').bind('click', function(){
		jQuery(this).select();
	});
	
	/* --- About BUTTON CODE end --- */
	
});

jQuery(document).ready(function(){

	var toc = '';
	
	jQuery('.vocabulary .copy').find('.item').each(function(){
		
		jQuery(this).prepend('<a href="#" class="small scroll-top">Наверх</a>');
		
		var title = jQuery(this).find('h3')
		var term = title.text();
		var id = title.attr('id');
		
		toc += '<li><a href="#' + id + '">' + term + '</a></li>';	
		
	});
	
	if(toc.length){
		toc = '<div id="table-of-contents" class="right"><h4 class="cufon-reg">Содержание</h4><ul>' + toc + '</ul></div>';
		jQuery('.vocabulary .copy').addClass('clearfix').prepend(toc);
	}
	
	jQuery('.vocabulary .copy .item').hover(function(){
		jQuery(this).addClass('hover');
	}, function(){
		jQuery(this).removeClass('hover');
	});
	
	jQuery('#full-list ul li:nth-child(4n+1)').addClass('first');

});


