var layoutDocsPath = "/sberbank/annual/2010/gb/layout/img";
var language;
var lang = new Object();
lang["Russian"] = new Array("Ваш сбор","В Вашем сборе нет файлов.","добавить файл","Файл добавлен в сбор.",'Их отдельные загрузки PDF из уже хранится содержимое см. <a href="###" title="Link в Мой Geschäftsbericht"> "Мой доклад" </ A>.');
lang["English"] = new Array("Your collection","There are no files in your download collection.","Add file","File added to the download collection",'Your individual PDF download of already stored content can be found under <a href="###" title="Link to My annual Report">"My annual report"</a>');

function changeDownloadType(event){
	$(event.target).parentsUntil(".tabs").parent().find(".tabHeading").toggleClass("tabHeadingActive");
	$(event.target).parentsUntil(".tabs").parent().find(".tabContent").toggleClass("tabContentActive");
}

function toggleDownloadList(event){
	$(event.target).parent().parent().find(".tabContent .downloadItems").toggle("slide",{ direction: "up" },200);
	//window.setTimeout("positionFooter()",200);
	$(event.target).toggleClass("active");
}

var footerTimeout;
function positionFooter(){
	$("#contentFooter").css({position: "absolute", bottom: "0px"});
}

function addDownloadItem(event){
	$("#noDownloads").parent().css("display","none")
	var itemId = $(event.target).attr("class").split(" ")[0];
	$(".warenkorbContent table").append(
			'<tr>' + 
				'<td>' + $(event.target).parent().parent().find(".downloadName").text() + '</td>' +
				'<td class="type">' + $(event.target).parent().parent().find(".downloadItem").text() + '</td>' + 
				'<td class="removeItem"><img src="'+layoutDocsPath+'/icon_remove.png" alt="X" class="' + itemId + ' removeItem" /></td>' +
			'</tr>');
	$(".warenkorbContent ." + itemId).bind("click",removeDownloadItem);
	$(event.target).attr("src",layoutDocsPath+"/icon_downloadAdded.png").attr("alt",lang[language][3]).attr("title",lang[language][3]).unbind("click",addDownloadItem).css("cursor","auto");
	$("#" + itemId).attr("checked","true");
	$(".warenkorbContent .noBorder").removeClass("noBorder");
	$(".warenkorbContent table tr:last-child").addClass("noBorder");
}

function removeDownloadItem(event){
	var itemId = $(event.target).attr("class").split(" ")[0];
	$(".warenkorbContent ." + itemId).unbind("click",removeDownloadItem);
	$(".warenkorbContent ." + itemId).parent().parent().remove();
	$("." + itemId).attr("src",layoutDocsPath+"/icon_addDownload.png").attr("alt",lang[language][2]).attr("title",lang[language][2]).bind("click",addDownloadItem).css("cursor","pointer");
	$("#" + itemId).attr("checked","");
	if($(".warenkorbContent tbody").children().length==1){
		$("#noDownloads").parent().css("display","");
	}
	else{
		$(".warenkorbContent .noBorder").removeClass("noBorder");
		$(".warenkorbContent table tr:last-child").addClass("noBorder");
	}
}

function showAll(){
	$(".downloadItems").show("slide",{ direction: "up" },200);
}

$(document).ready(function(){
	if(navigator.appVersion.indexOf("MSIE 6")==-1){
		language = $(document).attr("URL").replace(/.*?\/((Russian)|(English))\/.+/,"$1");
		if(!language.match(/(Russian)|(English)/)) language="Russian";
		$("#jsDownloadCenter").prepend('<div class="warenkorb"><h2>'+lang[language][0]+'</h2><div class="warenkorbContent"><table><tr><td colspan="3" id="noDownloads">'+lang[language][1]+'</td></tr></table></div></div><div class="warenkorbDownload"><a href="#" id="warenkorb_submit_link">'+$("#warenkorb_submit").val()+'</a></div>');
		$(".headingLink").wrapInner("<span />");
		$(".headingLink span").unwrap();
		$(".downloadAdd input[type=checkbox]").css("display","none").after(function(){return '<img src="'+layoutDocsPath+'/icon_addDownload.png" alt="'+lang[language][2]+'" title="'+lang[language][2]+'" class="'+$(this).attr("id")+' addItem"/>';});
		$("#warenkorb_submit").remove();
		$("#warenkorb_zip input[type=checkbox]").attr("checked","");
		$(".tabHeading").bind("click",changeDownloadType);
		$(".tabsHeading h2").bind("click",toggleDownloadList);
		$(".addItem").bind("click",addDownloadItem);
		$("#warenkorb_submit_link").bind("click",function(){ $("#warenkorb_zip").submit(); });
		$("#showall").bind("click",showAll).click();
		//$(".tabContent.default").parent().parent().find(".tabsHeading h2").click();
		if($("#jsDownloadCenter").length>0){
			$("#contentFooter").css({position: "static"});
			$("#content").css({ paddingBottom: "0px"});
		}
	}
});