var upload_callback_element;
var add_child_counter = 0;


function open_window(w,h,ziel) {
  h = h - 20; var x=0, y=0, parameter="";
  if (w < screen.availWidth || h < screen.availHeight) {
    x = (screen.availWidth - w - 12) / 2;
    y = (screen.availHeight - h - 104) / 2;
    if (window.opera) y = 0; // Opera positioniert unter den Symbolleisten
    if (x<0 || y<0) { x=0; y=0; }
    else parameter = "width=" + w + ",height=" + h + ",";
  }
  parameter += "left=" + x + ",top=" + y;
  parameter += ",menubar=yes,location=yes,toolbar=no,status=no";
  parameter += ",resizable=yes,scrollbars=yes";
  var Fenster = window.open(ziel,"PopUp",parameter);
  if (Fenster) Fenster.focus();
  return !Fenster;
}


function upload_image_callback_quality_icon(filePath, fileName) {
	$("img.quality_icon_image").attr("src",filePath+fileName);
	$("input.quality_icon").attr("value", fileName);
}


$(document).ready(function(){

	// Suckerfishersatz nur fuer IE6
	if ($.browser.msie && $.browser.version == "6.0" ) {
		$("ul#navigation-top li").hover(function(){
			$(this).addClass("over");
		},function(){
			$(this).removeClass("over");
		});
	}


	$("div.blockPrint a").click(function(){
		open_window(780,480,$(this).attr("href"));
		return false;
	});


	$("a.thickbox.thumb").click(function(){
		open_window(780,480,$(this).attr("href"));
		return false;
	});
	
	
	original_image = $("a.popupbox.normal").children("img").attr("src");
	
	$("a.popupbox.thumb").hover(function(){
		$("a.popupbox.normal img").attr("src", $(this).attr("href").replace("/zoom/", "/normal/"));
		$("a.popupbox.normal img").attr("src", $(this).attr("href").replace("/en/img/", "/de/img/"));
	},function(){
		$("a.popupbox.normal img").attr("src", original_image);
	});
	
	$("a.imageview.thumb").hover(function(){
		$("img.imageview.normal").attr("src", $(this).attr("href"));
	},function(){
		$("img.imageview.normal").attr("src", original_image);
	});
	
	$("a.popupbox").click( function() { 
		
		open_window(888, 605, "/en/wDynamic/wScripts/imageview.php?id=" + $("div.images").attr("id"));
		return false
		} 
	);

	$("a.upload").click(function(){
		open_window(780,480,$(this).attr("href"));
		upload_callback_element = $(this);
		return false;
	});


	$(".edit a.save").click(function(){
		if (document.forms.editor) {
			document.forms.editor.submit();
			return false;
		}
	});


	// document.forms.editor
	$(".edit a.del").click(function(){
		if (document.forms.editor) {
			document.forms.editor.submit();
			return false;
		}
	});


	$("a.add_child").click(function(){
		add_child_counter++;
		$("div.hidden"+add_child_counter).css("display","block");
		location.hash = "add_child_anchor_"+add_child_counter;
		return false;
	});


	$("a.del_child").click(function(){
		if (confirm("Variation wirklich löschen?")) {		
			$(this).parent().parent().remove();
			$.post("/de/wDynamic/wScripts/delete_child_ajax.php",{
  			"order_number": $(this).attr("href"),
			"language": "en"} ,
  			function(xml){
	  			var text = $("reply",xml).text();
	 			if (text == "ok") {
	  			} else {
	  				alert("Es ist ein Fehler aufgetreten!");
	  			}
			});
		}
		return false;
	});


	// fix for clicking in ie
	$('a.liste').each(function() {		
		$(this).click( function() {
			window.location.href = $(this).attr('href');
		});
	});
	
	/*
	//javascript workaround für die navigation
	$('#navigation-left ul li.open ul li.selected').each(function() {
		//alert($(this).children(".selected").get());
		$(this).parent().parent().removeClass("open");
		$(this).parent().parent().addClass("selected");		
	});
	*/

	// suckerfish
	$("#navigation-left ul li.open").hover(function(){
	  $(this).addClass("leftover");
	  $(this).addClass("over");
	}, function(){
	  $(this).removeClass("leftover");
	  $(this).removeClass("over");
	});
	

// needed for admin
tb_remove();


});
