/* SVN: $Id: common.js 34 2011-03-08 09:24:59Z brother79 $*/
var ui;
var template;

(function($){

	ui = { 
	    setParam: function(name, value){
			$.ajax({dataType:'json', type:'GET', url:app.url_param, data: name+'='+value});
	    },
		hideLeft : function(){
			$('#bb_hl').hide();
			$('#left_column').animate({width: 'toggle'}, 300, function(){
			$('#bb_sl').show();
				$('#content0').css('margin-left','0px');							
			});
		},
		showLeft : function(){
			$('#bb_sl').hide();
			$('#left_column').animate({width: 'toggle'}, 300, function(){
			$('#bb_hl').show();
				$('#content0').css('margin-left','162px');							
			});
		},
		hideTop : function(){
			$('#bb_ht').hide();
			$('#top_column').animate({height: 'toggle'}, 300, function(){
			$('#bb_st').show();
				$('#content0').css('margin-top','0px');
				$('#left_column, #right_column').css('top', '9px') ;
			
			$('#bb_hl').css('top',202);
			$('#bb_sl').css('top',202);
			$('#bb_hr').css('top',202);
			$('#bb_sr').css('top',202);
			});
			
			
		},
		showTop : function(){
			$('#bb_st').hide();
			$('#top_column').animate({height: 'toggle'}, 300, function(){
			$('#bb_ht').show();
				$('#content0').css('margin-top','150px');			
				$('#left_column, #right_column').css('top', '159px') ;
			$('#bb_hl').css('top',350);
			$('#bb_sl').css('top',350);
			$('#bb_hr').css('top',350);
			$('#bb_sr').css('top',350);
			});
			
		},
		hideRight : function(){
			$('#bb_hr').hide();
			$('#right_column').animate({width: 'toggle'}, 300, function(){
			$('#bb_sr').show();
				$('#content0').css('margin-right','0px');							
			});
		},
		showRight : function(){
			$('#bb_sr').hide();
			$('#right_column').animate({width: 'toggle'}, 300, function(){
			$('#bb_hr').show();
				$('#content0').css('margin-right','268px');							
			});
		},
		init_bb:function(s){
			$(s).hover(function(){
				$(this).css('background-position','33.5% top');
			},function(){
				$(this).css('background-position','left top');
			})
			.mousedown(function(){
				$(this).css('background-position','67% top');			
			}).
			mouseup(function(){
				$(this).css('background-position','33.5% top');
			});					
		},
		init:function(){
			this.init_bb('[id^=bb_], .but');
			$('#bb_ht').click(function(){ui.hideTop();ui.setParam('ht', 1);});
			$('#bb_st').click(function(){ui.showTop();ui.setParam('ht', 0);});
			$('#bb_hl').click(function(){ui.hideLeft();ui.setParam('hl', 1);});
			$('#bb_sl').click(function(){ui.showLeft();ui.setParam('hl', 0);});
			$('#bb_hr').click(function(){ui.hideRight();ui.setParam('hr', 1);});
			$('#bb_sr').click(function(){ui.showRight();ui.setParam('ht', 0);});			
			
			$('[href^=#js]').click(function(){$.ajax({dataType:'script',type:'GET',url:$(this).attr('href').substr(4)});});
			
			$('[href=#captcha]').live('click', function(){
				var a=$(this);
				$.ajax({dataType:'json', type:'GET', data:{r:1}, url:'/user-captcha.html', success:function(data){
					if (data.result) {a.html(h.img({src:'/user-captcha.html?t='+data.t}));};
				}});								
				return false;
			});			
		}
	};
	
	$(function(){
		$.ajaxSetup({
			type: "GET",
			beforeSend:function(){$('#indicator').show();},
			complete: function(){$('#indicator').hide();}				
		});

		$('li.add_book a').click(function(){
			addbookmarkA(app.url, document.title);
			return false;
		});

		$('.kurs-link').click(function(){
			document.location='/kurs.html';
			return false;
		}).css('cursor','pointer');
	});
})(jQuery);

function addbookmarkA(burl, btitle)
{
	if (window.sidebar) { 
		window.sidebar.addPanel(btitle, burl,"");
	} else if (document.all) { 
		window.external.AddFavorite(burl, btitle);
	} else if ( window.opera && window.print ) { 
		return true; 
	}
}


