var active_script = false;
var animtime;
var curID = '';

function initScripts()
{
	$('ul.quest').click(function(e)
	{
		var $par_li = $(e.target).parent();
		if ($par_li.hasClass('hide_a'))
	    {
	    	$old_li = $('ul.quest li.show_a');
	    	
			$old_li.find('ul').slideUp('slow', function(){
				$old_li.addClass('hide_a');
	    		$old_li.removeClass('show_a');
			});
  			
	    	$par_li.find('ul').slideDown('slow', function(){
	    		$par_li.addClass('show_a');
	    		$par_li.removeClass('hide_a');
			});
	    }
	}
	);
	active_script = true;
};

function initGallery()
{
	$(".slider_block2").jCarouselLite({
	    btnNext: ".next",
	    btnPrev: ".prev"
	});
	$("a.gal_images").fancybox();
};

function anim_mol(arrInd, Iter, Ind)
{
	switch (arrInd)
	{
		case 1:
			arr = new Array('mol_anim1', 'mol_anim2', 'mol_anim3', 'mol_anim4', 'mol_anim5', 'mol_anim6');
			 break;
		case 2:
			arr = new Array('mol_anim6', 'mol_anim7', 'mol_anim8', 'mol_anim9', 'mol_anim10', 'mol_anim11');
			 break;
		case 3:
			arr = new Array('mol_anim11', 'mol_anim12', 'mol_anim13', 'mol_anim14', 'mol_anim15', 'mol_anim1');
			 break;
		default:
			 break;
	}
	clearTimeout(animtime);
	animtime = setTimeout(function()
	{
		if ( ((Iter > 0) && (Ind >= 5)) ||
			((Iter < 0) && (Ind <= 0)) )
		{
			$big_text.removeClass('hide');
			$small_mol1.removeClass('hide');
			$small_mol2.removeClass('hide');
			$(curID).toggleClass('hide');
			return;
		}
		$('.molecula').addClass(arr[Ind + Iter]);
		$('.molecula').removeClass(arr[Ind]);
		anim_mol(arrInd, Iter, Ind + Iter);
	}, 70);
}

function show_info(id)
{
	if (!active_script)
		return;
	if ($('#' + id + '_mol').hasClass('big_text'))
		$('#' + id + '_info').toggleClass('hide');
	else
	{
		$('#erg_info').addClass('hide');
		$('#eko_info').addClass('hide');
		$('#evo_info').addClass('hide');
		
		id_class = $('#' + id + '_mol').attr('class');
		$big_text = $('.big_text');
		$small_mol1 = $('.small_mol1');
		$small_mol2 = $('.small_mol2');
		
		$big_text.addClass('hide');
		$small_mol1.addClass('hide');
		$small_mol2.addClass('hide');
		
		curID = '#' + id + '_info';
		if (id_class == 'small_mol1')
		{
			if (id == "eko")
				anim_mol(1, 1 , 0);
			else if (id == "evo")
				anim_mol(2, 1 , 0);
			else if (id == "erg")
				anim_mol(3, 1 , 0);
			$big_text.removeClass('big_text');
			$big_text.addClass('small_mol2');
			
			$small_mol1.removeClass('small_mol1');
			$small_mol1.addClass('big_text');
			
			$small_mol2.removeClass('small_mol2');
			$small_mol2.addClass('small_mol1');
		}
		else if (id_class == 'small_mol2')
		{
			if (id == "eko")
				anim_mol(2, -1 , 5);
			else if (id == "evo")
				anim_mol(3, -1 , 5);
			else if (id == "erg")
				anim_mol(1, -1 , 5);
			$big_text.removeClass('big_text');
			$big_text.addClass('small_mol1');
			
			$small_mol1.removeClass('small_mol1');
			$small_mol1.addClass('small_mol2');
			
			$small_mol2.removeClass('small_mol2');
			$small_mol2.addClass('big_text');
		}
	}
};

function search_keydown(event)
{
	if(event.keyCode == 13)
		$("#search_form").submit();
}

function initVideo()
{
	$("div.video_block img").each(function(){
		var video = $(this).parent().find('input').val();
		var image = "/images/video.jpg";
		$(this).fancybox({
			'titleShow' : false,
			'autoScale' : false,
			transitionIn : 'elastic',
			transitionOut : 'elastic',
			overlayOpacity : 0.1,
			'type' : 'swf',
			'backcolor' : '0xffffff',
			'href' : '/scripts/player-viral.swf?autostart=true',
			swf:
			{
				flashvars: "file=" + video + "&image=" + image,
				allowfullscreen: 'true',
				autostart: 'true'
			}
		});
	})
}
function initPhoto()
{
	$("div.video_block img").each(function(){
		var video = $(this).parent('a').attr('href');
		var image = "/images/video.jpg";
		$(this).fancybox({
			'titleShow' : false,
			'autoScale' : true,
			'hideOnContentClick' : true,
			transitionIn : 'elastic',
			transitionOut : 'elastic',
			overlayOpacity : 0.1,
			
			'backcolor' : '0xffffff',
			'href' : video,
			
		});
	})
}
