var flg=1;
setTimeout(clk,5000);
function clk (){
	if (flg) {
		flg=0;
		$('#menu').slideDown('slow');
	 	$('.slogan').css('cursor','default');
	}
}
function hi(id){
	$('#'+id).hide();}

function submitfrm(ref){
	
	href=$(ref).parents('form').attr('action');
	form=$(ref).parents('form').serialize();
	holder=$(ref).parents('div.holder');
	$.post(href,form,function(data){
		holder.html(data);
	});
	
	return false;
}
var fade;
var next;
var obj;
function nextslide(){
	clearTimeout(next);
	clearTimeout(fade);
	obj=0;
	tmp=$(".slide_holder");
		a=tmp.children('.slide:visible').attr('rel')*1;
		m=tmp.attr('rel')*1;
		n= a % m +1;
		
		tmp.children('.slide:visible').fadeOut();
		obj=tmp.children(".slide[rel="+n+"]");	

	if (obj) obj.fadeIn();
	next=setTimeout('nextslide()',10000);
}


	function subscribe(){
			if ($("#subscribe input[name=fullname]").val() && $("#subscribe input[name=from]").val()) {
				$.post("/runtime/subscribe/", $("#subscribe").serialize(),
				function(data) {
   					$("#subscribe").html(data);
 					} 
				);
				
			}else $(".subscribe").html("Заполните все поля"); 
		}
		
		var  sb_form='<form id="subscribe"><input type="hidden" name="go" value="1" >'+
    	'<center><div>Ваше имя</div><input name="fullname" maxlength="255" value="" class="login" type="text"><br><br>'+
    	'<div >Ваш электроный адрес</div><input name="from" maxlength="255" value="" class="login" type="text"><br><br><span class="subscribe_err"></span><br>'+
    	'<a class="submit"  href="javascript:subscribe()">Отправить</a>'+
    	'</center></form>';



var auto=1;

$(function(){
	
	$(".subscribe").click(function(){
				$.fancybox(sb_form,
				{
	        		"autoDimensions"	: false,
				"width"         		: 350,
				"height"        		: 170,
				"transitionIn"		: "none",
				"transitionOut"		: "none"
				});
				return false;
			});
	
	
	
	
	
	$('.slogan').click(function (){
		clk();
	});
$('.mainmenu a').click (function(){
					i=$(this).attr('rel');
					$('#sub'+i).show();
					$(this).parents('table').slideUp('slow');
					
					return false;
					}
				)
				.hover( function(){
							i=$(this).attr('rel');
							i=$(this).attr('rel');
							obj=$('.micon[rel="'+i+'"] img' );
							tmp=obj.attr('src');
							obj.attr('src',tmp.replace(/\.gif/,'-red.gif'));
							
						},
						function(){
							i=$(this).attr('rel');
							obj=$('.micon[rel="'+i+'"] img' );
							tmp=obj.attr('src');
							obj.attr('src',tmp.replace(/-red/,''));
							
						}
				);

		$('.back').click(function(){
			
			
			id=$(this).parents('table').attr('id');
			setTimeout("hi(id)", 500);
			$('.mainmenu').slideDown('slow');
			
			
			return false;
		});
		
		$(".cat").each(function(){
			$(this).addClass('hidden');
			$(this).before('<a href="#" class="cat_show">Подробнее</a>');
		})		
		$(".cat_show").click(function(){
			if ($(this).hasClass('cat_hide')){
				$(this).next('.cat').hide();
				$(this).removeClass('cat_hide').text('Подробнее');}
			
			else {
			$(this).next('.cat').show();
			$(this).addClass('cat_hide').text('Скрыть');}
			return false;	
		});
		
		
		$('.tab').click(function(){
	 		if (!$(this).hasClass('active')){
	 		old=$('.tab.active').attr('rel');
	 		$('.tab.active').removeClass('active');
	 		$(this).addClass('active');
	 		$('div.tab'+$(this).attr('rel')).show();
	 		$('div.tab'+old).hide();
	 		 if ($(this).attr('video') == '1'){	
	 		 	var flashvars = 
	 		 		{"comment":"http://ioffepartners.ru",
	 		 		"st":"http://www.ioffepartners.ru/js/uppod/style.txt",
	 		 		"file":"http://www.ioffepartners.ru/uploads/flv/ioffe_0"+$(this).attr('rel')+"_a.flv",
	 		 		"poster":"http://www.ioffepartners.ru/images/promo"+$(this).attr('rel')+".jpg",
	 		 		"volume":"0.3"};
	 		 	var params = {wmode:"transparent", allowFullScreen:"true", allowScriptAccess:"always",id:"videoplayer43801"}; 
	 		 	new swfobject.embedSWF("http://www.ioffepartners.ru/js/uppod/uppod.swf", 
	 		 							"videoplayer43801", "500", "280", "9.0.115.0", false, flashvars, params);
	 		 							
	 		 	
	 		 	$.scrollTo('#content',1000);
	 		 	//alert($('videoplayer43801').css('top'));
	 		 }
	 		}
	 });
	 
	 
	 if (auto) { $('.tab_holder div.tab:first').trigger('click');}	
	 
	 $(".slide_holder").each(function(){
	 	num=0;
	 	$(this).children('.slide').each(function(){
	 		num++;
	 		$(this).attr('rel',num);
	 	});
	 	$(this).attr('rel',num);
	 	
	 	$(this).children('.slide[rel=1]').fadeIn('slow');
	 	next=setTimeout('nextslide()',10000);
	 });
	 
	 $(".pre_holder").each(function(){

	 	if (parseInt($(this).find('.pre_content').height()) < parseInt($(this).find('.pre_content span').height()))
	 	$(this).append('<div class="pre_more"><a href="#" class="pre_more">подробнее</a></div>');
	 });

	$(".pre_more").click(function(){
		obj=$(this).parents('.pre_holder');		
		obj.find('.pre_more').detach();
		h=obj.find('.pre_content span').height();
		
		obj.find('.pre_content').animate({ height: h+'px'},100);
		obj.animate({ height: h+'px'},100);
		return false;
	})
	
		
});
