// JavaScript Document

	// Img width on the Woman page
	function womenBoxWidth(){
		$('.women_box_pic').each(function(){
			$(this).width( (($('#content').width() - 110)/ 3) + 'px');
		});
	}

	// Youtube Video height:
	function iframeHeight(){ $('div#column_right div.foto-video_big iframe').height($('div#column_left div.foto-video_big img').height() + 'px'); }
	
	function spreadAllWidth(jQSel, Start){
		var containerWidth = $(jQSel).parent().width();
		var totalWidth = 0;
		var n = $(jQSel).size();
		$(jQSel).css('float', 'left').each(function(){
			totalWidth += $(this).width();
		});
		if (Start == 1) { totalWidth = 598; }
		if (Start == 2) { totalWidth = 610; }

	    $(jQSel).not(':first').css('margin-left', Math.floor((containerWidth - totalWidth - 1) / (n - 1)) + 'px');
		
	}
	
	function showmail(user, site) {
		document.write('<a href="mailto:' + user + '@' + site + '">');
		document.write(user + '@' + site + '</a>');
	}	

$(document).ready(function(){
	
	//Replace news record @ first position
	var temp_item = $('.pressa_post_index').eq(2).html();
	$('.pressa_post_index').eq(2).remove();
	$('.pressa_post_index:first').before('<div class="pressa_post_index">' + temp_item + '</div>');
	
	
    $(window).resize(function(){
		womenBoxWidth();
		iframeHeight();
		spreadAllWidth('#header ul li');
		spreadAllWidth('#menu_index ul li');
	});
	
	// Original gallery 
	$("a.foto2big").click(function(){ $(".toBig").html('<img src="' + $(this).attr('name') + '">'); });
	$(".toBig").html('<img src="' + $("div:first-child a.foto2big").attr('name') + '">');
		
	$('.gallery_buttons .next').each(function(){ 
		$(this).click(function(){
			
			var currentIndex = $(this).parent().prev().find('img.this').index(); 
			var lastIndex = $(this).parent().prev().find('img:last-child').index();

			$(this).parent().prev().find('img').each(function(){ 
				if ( $(this).index() == (currentIndex) && currentIndex != lastIndex) { $(this).removeClass('this'); }
				else if ( $(this).index() == (currentIndex+1) ) { $(this).addClass('this'); }
			});
			
			lastIndex++; currentIndex+=2;
			if ( currentIndex > lastIndex ) { currentIndex = lastIndex; }
			$(this).parent().find('.gallery_pages').html( currentIndex + ' из ' + lastIndex );
			
		}); 
	});
	
	$('.gallery_buttons .prev').each(function(){ 
		$(this).click(function(){
			
			var currentIndex = $(this).parent().prev().find('img.this').index(); 
			var lastIndex = $(this).parent().prev().find('img:last-child').index();
			var firstIndex = $(this).parent().prev().find('img:first-child').index();

			$(this).parent().prev().find('img').each(function(){ 
				if ( $(this).index() == (currentIndex) && currentIndex != firstIndex) { $(this).removeClass('this'); }
				else if ( $(this).index() == (currentIndex-1) ) { $(this).addClass('this'); }
			});
			
			lastIndex++; firstIndex++;
			if ( currentIndex < firstIndex ) { currentIndex = firstIndex; }
			$(this).parent().find('.gallery_pages').html( currentIndex + ' из ' + lastIndex );
			
		}); 
	});
		
	$('.gallery_buttons .gallery_pages').each(function(){ $(this).html( ($(this).parent().prev().find('img.this').index() + 1) + ' из ' + ($(this).parent().prev().find('img:last-child').index() + 1) ); });
	
	$('.arenda_club_list > div').click(function(){
		var noneClub = $('.arenda_club_list_active').index();
		showClub = $(this).index();
		
		$('.arenda_club div.club' + showClub).removeClass('none');
		$('.arenda_club div.club' + noneClub).addClass('none');
		
		$('.arenda_club_list div.arenda_club_list_active').removeClass('arenda_club_list_active');
		$(this).addClass('arenda_club_list_active');
	});
	
	var showClub = $('.arenda_club_list').find('div.arenda_club_list_active').index();
	$('.arenda_club .club' + showClub).removeClass('none');
	
	// Index text slider
	$('div#seo_index .seo_info_index p').css('display', 'none');
	$('div#seo_index .first p').css('display', 'block');
	
	$('a.indexText').click(function(){
		if ( $(this).next().find('p').css('display') == 'block' ) {}
		else {
			$('div#seo_index .seo_info_index p').each(function(){ if ( $(this).css('display') == 'block' ) { $(this).slideToggle(200); } });
			$(this).next().find('p').slideToggle(200);
		}
	});
	
	// Hover menu
	$('#menu ul li a.active').mouseover(function(){ $(this).addClass('hoverActive'); }).mouseleave(function(){ $(this).removeClass('hoverActive'); });
	$('#menu ul li a.unactive').mouseover(function(){ $(this).addClass('hover'); }).mouseleave(function(){ $(this).removeClass('hover'); });
	$('#menu_index ul li a.unactive').mouseover(function(){ $(this).addClass('hover'); }).mouseleave(function(){ $(this).removeClass('hover'); });
	
	// Service Page
	$('.uslugi_link_index a').click(function(){
		var noneService = $('.uslugi_link_index a.uslugi_link_index_active').index();
		var showService = $(this).index();

		$('.uslugi_link_about div.service' + noneService).removeClass('this');
		$('.uslugi_link_about div.service' + showService).addClass('this');
		
		$('.uslugi_link_index a.uslugi_link_index_active').removeClass('uslugi_link_index_active');
		$(this).addClass('uslugi_link_index_active');
	});
		
	
	// Init functions
	if ( $('#menu').attr('class') == 'iPhone' ) { spreadAllWidth('#menu ul li', 2); }
	else { spreadAllWidth('#menu ul li', 1); }
	
	if ( $('#menu_index').attr('class') == 'iPhone' ) { spreadAllWidth('#menu_index ul li', 2); }
	else { spreadAllWidth('#menu_index ul li', 1); }
	womenBoxWidth();

	// Init some effects
	$('div#column_right div.foto-video_big iframe').height( ((($('#content').width() / 2) - 40) / 1.6404) + 'px');
	$('.uslugi_link_about div.on').addClass('this').removeClass('on');
	$('.uslugi_link_index a.on').addClass('uslugi_link_index_active').removeClass('on');
	
});

