var fnt=200;
var active=0;
var prevObj;
	
$(document).ready(function(){
	resetTabs();
	dataCell();
	 $(".selectBlock").bind('click', function () {
										   
				var prevObj=$(this);
				var x=$(this).find('div.solution-info').children('p');
				if(x.text().length>0 && $(this).hasClass('active-tab')&&cursor_default($(this))){
					resetTabs();
					highlight($(this));	
					$(this).removeClass('active-tab')
					x.text('');
					$(this).find('div.arrow').addClass('shopcartsdown');
					$(this).find('div.arrow').removeClass('shopcarts');
					$(this).find('div.showpanel').show();
					$(this).find('a.collapsAll').show();
					$(this).attr('id','');/*id=bl*/
					$(this).parent().siblings('.bmg_portlet_title_container').attr('id',''); /*id=topLeft*/
				}
				else{ 
					if(active) $(this).addClass('active-tab');
					active=0; 
				}
		
    });
	$('a.collapsAll').click(function(){ 
			var s=$(this).parents('div.selectBlock');						 
			resetTabs();
			closeAll('.selectBlock');
			dataCell();
			$('div.shopcartsdown').each(function(){$(this).addClass('shopcarts').removeClass('shopcartsdown'); });
			$(this).parents('div.selectBlock').removeClass('active-tab');	
			singleSelect(s);
	});	
	
	$('a.tabs').bind('click',function(){ 						
			var s=$(this).parents('div.selectBlock');
			singleSelect(s);
	});
	
	$('div.arrow').bind('click',function(){ 
			var s=$(this).parents('div.selectBlock'); 
			singleSelect(s);
	});
});

function singleSelect(s)
{
	$('a.collapsAll',s).hide();
	$('div.showpanel',s).hide(); 
	$('div.shopcartsdown',s).addClass('shopcarts').removeClass('shopcartsdown');
	var dt=$('td.dataCell',s).text().substring(0,fnt)+'...';
	$('div.solution-info',s).children('p').text(dt);
	active=1;
	cursor_pointer(s);
	s.attr('id','bl');  /*id=bl*/
	s.parent().siblings('.bmg_portlet_title_container').attr('id','topLeft'); /*id=topLeft*/
}

function cursor_default(crs)
{
	if($(crs).css('cursor')=='pointer'){	
		$(crs).css('cursor','auto');
		return true;
	} else return false;
}
function cursor_pointer(crs)
{
	if($(crs).css('cursor')=='auto'){	
		$(crs).css('cursor','pointer');
	}
}	
function closeme(c){ 
		$('a.collapsAll',$(c)).hide();
		$('div.showpanel',$(c)).hide(); 
		$('div.shopcartsdown',$(c)).addClass('shopcarts').removeClass('shopcartsdown');
		$('div.solution-info > p',$(c)).text($('td.dataCell',$(c)).text().substring(0,fnt)+'...');
		highlight(c);
		}
function closeAll(x)
{  
				$(x).find('div.showpanel').hide();
				$(x).find('a.collapsAll').hide();
				//highlight(x);
				$(x).attr('id','bl');/*id=bl*/
				$(x).parent().siblings('.bmg_portlet_title_container').attr('id','topLeft'); /*id=topLeft*/
}

function highlight(x)
{
	$(x).parents("div.bmg_theme_action_call_wht3").each(function(i){
					if(i==0)$(this).addClass('bmg_theme_action_calls_wht3').removeClass('bmg_theme_action_call_wht3').removeClass('bmg_theme_action_call_sln'); });
				 $(x).parents("div.bmg_portlet_container").each(function(i){
					if(i==0)$(this).addClass('bmg_portlet_container_sln').removeClass('bmg_portlet_container'); 
					
	});
}
function resetTabs()
{  
	$('div.bmg_theme_action_calls_wht3').each(function(){ $(this).addClass('bmg_theme_action_call_wht3').addClass('bmg_theme_action_call_sln').removeClass('bmg_theme_action_calls_wht3'); });
	$('div.bmg_portlet_container_sln').each(function(){ $(this).addClass('bmg_portlet_container').removeClass('bmg_portlet_container_sln'); });
}
function dataCell()
{
	$('.selectBlock').each(function(i){ 											  
		$(this).addClass('active-tab');
		var data= $('td.dataCell',$(this)).text();	
		$('div.solution-info > p',$(this)).text(data.substring(0,fnt)+'...'); 
		cursor_pointer($(this));
	});
}
