/*TopPage*/
$(document).ready(function() {
	$('a#toptop').click(function(){
	$('html, body').animate({scrollTop:0}, 'slow');
	return false;
	});
});

/* Height #btags */
$(document).ready(function(){
    $('#btags').css("margin-top", -$('#btags').height());
	$('#mcontent').css("padding-bottom", $('#btags').height());
});

/* Upload line */
$(function(){
	var h=0;
		$("#lineimgs").find("li").each(function(){
		h+=$(this).width();
	}).end().width(h);
});


/*LoginBtns*/
$(document).ready(function(){
	$('#loginbtns .ilbtn a').hover(
		function() {
			$('#loginbtns .ilbtn a').removeClass("selected");
		},
		function() {
			$(this).addClass("selected");
		}
	);
});

/* VertMenu */
$.fn.UlMenu=function() {
	$.each(this,function(){
	$("li.submenu",this).hide();
		$("li:has(.sublnk)",this).click(function(){
			$(this).toggleClass("selected").next("li.submenu").slideToggle(300).css("display",function(){
					if($(this).css("display")=="list-item")
				return "block";
			});
		});
	}); return this;
}

/*LoginClientDialog*/
$(function() {
	$( '#dialogclient' ).dialog({
		autoOpen: false,
		width: 300
	});

	$('#loginclient').click(function(){
		$('#dialogclient').dialog('open');
		return false;
	});
});

/*LoginUserDialog*/
$(function() {
	$( '#dialoguser' ).dialog({
		autoOpen: false,
		width: 300
	});

	$('#loginuser').click(function(){
		$('#dialoguser').dialog('open');
		return false;
	});
});

/*PollDialog*/
$(function() {
	$( "#polldialog" ).dialog({
		autoOpen: false,
		width: 450
	});

	$('#polllink a').click(function(){
		$('#polldialog').dialog('open');
		return false;
	});
});

/* Slidedown */
$.fn.Button=function(sel)
{
	var closed=true,
		th=this;
	$(sel).hide();
	$(this).removeClass('selected').click(function(){
		$(sel).slideToggle("slow");
		$(this).toggleClass("selected");
		closed=!closed;
		return false;
	});
	$(document).click(function(e){
		if(closed)
			return;
		var target=e.target||e.srcElement;
		while(target)
		{
			var ret=false;
			$(sel).each(function(){
				if(ret=target==this)
					return false;
			});
			if(ret)
				return;
			target=target.parentNode;
		}
		$(sel).hide('slow');
		$(th).removeClass('selected');
		closed=true;
	});
	return this;
}

/* Tabs */
$(document).ready(function(){
	var tabContainers = $('#tabbs .tabcont');
		tabContainers.hide().filter(':first').show();
								
		$('#tabbs .tabmenu a').click(function () {
			tabContainers.hide();
			tabContainers.filter(this.hash).show();
			$('#tabbs .tabmenu a').removeClass('selected');
			$(this).addClass('selected');
			return false;
		}).filter(':first').click();
});

/* Favorites */
function addBookmark(title, url) {
	if (document.all)
		window.external.AddFavorite(url,title);
	else
		window.sidebar.addPanel(title,url,'');
}
