var number = -1;
function Like(type){
	if(type=='l'){//If show only text, hide all images
		$("#list",this).css("display","block");
		$("#images",this).css("display","none");
		$("#hall",this).css("display","none");
		InitContainer('list');
	}else if(type=='i'){//If show only images, hide all strings
		$("#list",this).css("display","none");
		$("#images",this).css("display","block");
		$("#hall",this).css("display","none");
		
	}else if(type=='h'){
		$("#list",this).css("display","none");
		$("#images",this).css("display","none");
		
		var hall = $("#hall");
		if(hall.html()==''){
			hall.html($("#list").clone().html());
			$("div.container",hall).each(function(){
				var date = $('h3.date',this).clone();
				var out = '';
				var red = $("div._2",this).each(
					function(){out += $(this).html();}
				);
				out += '<br />';
				var green = $("div._1",this).each(
					function(){out += $(this).html();}
				);
				$(this).html(out);
				date.prependTo($(this));
			});
		}
		$("#hall",this).css("display","block");
		InitContainer('hall');
	}else return;
	$("#icons>div").css("backgroundPosition","0 -31px");
	$("#icons>div."+type).css("backgroundPosition","0 0px");
}

/* Show info block
* @n int number of current block	
* @visible bool show or hide flag 
*/
var detail;
//var pos;
function Info(e,container,id,visible){
	if(container.nodeName=='IMG')
		mode = 0;
	else
		mode = 1;
	if(mode==1 && e.type == 'mousemove'){
		if(visible==1){
			var x = e.pageX==undefined?e.x:e.pageX;
			if(detail)
			detail.css({"left":x+20, 'padding':'10px'});
			return;
		}
	}
	
	if(number>-1 && visible!=0){
		Info(e,container,number,0);
	}
	
	if(mode==0){//Image	
		detail= $("#_d"+id);
		if(visible==1){
			
			if(detail.css("visibility")=='visible') return;

			var pos = $(container).offset();
			var y = pos.top+pos.scrollTop-10;
			var x = pos.left+pos.scrollLeft-10;
			
			detail.mouseout(function(e){
				var p = detail.offset();
				var y = pos.top+pos.scrollTop-10;
				var x = pos.left+pos.scrollLeft-10;
				
				if((e.pageX>x && e.pageX<(x+detail.outerWidth())) && (e.pageY>y && e.pageY<(y+detail.outerHeight())))
					return;
				else
					Info(e,container,id,0);
					return;
			});
			detail.css({"top":y+'px', "left":x+'px', 'padding':'10px'});
			detail.css("visibility","visible"); 
		}else{
			if(detail.css("visibility")!='visible') return;
			detail.css("visibility","hidden");
			detail.unbind();
			number = -1;
		}
	}else if(mode==1){ //Text
		
		//if(typeof(e)=='undefined')var e=window.event
	
		detail= $("#_d"+id);
		if(visible==1){
			
			var pos = $(container).offset();

			if(detail.css("visibility")=='visible') return;
			var y = e.pageY==undefined?pos.top:e.pageY;
			var x = e.pageX==undefined?e.x:e.pageX;
	
			detail.css({"top":y-20, "left":x+20, 'padding':'10px'});
			detail.css("visibility","visible"); 
			
		}else{
			if(detail.css("visibility")!='visible') return;
			detail.css("visibility","hidden");
			number = -1;
		}
	
	}
	number = id;
}
if($.blockUI){
	$.extend($.blockUI.defaults.pageMessageCSS, { color: '#fff', backgroundColor: '#2C3A3D' });
}
function Details(id){
	$.blockUI('<br /><h3 style="color:#fff"><img src="/i/Image/site/busy.gif" /> Секунду...</h3><br />');	
	var url = location.protocol+'//'+document.domain+'?'+'ajax=yes&name=Films&fid='+id;
	ImageArray = Array();
	$.post(url, '', function(e){
		onResponse(e);
	});
	
}
$().ajaxStop($.unblockUI); 
function onResponse(e){
	$('#_film').html(e);
	initStar();
	initTrailer();
}; 

//Инициализация трейлера
function initTrailer(){
	var tr = $('#trailer').attr("rel");
	if(tr){
		var so = new SWFObject("/i/Flash/header.swf", "trailer", "100%","260", "8", "#000000");
		so.addVariable("link_to_menu", tr);
		so.addParam("wmode", "opaque");
		so.write("trailer");
	}
}

//Смена табов
function tab(o,id){
	$('#tabs>div').removeClass();
	$('#tab_content>div').removeClass();
	$(o).addClass('on');
	$('#'+id).addClass('current');
}
/*
function InitContainer(id){
	var max = 0
	var divs = $('#'+id+'>div.container');
	var top = 0;
	var n=0;
	divs.each(function(i){
		var o = $(this);
		top = i==0?o.offset().top:top;
		var h = o.height();
		max=max<h?h:max;
		if(o.offset().top>top){
			for(k=i-1;k>n;k--)
				divs.eq(k).css('height',max+10+'px');
			n=i; max=0;
		}
	});
	for(k=divs.length-1;k<n;k--){
		divs.eq(k).css('height',max+'px');
	}
	divs.eq(divs.length-1).css('height','auto');
}
*/
function InitContainer(id){
	var max, h;
	var divs = $('#'+id+'>div.container');
	var i, j, j1, row = 0;
	var o = divs.eq(0).offset().top;
	for (i = 1; i < divs.length - 1; i++ ) {
		if ( o != divs.eq(i).offset().top ) {
			row = i;
			break;
		}
	}
	j = 0;
	//while ( j < 7 ) {
		max = 0;
		j1 = j;
		for (i = 0; i < row; i++) {
			if ( j >= 7 ) break;			
			h = divs.eq(j).height();
			max=max<h?h:max;
			j++;
		}		
		for (i = 0; i < row; i++) {
			if ( j1 >= 7 ) break;			
			divs.eq(j1).css('height',max+'px');
			j1++;
		}
        
	//}
}
window.onload = function(){InitContainer('list');}
