// # TOM 26.04.2010 

document.write('<'+'script src="/js/lib_m.js" type="text/javascript"'+'><'+'/script'+'>');

var Pager 		= new Array();
var source		= "";
var currentPos	= "";
var customer	= "";
var layereditQueue = new Array();
var edit_object_id = "";



function saveAppFe(el,param){
	
	target = el;
//console.log('saveApp target: '+target);			
//alert('#form_'+target+' iframe body');
	
	fields = $('#form_'+target+' :input').serialize(); 
//console.log('fields: '+fields);
	

	if(param){
//console.log('para:' + param);		
		str = encodeURI('f['+ target +'][form]='+param);
		inputfields = str+'&'+fields;
			
//console.log(inputfields);		
	} else {
//console.log('alles klar');			
		inputfields = fields;
	}
	
//console.log('inputfields: '+inputfields);	
	

	 $.ajax({
	   type: "POST",
	   url: "/ajax/appfe/",
	   data: inputfields,
	   dataType: "json",
	   success: function(data){
	   	
	   		var success = false;
			
			if (data[target]['success'] == true){

				success = true;
				
			}else{
//console.dir(data);
		
				if (data[target]['session'] == false) {
	 				//window.location.href = "/profile/edit";
						
	 			}
				
	 			if (button != ""){
	 				
	 				$(button).css('visibility','visible');
	 				
	 			}
	 			
				$.each(data[target]['errors'], function(n, message){
			
					if ($('#edit_'+target+'_'+n).length > 0){
							
						formErrorMessage('#edit_'+target+'_'+n);
					}
					
				}) ;
			}
				
     		if (success == true){
     		
					elements = data[target]['return'];
					
					if (data[target]['callback']) {
					
						eval(data[target]['callback'] + "();");
					}
					
					$.each(elements, function(i, item){
						
							$('#' + target + '_' + i).html(item);
						
					});
				
				$('#form_' + target).parents(".edit").css('display', 'none');
				$('#form_' + target).parents(".edit").prev().css('display', 'block');
				
				
     		}
 			
     	}
	   
	 });

	
}



//#raus alte NL Dropdowns
/*
function get_nl_numbers_of_year(src){
	
	var year = document.newsletter_form.year.value;
	var type = document.newsletter_form.nl_type.value;
	//mod Tom 01.2010
	//bei Type Wechsel erst das höchste Jahr dieses Typs ermitteln...
	if (src != 'year') {
		$.post("/search/year/", {
			type: type,
			modus: 'dataonly'
		}, function(data){
			highestyear = eval(data);
			$("#number").load("/search/number/", {year: highestyear, type: type});
			$("#year").load("/search/year/", {type: type});
			
		})
	} else {
		
		$("#number").load("/search/number/", {year: year, type: type});
	}
	
}
*/



function cm_bwcheck()
{
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.ns4=(!this.dom && document.layers)?1:0;
	this.op=window.opera 
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ie=this.agent.indexOf("msie")>-1 && !this.op
	this.safari=(this.agent.indexOf("safari")>-1)
	if(this.op){
		this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
		this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
		this.op7=this.dom&&!this.op5&&!this.op6
	}else if(this.moz) this.ns6 = 1
	else if(this.ie){
		this.ie4 = !this.dom && document.all
  	this.ie5 = (this.agent.indexOf("msie 5")>-1)
  	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
  	this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
  	this.ie7 = document.all && !document.XMLHTTPObject
  	this.ie8 = document.all && !document.XMLHTTPObject
	}
	this.mac=(this.agent.indexOf("mac")>-1)
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
  this.usedom= this.ns6||this.op7
  this.reuse = this.ie||this.op7||this.usedom
  this.px=this.dom&&!this.op5?"px":""
	return this
}

var bw=new cm_bwcheck();

// Anzeigestatus 0 = aus, 1 = an
var imageGalleryLayer = 1;

// Layer Maße: Breite
var imageGalleryLayerWidth = 1008;
var mailLayerWidth = 712;
var archiveLayerWidth = 912;
var creditsLayerThreeWidth = 934;
var creditsLayerTwoWidth = 634;
var creditsLayerSendNewsWidth = 1000;
var feedBackLayerWidth = 248;
var uploadLayerWidth = 248;

// Layer Maße: Höhe
var imageGalleryLayerHeight = 688;
var mailLayerHeight = 690;
var archiveLayerHeight = 614;
var creditsLayerThreeHeight = 735;
var creditsLayerTwoHeight = 735;
var creditsLayerSendNewsHeight = 900;
var feedBackLayerHeight = 121;
var uploadLayerHeight = 200;

var obj = null;


var currentPos 	= "";

function showGallery(src, pic_id) {
//console.log('src: '+src+' pic_id: '+pic_id);	

	source 	= src;
	id		= pic_id;
//alert('id1:'+id);	
	if (showGallery.arguments.length > 2){
		if (showGallery.arguments[2] == 1){
			customer = 1;
			getImageCustomerDetails(id);
		}else{
			customer = 0;
			getImageDetails(id);	
		}
		
	}else{
		customer = 0;
		getImageDetails(id);
	}
	
	unhideGallery();

//alert('id2:'+id);	
//alert('pic id:'+pic_id);

// id wird im IE kurios überschrieben. macht erstmal keinen sinn, deshalb hier weiter mit pic_id
	
	$("#lb-pager").html(Pager_Output(source, pic_id));
	imageGalleryLayer = 1;
	
	if (bw.ie && !document.documentElement.clientWidth) {
		getScroll();
		prepareIE('100%', 'hidden');
		setScroll(0,0);
	}
		
	
}

function showInboxGallery(src, pic_id) {
	var source 	= src;
	var id		= pic_id;
	

	customer = 0;
	getImageDetails(id, true);
	
	
	unhideGallery();
	
	
	$("#lb-pager").html(Pager_Output(source, id));
	imageGalleryLayer = 1;
	
	if (bw.ie && !document.documentElement.clientWidth) {
		getScroll();
		prepareIE('100%', 'hidden');
		setScroll(0,0);
	}
		
	
}

function showCategoryImageGallery(id, cat_id) {
	var result_num;
    unhideGallery();
    getImageDetails(id);
    ajaxLoader();
    $.ajax({
       type: "GET",
       url: "/search/categoryimageajax/",
       data: "object_id="+id+"&cat_id="+cat_id,
       dataType: "json",
       success: function(data){
            
            Pager        = data['pager'];
            prepareOutputForImageGallery(id + '');
       }
     });
}

function showGlobalImageGallery(id, all) {
    var result_num;
    unhideGallery();
    getImageDetails(id);
    ajaxLoader();
    $.ajax({
       type: "GET",
       url: "/search/globalimagesajax/",
       data: "object_id="+id+"&get_all="+all,
       dataType: "json",
       success: function(data){
            
            
           
            Pager        = data['pager'];
            prepareOutputForImageGallery(id);
       }
     });    
}

/* REFACT raus s.u.
function showImageGallery(id, all) {
	var result_num;
	unhideGallery();
	getImageDetails(id);
	ajaxLoader();
	$.ajax({
	   type: "GET",
	   url: "/search/imagesajax/",
	   data: "object_id="+id+"&get_all="+all,
	   dataType: "json",
	   success: function(data){

			Pager		= data['pager'];
			prepareOutputForImageGallery(id);
	   }
	 });

}
*/

function showImageSearchGallery(id) {
// REFACT Image Search Pager auf die Bilder pro Seite begenzt

	var result_num;
	unhideGallery();
	getImageDetails(id);
	
	source = 1;
	customer = 0;
	
	$("#lb-pager").html(Pager_Output(source, id));	
	
	imageGalleryLayer = 1;
	
	if (bw.ie && !document.documentElement.clientWidth) {
		getScroll();
		prepareIE('100%', 'hidden');
		setScroll(0,0);
	}

}







function prepareOutputForImageGallery(id){
	source = 1;
	customer = 0;
	//getImageDetails(id);
	$("#lb-pager").html(Pager_Output_ImageGallery(source, id));
//$("#lb-pager").html(Pager_Output(source, id));	
	imageGalleryLayer = 1;
	
	if (bw.ie && !document.documentElement.clientWidth) {
		getScroll();
		prepareIE('100%', 'hidden');
		setScroll(0,0);
	}
}

function Pager_Output_ImageGallery(source, id) {
	
	
	$("select").css("visibility", "hidden");
	
	maxPages 	= 8;
	shortened 	= 0;
	
	str = "";
	
	maxamount 	= Pager[source].length;
	
	currentPos 	= jQuery.inArray(id, Pager[source]);
	
	
	minValue = (currentPos-maxPages/2);
	maxValue = (currentPos+maxPages/2);
	
	showPages = maxamount;
	if (maxamount > maxPages) {
		showPages = maxPages;
		shortened = 1;
	}
	
	start = 0;
	if (minValue >= 0) start = minValue;
	end = (start+maxPages);
	if (end > maxamount) { 
		end = maxamount;
		start = end-maxPages;
		if (start < 0) start = 0;
	}
	
	$("#lb-nav-btnNext").css("display","none");
	$("#lb-nav-btnPrev").css("display","none");
	
	
	for (i = start; i < end; i++) {
		
		if (i == start && currentPos != 0) str += " <a href='#' onclick='showGallery("+source+", "+Pager[source][0]+", false);return false;'>1</a>&nbsp;";
		//zurück
		if (i == start && Pager[source][(currentPos-1)]) {
			str += "<a href='#' onclick='showGallery("+source+", "+Pager[source][(currentPos-1)]+", false);return false;'>&nbsp;PREVIOUS</a> | ";
			$("#lb-nav-btnPrev").css("display","block");
		}
		if (currentPos == i) { str += "<a href='#' class='act'>"+(i+1) + "</a> | "; } else { str += "<a href='#' onclick='showGallery("+source+", "+Pager[source][i]+", false); return false;'>" + (i+1) + "</a> | "; } 
		//weiter
		if (i == (end-1) && Pager[source][(currentPos+1)]) {
			str += "<a href='#' onclick='showGallery("+source+", "+Pager[source][(currentPos+1)]+", false);return false;'>NEXT&nbsp;</a>";
			$("#lb-nav-btnNext").css("display","block");
		}
		if (i == (end-1) && shortened == 1 && currentPos !=(maxamount-1)) str += " <a href='#' onclick='showGallery("+source+", "+Pager[source][(maxamount-1)]+", false);return false;'>"+maxamount+"</a>";
		
	}
    

	return str;
	
}

function Pager_Output(source, id) {

	ajaxLoader();
	
	$("select").css("visibility", "hidden");
	
	maxPages 	= 8;
	shortened 	= 0;
	
	str = "";
	
	maxamount 	= Pager[source].length;
	
	currentPos 	= jQuery.inArray(id, Pager[source]);
//alert('id: '+id);	
//alert(currentPos);	

	minValue = (currentPos-maxPages/2);
	maxValue = (currentPos+maxPages/2);
	
	
	showPages = maxamount;
	if (maxamount > maxPages) {
		showPages = maxPages;
		shortened = 1;
	}
	
	start = 0;
	if (minValue >= 0) start = minValue;
	end = (start+maxPages);
	if (end > maxamount) { 
		end = maxamount;
		start = end-maxPages;
		if (start < 0) start = 0;
	}
	
	$("#lb-nav-btnNext").css("display","none");
	$("#lb-nav-btnPrev").css("display","none");
	
	for (i = start; i < end; i++) {
		
		if (i == start && currentPos != 0) str += " <a href='#' onclick='showGallery("+source+", "+Pager[source][0]+", "+customer+");return false;'>1</a>&nbsp;";
		//zurück
		if (i == start && Pager[source][(currentPos-1)]) {
			str += "<a href='#' onclick='showGallery("+source+", "+Pager[source][(currentPos-1)]+", "+customer+");return false;'>&nbsp;zurück</a> | ";
			$("#lb-nav-btnPrev").css("display","block");
		}
		if (currentPos == i) { str += "<a href='#' class='act'>"+(i+1) + "</a> | "; } else { str += "<a href='#' onclick='showGallery("+source+", "+Pager[source][i]+", "+customer+"); return false;'>" + (i+1) + "</a> | "; } 
		//weiter
		if (i == (end-1) && Pager[source][(currentPos+1)]) {
			str += "<a href='#' onclick='showGallery("+source+", "+Pager[source][(currentPos+1)]+", "+customer+");return false;'>weiter&nbsp;</a>";
			$("#lb-nav-btnNext").css("display","block");
		}
		if (i == (end-1) && shortened == 1 && currentPos !=(maxamount-1)) str += " <a href='#' onclick='showGallery("+source+", "+Pager[source][(maxamount-1)]+", "+customer+");return false;'>"+maxamount+"</a>";
		
	}
    

	return str;
	
}

function hideGalleryInfos() {

	$("#lb-center2").fadeOut(500, function(){
		$('#lb-center2').css({'height':'730px'});
	});
	$("#lb-center3").fadeOut(500, function(){
		$('#lb-center3').css({'height':'730px'});
	});
	
	$("#lb-archive1").fadeOut(500, function(){
		$('#lb-archive1').css({'height':'730px'});
	});
	
	$("#lb-creditsThree1").fadeOut(500, function(){
		$('#lb-creditsThree1').css({'height':'730px'});
	});
	$("#lb-creditsThreeMedia").fadeOut(500, function(){
		$('#lb-creditsThreeMedia').css({'height':'730px'});
	});
	$("#lb-creditsSendNews").fadeOut(500, function(){
		$('#lb-creditsThreeMedia').css({'height':'730px'});
	});
	$("#lb-creditsTwo1").fadeOut(500, function(){
		$('#lb-creditsTwo1').css({'height':'730px'});
	});
	
	$("#lb-feedBack1").fadeOut(500, function(){
		$('#lb-feedBack1').css({'height':'730px'});
	});
	$("#lb-feedBack1").fadeOut(500, function(){
		$('#lb-feedBack1').css({'height':'730px'});
	});
	$("#confirm_dialog").fadeOut(500, function(){
		$('#confirm_dialog').css({'height':'730px'});
	});
	$("#confirm_dialog_news").fadeOut(500, function(){
		$('#confirm_dialog_news').css({'height':'730px'});
	});
	$("#confirm_abort_news").fadeOut(500, function(){
		$('#confirm_abort_news').css({'height':'730px'});
	});
	
	$("#lb-overlay").fadeOut(500);
	
	
	$("#affilliate_webgains2").css("display", "inline");
	$("#affilliate_webgains3").css("display", "inline");
	$(".DIVWEFOR").css("display", "inline");
	
	if (document.getElementById('div_popup1')){
		$("#div_popup1").css("display", "inline");	
	}
	

	$("select").css("visibility", "visible");
	$("#lb-center1").fadeOut(500);
	$("body").css("position", "");
	$("body").css("height", "");
	$("body").css("overflow","auto");
// HIER	

//	$("#lb-image").attr({
//		src: ""
//		});
		
	var innergal = "<table><tr><td><img class = 'lb-image' id = 'lb-image' src='' /></td></tr></table>";
	$("#lb-image-wrap").html(innergal);
	
	
	$("#lb-archive1 iFrame").attr("src", "about:blank");
		
	//Mail-Layer:
	
	$('#inputs_wrapper').show();
	$('#lb-wrapmail :input').val("");
	$('#lb-wrapmail #error').html("");
	$('#lb-wrapmail #warning').hide();
	$('#lb-fileUpload1').hide();
	$("#lb-mailform :input").parent().removeClass("highlight");
	$('#lb-wrapmail #success').hide();
	
	imageGalleryLayer = 0;
	
	if (bw.ie && !document.documentElement.clientWidth) {
		
		setScroll(0,this.yPos);
		prepareIE("auto", "auto");
	}
	
	//YUI3 Uploader: nach Layern init, sonst bug: kein Multiupload mehr mäglich
	try { yuiUploaderInit.init(); } catch (e) {}
		
	
}

function unhideGallery(){
	
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (bw.ie && !document.documentElement.clientWidth) {
		width = document.body.offsetWidth;
	} else if (bw.ie7) {
		width = document.documentElement.clientWidth;
	}
	
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (bw.ie && !document.documentElement.clientHeight) {
		height = document.body.offsetHeight;
	} else if (bw.ie7) {
		height = document.documentElement.clientHeight;
	} 
	
	
	
	
		
	pos_left = (width-imageGalleryLayerWidth)/2;
	pos_top	 = (height-imageGalleryLayerHeight)/2;
	pos_left 	= Math.ceil(pos_left);
	pos_top 	= Math.ceil(pos_top);
	
	if (pos_top < 0) pos_top = 0;
	
	$("#affilliate_webgains2").css("display", "none");
	$("#affilliate_webgains3").css("display", "none");
	$(".DIVWEFOR").css("display", "none");
	$("#div_popup1").css("display", "none");
	
	
	$("#lb-overlay").css("height", height);
	$("body").css("position", "relative");
	$("body").css("overflow","hidden");
	$("body").css("height", height);
	$("#lb-center1").fadeIn(500);
	$("#lb-overlay").css("display", "block");
	$("#lb-overlay").css("filter", "alpha(opacity=70)");
	$("#lb-center1").css("left", pos_left+"px");
	$("#lb-center1").css("top", pos_top+"px");
 /* */	
}

function next(){
	showGallery(source, Pager[source][currentPos+1], customer);
}
function previous(){
	showGallery(source, Pager[source][currentPos-1], customer);
}

//HIER
function ajaxLoader(){
	if ($("#lb-innerwrap").hasClass("whiteLayer")){
		//$("#lb-image").attr({src: "/css/default/img/ajax-loader-white.gif"});
		var innergal = "<table><tr><td><img class = 'lb-image' id = 'lb-image' src='/css/default/img/ajax-loader-white.gif' /></td></tr></table>";
		$("#lb-image-wrap").html(innergal);
	}else{
		//$("#lb-image").attr({src: "/css/default/img/ajax-loader.gif"});	
		var innergal = "<table><tr><td><img class = 'lb-image' id = 'lb-image' src='/css/default/img/ajax-loader.gif' /></td></tr></table>";
		$("#lb-image-wrap").html(innergal);	
	}
	
}



function showCreditInput(){

	$('#lb-overlay').attr({onclick: ''});
	$('#lb-overlay').show();
	
}


/*
Ajax Request für Bildinformationen
*/
function getImageDetails(id, isInbox) {
	
	if (typeof object_group_type == "undefined") is_profile = false; else is_profile = object_group_type;
	
	if (getImageDetails.arguments.length > 1 || is_profile == 4){
		$.getJSON("/image/getdetails/", {id: id, isinbox: isInbox}, function(data) {
			writeImageData(data, false);
		});			
	}else{
		$.getJSON("/image/getdetails/", {id: id}, function(data) {
			writeImageData(data, false);
		});
	}
	
	

}



/*
Ajax Request für Bildinformationen
*/
function getImageCustomerDetails(id) {

	$.getJSON("/image/getcustomerimagedetails/", {id: id}, function(data) {
			
			writeImageData(data, true);
		});
	

}



function writeImageData(item, isCustomerGallery){
	//image
	/*
	$("#lb-image").attr({ 
          src: "/prev/616x616"+item['path']+"/"+item['file'],
          alt: item['title']
        });
	*/
//console.dir(item);		
	var vpath = "http://62.146.188.64"+ item['path'];
	
	var vfile = item['file'];
	var scpath = item['screenshot_path'];
	
	//workaround alter Video Server
	if(scpath == "/media/flv"){
		scpath = "/images/content2";
	}
	
	var scfile = item['screenshot_file'];
	var scwidth = item['width'];
	var scheight = item['height'];
	
	if(item['type'] == 3) {
		//local
		//var innergal = "<table><tr><td><!--[if lte IE 7]><span></span><![endif]--><object width='600' height='500' id='flvPlayer'><param name='bgcolor' value='#ffffff'><param name='allowFullScreen' value='true'><param name='base' value='.'><param name='movie' value='/js/default/flvplayer/flvplayer.swf?playerpath=http://goseedev2/js/default/flvplayer&contentpath=" + vpath + "&video=" + vfile + "' width='616'><embed src='/js/default/flvplayer/flvplayer.swf?playerpath=http://goseedev2/js/default/flvplayer&contentpath=" + vpath + "&video=" + vfile + "' width='616' height='616' allowFullScreen='true' base='.' bgcolor='#ffffff' type='application/x-shockwave-flash'></object></td></tr></table>";
		
		//var innergal = "<table><tr><td><!--[if lte IE 7]><span></span><![endif]--><object width='600' height='360' id='flvPlayer'><param name='bgcolor' value='#ffffff'><param name='allowFullScreen' value='false'><param name='base' value='.'><param name='movie' value='/flash/GoSee.swf?videoURL=" + vpath + "/" + vfile + "&videoPreviewURL=http://video.gosee.de/bild/vorschau/" + scwidth + "x" + scheight + scpath + "/" + scfile + "' ><embed src='/flash/GoSee.swf?videoURL=" + vpath + "/" + vfile + "&videoPreviewURL=http://video.gosee.de/bild/vorschau/" + scwidth + "x" + scheight + scpath + "/" + scfile + "' width='600' height='360' allowFullScreen='true' base='.' bgcolor='#ffffff' type='application/x-shockwave-flash'></object></td></tr></table>";
		
		var innergal ="<table><tr><td><div id='player2'></div><script type='text/javascript'>swfobject.embedSWF('/flash/GoSee.swf', 'player2', '600', '360', '10.0.0', null, {videoURL:'" + vpath + "/" + vfile + "', videoPreviewURL:'http://www.gosee.de/prev/" + scwidth + "x" + scheight + scpath + "/" + scfile + "'});</script></td></tr></table>";
		
		
		//var innergal = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="GoseePlayer_big_v1" width="630" height="374" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><param name="FlashVars" value="xmlUrl=/xml/getStructure/news_id/<?=$item['news_id']?>" /><param name="movie" value="/swf/GoseePlayer_big_v1.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true" /><embed src="/flash/GoseePlayer_big_v1.swf" quality="high" bgcolor="#ffffff" width="630" height="375" name="GoseePlayer_big_v1" align="middle"	FlashVars="xmlUrl=/xml/getstructure/news_id/<?=$this->news_id?>" play="true"		loop="false"		quality="high" 	allowScriptAccess="sameDomain"		allowFullScreen="true"		type="application/x-shockwave-flash"		pluginspage="http://www.adobe.com/go/getflashplayer"></embed></object>';
		
		// Dev Server
		//var innergal ="<div id='player2'></div><script type='text/javascript'>swfobject.embedSWF('/flash/GoSee.swf', 'player2', '600', '360', '10.0.0', null, {videoURL:'" + vpath + "/" + vfile + "', videoPreviewURL:'http://gosee.customer.keppler-it.net//prev/" + scwidth + "x" + scheight + scpath + "/" + scfile + "'});</script>";
		
	} else {
		//Hochkomma raus, macht Ärger im IE
		var itemtitle = item['title'].replace(/\'/g,"");
		var innergal = "<table><tr><td><!--[if lte IE 7]><span></span><![endif]--><img class = 'lb-image' id = 'lb-image' src='/prev/616x616" + item['path'] + "/" + item['file'] + "' alt = '" + itemtitle + "' /></td></tr></table>";
	
	}
	
	$("#lb-image-wrap").html(innergal);
	
	
		
    //restliche Elemente
	if (item['title']) {$("#lb-image-title").css("display", "block"); $("#lb-image-title").text(stripslashes(item['title']));} else {$("#lb-image-title").css("display", "none");}
	if (item['description']) { $("#lb-description-tr").css("display", "block");$("#lb-description").text(stripslashes(item['description']))} else {$("#lb-description-tr").css("display", "none");}
	
	
	felder = new Array("artist", "director", "dop", "illustration", "photographer", "model", "model2", "model3", "model4", "casting", "hair", "makeup", "styling", "setdesign", "location", "aa", "ab", "ad", "cd", "producer", "planner", "copywriter", "client", "usage", "editing", "visualeffects", "animation", "sounddesign", "music", "postproduction", "serviceproduction", "production", "free1val", "free2val", "free3val");

	for (var i = 0; i < felder.length; i++) {
		
		//Creditnamen Eintrag besteht aus COMPANY, VORNAME NACHNAME
		//Company kann Komma enthalten, meist Nachname, Vorname
		//wenn Company aus Vorname + Nachname besteht, soll nur Company angezeigt werden
		//Lösung ist eine Näherung
		//nur für die FREE Felder, Standard Credits nur Firmenname
		
		if(item[felder[i]]) {
		
			//nach letztem Komma kommen die Personennamen
			var letztesKomma = item[felder[i]].lastIndexOf(",");
			
			if(letztesKomma > 0){
				var firmenname = item[felder[i]].substring(0, letztesKomma);
			
			} else {
				//wenn sowieso nur Firmennamen im String
				var firmenname = item[felder[i]];
			}
			
			//split
			var namen_array = item[felder[i]].split(",");
			
			//wenn mehr als ein Komma, nur letzes Element
			if(namen_array.length > 1) {
				var personenname = namen_array[namen_array.length-1] ? $.trim(stripslashes(namen_array[namen_array.length-1])) : '';
			} else {
				var personenname = '';
			}
			
			
			//vergleich personennamen und firmennamen, wenn identisch => nur firmennamen
			//whitespace entfernen
			var fn = firmenname.split(' ').join('');
			var pn = personenname.split(' ').join('');
			
			//wenn firmennamen und personennamen identisch, nur firmennamen
			if(fn.toLowerCase() == pn.toLowerCase()){
				var mname = firmenname;
			} else {
				//wenn der firmennamen auch noch ein Komma hat, kommt personennamen raus, da wahrscheinlich Firmenname = Nachname, Vorname
				if(personenname != '' && firmenname.indexOf(",") == -1){
					var mname = firmenname + ' / ' + personenname;
				} else {
					var mname = firmenname;
				}
				
			}
			
			//Free Felder
			if(felder[i] == 'free1val' || felder[i] == 'free2val' || felder[i] == 'free3val') {	
		
				if (item[felder[i]+'_aid'] != 0) {
					var cl = "<a target='_blank' href='/artist/show/id/" + item[felder[i]+'_aid'] + "'>" + mname + "</a>";
				} else if (item[felder[i]+'_cid'] != 0) {
					var cl = "<a target='_blank' href='/member/show/id/" + item[felder[i]+'_cid'] + "'>" + mname + "</a>";
				} else {
					var cl = stripslashes(item[felder[i]]);
				}
				
				//if (item[felder[i]]) { $("#lb-"+felder[i]+"-tr").css("display", "block"); $("td#lb-"+felder[i]).html(cl)} else {$("#lb-"+felder[i]+"-tr").css("display", "none");}
				$("#lb-"+felder[i]+"-tr").css("display", "block"); $("td#lb-"+felder[i]).html(cl)
			
				if (item['free1val']) {$("#lb-free1title").text(stripslashes(item['free1title'])) }
				if (item['free2val']) {$("#lb-free2title").text(stripslashes(item['free2title'])) }
				if (item['free3val']) {$("#lb-free3title").text(stripslashes(item['free3title'])) }
			
			} else {
				//Standard Cresit Felder
				
				if (item[felder[i]+'_aid'] != 0) {
					var cl = "<a target='_blank' href='/artist/show/id/" + item[felder[i]+'_aid'] + "'>" + stripslashes(firmenname) + "</a>";
				} else if (item[felder[i]+'_cid'] != 0) {
					var cl = "<a target='_blank' href='/member/show/id/" + item[felder[i]+'_cid'] + "'>" + stripslashes(firmenname) + "</a>";
				} else {
					var cl = stripslashes(item[felder[i]]);
				}
				
				//if (item[felder[i]]) { $("#lb-"+felder[i]+"-tr").css("display", "block"); $("td#lb-"+felder[i]).html(cl)} else {$("#lb-"+felder[i]+"-tr").css("display", "none");}
				$("#lb-"+felder[i]+"-tr").css("display", "block"); $("td#lb-"+felder[i]).html(cl)
				
			}
		} else {
			//ohne Inhalt Feld ausblenden
			$("#lb-"+felder[i]+"-tr").css("display", "none");
			
		}
	}
	
	
	
	if (item['customer_id'] && item['customer_id'] != "0" && !isCustomerGallery) {
		$("#lb-customer_name-tr").css("display", "block");
		if (item['href']){
			$("#lb-customer_name-a").attr("href", item['href']);
		}else{
			$("#lb-customer_name-a").css("display", "none");
		}
	} else {$("#lb-customer_name-tr").css("display", "none");}
	
	
}




function prepareIE(height, overflow){
	bod = document.getElementsByTagName('body')[0];
	bod.style.height = height;
	bod.style.overflow = overflow;

	htm = document.getElementsByTagName('html')[0];
	htm.style.height = height;
	htm.style.overflow = overflow; 
}

function deleteLogo(){
	$("#obj_img").attr({
			src: ""
		});		
	$("#obj_path").attr({
			value: ""
		});
	$("#obj_file").attr({
			value: ""
		});
}

function removeFromCustomerImage(id, cust_id){
	$.getJSON("/member/removecustomerimage/", {id: id}, function(data) {
			if (data > 0){
				$("#image-gallery-li-"+id).remove();
				$("#images-count").attr({value: $("#images-count").val()-1});	
				
				removeItemFromPager(id,cust_id);
				
				return true;
			}
			
		});
}

function removeItemFromPager(id,cust_id){
	tmp 			= new Array();
	tmp[cust_id] 	= new Array();
	for (item in Pager[cust_id]){
		if (Pager[cust_id][item] == id) continue;
		tmp[cust_id].push(Pager[cust_id][item]);
	}
	Pager = tmp;
}

function removeNewsItem(id){
	parent.$("#form-news-count-objects").val(eval(parent.$("#form-news-count-objects").val())-eval(1));
	$(".form-image-gallery").find(".item-"+id).remove();
	$("#insert_id_"+id).remove();
}


function editNewsItem(object_id){
	
	$("#form-news-method").attr({value: 2});
	$("#news-addimage-path").val(object_id);
	$("#form-news-picture-object-id").val(object_id);
	
	$.getJSON("/member/getinboxobjectdetails/", {id: object_id}, function(dataNewsItem) {
			
			writeNewsItemInput(dataNewsItem);
			parent.$("#account-addimage").css({display: "block"});			
				
			
		});
	
	
}

function writeNewsItemInput(item){

	for (var key in item){
		$("#news-addimage-"+key).attr({value: item[key]});
	}
	$("#editMetaData > img").attr({src: "/prev/96x80"+item['path']+"/"+item['file']});

}

function cancelUploadNewsItem(){
	
	parent.$("#form-account-addimage > .account-image-inputs :input").attr({value: ""});
	parent.$("#profile-image-upload").attr({value: ""});
	$("#form-news-method").attr({value: 1});
	$("#account-addimage").css({display:"none"});
	
}

function validateNewsItem(){
	/*$(".account-image-inputs > .form-row :input")*/
	if ($('#news-addimage-title').val().length > 0){
		return true;
	}
	$("#account-image-news-title").addClass("highlight");
	$("#form-error-msg-news").css({display:"block"});
	return false;
	
}

function editArtist(id){
	
	//anpassen der Höhe des Eingabefeldes nach Fehlermeldung
	errorheight = $("#error-msg-artist").height()+17;
	if (errorheight == 17) errorheight = 0;
	offset = $("#imageform-artist").offset();
	if (offset.top < 630) offset.top = 630;
	if (typeof correctedOffset == "undefined"){
		$("#imageform-artist").css({top: offset.top+errorheight});
		correctedOffset = true;
	}else{
		$("#imageform-artist").css({top: offset.top});
	}
	$("#imageform-artist").css({display:"block"});	
	
	
	if (id){
		//vorhandenen Artist bearbeiten
		$("#edit-artist-checkboxes :input").removeAttr("checked");
		$("#artist-firstname").attr({value: $("#id_"+id+"_firstname").val()});
		$("#artist-lastname").attr({value: $("#id_"+id+"_lastname").val()});
		$("#artist-picture").attr({src: "/prev/166x109"+$("#id_"+id+"_path").val()+"/"+$("#id_"+id+"_file").val()});
		$("#artist-path").attr({value: $("#id_"+id+"_path").val()});
		$("#artist-file").attr({value: $("#id_"+id+"_file").val()});
		
		$("#edit-artist-header-1").css({display: "none"});
		$("#edit-artist-header-2").css({display: "block"});
		$("#edit-artist-header-2 > span").text($("#id_"+id+"_firstname").val()+" "+$("#id_"+id+"_lastname").val());
		
		$("#artist-method").attr({value: "update"});
		$("#artist-id").attr({value: id});
		$("#edit-artist-header").text("Artist \""+$("#id_"+id+"_firstname").val()+" "+$("#id_"+id+"_lastname").val()+"\" bearbeiten:");
		
		locations = $("#id_"+id+"_location_id").val().split(",");
		categories = $("#id_"+id+"_category_id").val().split(",");
		for (loc_id in locations){
			$("#artist-location-"+locations[loc_id]).attr({checked: "checked"});
		}
		for (cat_id in categories){
			$("#artist-category-"+categories[cat_id]).attr({checked: "checked"});
		}
		
		$("#form-delete-artist").attr({
									onclick: "deleteArtist("+id+"); return false;",
									href: "javascript:deleteArtist("+id+");"
									});
		$("#form-delete-artist").show();
		
	}else{
		//neuen Artist anlegen
		$("#edit-artist-basic :input").attr({value: ""});
		$("#artist-path").attr({value: ""});
		$("#artist-file").attr({value: ""});
		$("#artist-method").attr({value: "insert"});
		
		$("#edit-artist-checkboxes :input").removeAttr("checked");
		$("#artist-picture").attr({src: "/css/default/img/dot_clear.gif"});	
		
		$("#edit-artist-header-1").css({display: "block"});
		$("#edit-artist-header-2").css({display: "none"});
		
		$("#form-delete-artist").hide();
		
	}
	
	$(".scroll-container").removeClass("highlight-border");
	$("#edit-artist").slideDown();
	return false;
}

function canceleditArtist(){
	$("#edit-artist").slideUp();
	$("#imageform-artist").css({display:"none"});
	parent.$("#form-account-addimage > .account-image-inputs :input").attr({value: ""});
	parent.$("#profile-image-upload").attr({value: ""});
	$("#form-delete-artist").show();
}

/* RAUS
function deleteArtist(id){
	
		$.getJSON("/artist/delete", {artist_id: id});
	
}
*/

function addnewsimage(path_file, id){
	
	var count = eval(parent.$("#form-news-count-objects").val())+eval(1);
	
	if (count < 11){
	
		/*parent.$("#insert_ids").val(parent.$("#form-image-gallery-insert_ids").val()+id+',');*/
		parent.$("#form-account-news").append("<input name='data[insert_ids][]' value='"+id+"' id='insert_id_"+count+"' type='hidden' />");
		parent.$("#form-news-count-objects").val(count);
		
		parent.$(".item-"+count).toggleClass("empty");
		parent.$(".item-"+count).find(".img-container").append("<!--[if lte IE 7]><span></span><![endif]--><img src='/prev/96x80"+path_file+"' alt='"+path_file+"' />");
		parent.$(".item-"+count).find(".img-tools").append("<a href='javascript:void(0);' onclick='removeNewsItem("+count+"); return false;' class='left img-gallery-trash' title='delete image'><span class='hidden'>delete</span></a>");
		parent.$(".item-"+count).find(".img-tools").append("<a href='javascript:void(0);' onclick='editNewsItem("+id+");' class='right img-gallery-edit' title='edit image'><span class='hidden'>edit</span></a>");
		
		
		parent.$("#form-news-picture_id").val(count);
		
		//leeren der Input-Felder
		parent.$("#form-account-addimage > .account-image-inputs :input").attr({value: ""});
		parent.$("#profile-image-upload").attr({value: ""});
		parent.$("#account-addimage").css({display: "none"});
	}else{
		parent.$("#form-account-news").append("<input name='data[insert_ids][]' value='"+id+"' id='insert_id_"+count+"' type='hidden' />");
		parent.$("#form-news-count-objects").val(count);
		
		parent.$("#ul-image-gallery").append("<li class='item-"+count+"'><div class='img-container'><!--[if lte IE 7]><span></span><![endif]--><img alt='"+path_file+"' src='/prev/96x80"+path_file+"'/></div><div class='img-tools clearfix'></div></li>");
		parent.$(".item-"+count).find(".img-tools").append("<a href='javascript:void(0);' onclick='removeNewsItem("+count+"); return false;' class='left img-gallery-trash' title='delete image'><span class='hidden'>delete</span></a>");
		parent.$(".item-"+count).find(".img-tools").append("<a href='javascript:void(0);' onclick='editNewsItem("+id+");' class='right img-gallery-edit' title='edit image'><span class='hidden'>edit</span></a>");
		
		parent.$("#form-news-picture_id").val(count);
		
		//leeren der Input-Felder
		parent.$("#form-account-addimage > .account-image-inputs :input").attr({value: ""});
		parent.$("#profile-image-upload").attr({value: ""});
		parent.$("#account-addimage").css({display: "none"});
	}
}


function scrollLink(link, id, link2, id2){
	
	$.getJSON("/news/category/id/"+id, function(category){
		additional = "";
		if (link2) additional = link2+id2;
		window.location.href = '/news/'+category+'/'+link+id+'/jsscroll/'+$("#searchresultbox").scrollTop()+additional;
	});
	
	
}

function scrollMemberLink(link, id, link2, id2){
	
	$.getJSON("/member/directlink/id/"+id, function(directlink){
		
		additional = "";
		if (link2) additional = link2+id2;
		
		if (directlink.length > 0){
			window.location.href = '/'+directlink+'/jsscroll/'+$("#searchresultbox").scrollTop()+additional;
		}else{
			window.location.href = link+id+'/jsscroll/'+$("#searchresultbox").scrollTop()+additional;
		}
		
		
	});
	
	
}

function scrollArtistLink(link, id, link2, id2){
	
	additional = "";
	if (link2) additional = link2+id2;
	

	window.location.href = link+id+'/jsscroll/'+$("#searchresultbox").scrollTop()+additional;
	
}

function openWin(uri,name,w,h,l,t,_options){
	if (!uri) return false;
	if (!w) w=400;
	if (!h) h=500;
	if (!l) l=10;
	if (!t) t=10;
	if (!_options) _options='scrollbars=no,resizable=1,status=1';
	popup = window.open(uri,name,"width="+w+",height="+h+",left="+l+",top="+t+","+_options)
	popup.focus();
}

function stripslashes(str)
{
	return str.replace(/\\/g, '');
}

function invertLayer(){
	if (!$("#lb-innerwrap").hasClass("whiteLayer")){
		$("#lb-innerwrap").toggleClass("whiteLayer");
		$("#lb-pagination").toggleClass("whiteLayer");
		$("#lb-nav-btnClose").toggleClass("whiteLayer");
		$('#lb-customer_name-a').toggleClass("whiteLayer");
		
		//buttons
		$("#lb-nav-btnPrev").toggleClass("invertPrevButton");
		$("#lb-nav-btnNext").toggleClass("invertNextButton");
		
	}
	
}

function showCategoriesOfArtists(cat_id, cust_id){
	
	$.getJSON("/member/getartistsbycatid", {cat_id: cat_id, cust_id: cust_id}, function(result) {
			$("#list-artists-by-categories").html('');
			for (i=0; i<=result.length; i++){
				$("#list-artists-by-categories").append("<li class='clearfix'><a href='/artist/show/id/"+result[i]['artist_id']+"'>"+result[i]['lastname']+", "+result[i]['firstname']+"</a> | Categories: "+result[i]['category_id']+" | Location: "+result[i]['location_id']+"</li>");	
			}
			
		});
}

function getClipDetails(id){
	$.getJSON("/newsfilm/getcredits", {object_id: id}, function(result) {
		$('#film_title').text(result['base']['title']);
		$('#film_description').text(result['base']['description']);
		$('#film_credits').text("");
		for (var item in result['credits']){
			$('#film_credits').append("<b>"+item+"</b> "+result['credits'][item]+" ");
		}
		
	});
}



function validate_send_mail_fields(){
	pstring = "";
	
	
	$.each($('#lb-mailform :input'), function(i, element){
		el = element.value.split('&').join('%26');
		pstring +=  element.name+'='+el+'&';
		
	});
	
	var strLen = pstring.length;
	pstring = pstring.slice(0,strLen-1); 

	
	$.ajax({
	   type: "POST",
	   url: "/index/sendmail/",
	   data: pstring,
	   dataType: "json",
	   success: function(msg){
			$("#lb-mailform #error").html("");
			$("#lb-mailform :input").parent().removeClass("highlight");
			$('#lb-wrapmail #warning').css({display:'none'});
			
	   		if (msg['success'] != true){
	   			$('#lb-wrapmail #warning').css({display:'inline'});
	   			$('#captcha_wrapper').load("/index/captcha/", function(){
	   				for (var el in msg){
		   				if (el != "success"){
		   					$("#lb-mailform #error").append("<p>"+msg[el]+"</p>");
		   					$("#lb-mailform #"+el).parent().addClass("highlight");
		   					//.css({"border-color": "#CC0088"});
		   				}
		   			}	
	   			});
	   			
	   		}else{
	   		
	   			$('#lb-wrapmail #success').css({display:'inline'});
	   			$('#lb-wrapmail :input').val("");
				$('#lb-wrapmail #error').html("");
				$('#lb-wrapmail #warning').hide();
				$('#inputs_wrapper').hide();
				
				$("#lb-mailform :input").parent().removeClass("highlight");
				
				$('#lb-center2').css({'height':'128px'});
				//pausecomp(2000);
				//hideGalleryInfos();
				
				
			
	   		}

	   }
	 });

}



function showMailLayer(id, companyname, is_job){
	
	if (showMailLayer.arguments.length > 2){
		$('#send_to_id').attr({name:"send_to_job_id"});
		$('#upload-attachment-view').load("/jobs/uploadattachmentview/");
	}
	
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (bw.ie && !document.documentElement.clientWidth) {
		width = document.body.offsetWidth;
	} else if (bw.ie7) {
		width = document.documentElement.clientWidth;
	}
	
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (bw.ie && !document.documentElement.clientHeight) {
		height = document.body.offsetHeight;
	} else if (bw.ie7) {
		height = document.documentElement.clientHeight;
	} 
	
	
	
	
		
	pos_left = (width-mailLayerWidth)/2;
	pos_top	 = (height-mailLayerHeight)/2;
	pos_left 	= Math.ceil(pos_left);
	pos_top 	= Math.ceil(pos_top);
	
	if (pos_top < 0) pos_top = 0;
	
	$("select").css("visibility", "hidden");	
	$('#captcha_wrapper').load('/index/captcha/');
	$("#affilliate_webgains2").css("display", "none");
	$("#affilliate_webgains3").css("display", "none");
	$("#lb-overlay").css("height", height);
	$("body").css("position", "relative");
	$("body").css("overflow","hidden");
	$("body").css("height", height);
	$("#lb-center2").fadeIn(500);
	$("#lb-overlay").css("display", "block");
	$("#lb-overlay").css("filter", "alpha(opacity=70)");
	$("#lb-center2").css("left", pos_left+"px");
	$("#lb-center2").css("top", pos_top+"px");
	
	$(".hot-links > #link").css("display", "none");
	$('#lb-center2 #company_name').html(companyname);
	$('#send_to_id').val(id);
}


function showArchiveLayer(object_group_type){

	
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (bw.ie && !document.documentElement.clientWidth) {
		width = document.body.offsetWidth;
	} else if (bw.ie7) {
		width = document.documentElement.clientWidth;
	}
	
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (bw.ie && !document.documentElement.clientHeight) {
		height = document.body.offsetHeight;
	} else if (bw.ie7) {
		height = document.documentElement.clientHeight;
	}
	
	pos_left = (width-archiveLayerWidth)/2;
	pos_top	 = (height-archiveLayerHeight)/2;
	pos_left 	= Math.ceil(pos_left);
	pos_top 	= Math.ceil(pos_top);
	
	if (pos_top < 0) pos_top = 0;
	
	$("select").css("visibility", "hidden");
	$("#lb-innerarchiveProfile select").css("visibility", "visible");
	$("#affilliate_webgains2").css("display", "none");
	$("#affilliate_webgains3").css("display", "none");
	$("#lb-overlay").css("height", height);
	$("body").css("position", "relative");
	$("body").css("overflow","hidden");
	$("body").css("height", height);
	
	$("#lb-archive1 iFrame").attr("src", "/profile/archiveiframe/type/"+object_group_type);
		
	$("#lb-archive1").fadeIn(500);
	$("#lb-overlay").css("display", "block");
	$("#lb-overlay").css("filter", "alpha(opacity=70)");
	$("#lb-archive1").css("left", pos_left+"px");
	$("#lb-archive1").css("top", pos_top+"px");
	
	$(".hot-links > #link").css("display", "none");
	
}


function decideLayer(object_id, src, uploadqueue){
	
	if (typeof layereditQueue == "object" && layereditQueue[0] && layereditQueue[0].length > 0){
					
		object_id = layereditQueue[0];	
			
	}
	
	if (activeLayer[object_id] == 3){
		showCreditsLayerThree(object_id, src, uploadqueue);
	}else{
		showCreditsLayerTwo(object_id, src, uploadqueue);
	}
	
}


function showCreditsLayerThree(object_id, src, uploadqueue){
//console.log('ID:'+object_id+' src:'+src);	
	
	if(src == 'portfolio' || src == 'archive' || src == 'lightbox' || src == 'artist' || src == 'archivesingle') {
		form = src;
		src = 'credits_image';
	}

	if (showCreditsLayerThree.arguments.length > 2){
//console.log('A');		
		if (typeof layereditQueue == "object" && layereditQueue[0] && layereditQueue[0].length > 0){
//console.log('B');	
//console.log(layereditQueue);				
			object_id = layereditQueue[0];	
				
		}else{
//			clearFileUpload();
			layereditQueue == new Array();
			//$('#showEdit_07 .basic').toggle(); 
			//$('#showEdit_07 .edit').toggle();
			return false;
		}
	}
	
	edit_object_id = object_id;
	
	cleanFields(src);
	
	if (src == "inbox_object") {
		getObjectDetails(object_id, src, true);
	}else{
		getObjectDetails(object_id, src, false, form);
	}

	
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (bw.ie && !document.documentElement.clientWidth) {
		width = document.body.offsetWidth;
	} else if (bw.ie7) {
		width = document.documentElement.clientWidth;
	}
	
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (bw.ie && !document.documentElement.clientHeight) {
		height = document.body.offsetHeight;
	} else if (bw.ie7) {
		height = document.documentElement.clientHeight;
	}
	

	pos_left = (width-creditsLayerThreeWidth)/2;
	pos_top	 = (height-creditsLayerThreeHeight)/2;
	pos_left 	= Math.ceil(pos_left);
	pos_top 	= Math.ceil(pos_top);
	
	if (pos_top < 0) pos_top = 0;
	
	if (src == 'credits_image' || src == 'credits_image_film') {
		cleanFields('credits_image_film');
//console.log('B');		
		$("select").css("visibility", "hidden");
		$("#lb-innercreditsProfile select").css("visibility", "visible");
		$("#affilliate_webgains2").css("display", "none");
		$("#affilliate_webgains3").css("display", "none");
		$("#lb-overlay").css("height", height);
		$("body").css("position", "relative");
		$("body").css("overflow", "hidden");
		$("body").css("height", height);
		$("#lb-creditsThreeMedia").fadeIn(500);
		
		$("#lb-overlay").css("display", "block");
		$("#lb-overlay").css("filter", "alpha(opacity=70)");
		$("#lb-creditsThreeMedia").css("left", pos_left + "px");
		$("#lb-creditsThreeMedia").css("top", pos_top + "px");
		
		$(".hot-links > #link").css("display", "none");
	}
	else {
	
		$("select").css("visibility", "hidden");
		$("#lb-innercreditsProfile select").css("visibility", "visible");
		$("#affilliate_webgains2").css("display", "none");
		$("#affilliate_webgains3").css("display", "none");
		$("#lb-overlay").css("height", height);
		$("body").css("position", "relative");
		$("body").css("overflow", "hidden");
		$("body").css("height", height);
		$("#lb-creditsThree1").fadeIn(500);
		
		$("#lb-overlay").css("display", "block");
		$("#lb-overlay").css("filter", "alpha(opacity=70)");
		$("#lb-creditsThree1").css("left", pos_left + "px");
		$("#lb-creditsThree1").css("top", pos_top + "px");
		
		$(".hot-links > #link").css("display", "none");
	}
	
}





function showCreditsLayerTwo(object_id, src, uploadqueue){
	
	if(src == 'portfolio' || src == 'archive' || src == 'lightbox' || src == 'artist' || src == 'archivesingle') {
		var form = src;
		src = 'credits_image';
	}

	if (showCreditsLayerTwo.arguments.length > 2){
//console.log('A');	
		if (typeof layereditQueue == "object" && layereditQueue[0] && layereditQueue[0].length > 0){
//console.log('B');
			object_id = layereditQueue[0];	
				
		}else{
//console.log('C');
				
//			clearFileUpload();
			layereditQueue == new Array();
			//$('#showEdit_07 .basic').toggle(); 
			//$('#showEdit_07 .edit').toggle();
			
			return false;
		}
	}
	
	edit_object_id = object_id;
	
	cleanFields(src);
	
	if (src == "inbox_object") {
		getObjectDetails(object_id, src, true);
	}else{
		getObjectDetails(object_id, src, false, form);
	}
	
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (bw.ie && !document.documentElement.clientWidth) {
		width = document.body.offsetWidth;
	} else if (bw.ie7) {
		width = document.documentElement.clientWidth;
	}
	
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (bw.ie && !document.documentElement.clientHeight) {
		height = document.body.offsetHeight;
	} else if (bw.ie7) {
		height = document.documentElement.clientHeight;
	}
	

	pos_left = (width-creditsLayerTwoWidth)/2;
	pos_top	 = (height-creditsLayerTwoHeight)/2;
	pos_left 	= Math.ceil(pos_left);
	pos_top 	= Math.ceil(pos_top);
	
	if (pos_top < 0) pos_top = 0;
	
//auskomm. da sich die Sichtbarkeit nicht mehr herstellen lässt				
	//$("select").css("visibility", "hidden");
	//$("#lb-innercreditsProfile select").css("visibility", "visible");
	$("#affilliate_webgains2").css("display", "none");
	$("#affilliate_webgains3").css("display", "none");
	$("#lb-overlay").css("height", height);
	$("body").css("position", "relative");
	$("body").css("overflow","hidden");
	$("body").css("height", height);
	$("#lb-creditsTwo1").fadeIn(500);
	
	$("#lb-overlay").css("display", "block");
	$("#lb-overlay").css("filter", "alpha(opacity=70)");
	$("#lb-creditsTwo1").css("left", pos_left+"px");
	$("#lb-creditsTwo1").css("top", pos_top+"px");
	
	//$("#lb-imagesearch").css("display", "none");
	
	$(".hot-links > #link").css("display", "none");
	
}


function showCreditsLayerSendNews(object_id, src, uploadqueue){
	
	if(src == 'portfolio' || src == 'archive' || src == 'lightbox' || src == 'artist' || src == 'archivesingle') {
		var form = src;
		src = 'credits_image';
	}
//console.log('src:'+src);
	if (showCreditsLayerSendNews.arguments.length > 2){
//console.log('A');	
		if (typeof layereditQueue == "object" && layereditQueue[0] && layereditQueue[0].length > 0){
//console.log('B');
			object_id = layereditQueue[0];	
				
		}else{
//console.log('C');
				
//			clearFileUpload();
			layereditQueue == new Array();
			//$('#showEdit_07 .basic').toggle(); 
			//$('#showEdit_07 .edit').toggle();
			
			return false;
		}
	}
	
	edit_object_id = object_id;
	
	cleanFields(src);
	
	if (src == "inbox_object") {
		
		getObjectDetails(object_id, src, true);
	}else{
		getObjectDetails(object_id, src, false, form);
	}
	
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (bw.ie && !document.documentElement.clientWidth) {
		width = document.body.offsetWidth;
	} else if (bw.ie7) {
		width = document.documentElement.clientWidth;
	}
	
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (bw.ie && !document.documentElement.clientHeight) {
		height = document.body.offsetHeight;
	} else if (bw.ie7) {
		height = document.documentElement.clientHeight;
	}
//console.log('YES');	

	pos_left = (width-creditsLayerSendNewsWidth)/2;
	pos_top	 = (height-creditsLayerSendNewsHeight)/2;
	pos_left 	= Math.ceil(pos_left);
	pos_top 	= Math.ceil(pos_top);
	
	if (pos_top < 0) pos_top = 0;
	
//auskomm. da sich die Sichtbarkeit nicht mehr herstellen lässt				
	//$("select").css("visibility", "hidden");
	//$("#lb-innercreditsProfile select").css("visibility", "visible");
	$("#affilliate_webgains2").css("display", "none");
	$("#affilliate_webgains3").css("display", "none");
	$("#lb-overlay").css("height", height);
	$("body").css("position", "relative");
	$("body").css("overflow","hidden");
	$("body").css("height", height);
	$("#lb-creditsSendNews").fadeIn(500);
	
	$("#lb-overlay").css("display", "block");
	$("#lb-overlay").css("filter", "alpha(opacity=70)");
	$("#lb-creditsSendNews").css("left", pos_left+"px");
	$("#lb-creditsSendNews").css("top", pos_top+"px");
	
	//$("#lb-imagesearch").css("display", "none");
	
	$(".hot-links > #link").css("display", "none");
	
}


function showFeedBackLayer(){
	
 	/* if (showFeedBackLayer.arguments.length > 2){
		if (layereditQueue[0].length > 0){
			object_id = layereditQueue[0];	
		}else{
			alert(layereditQueue);
		}
	} 
	
	edit_object_id = object_id;
	
	cleanFields(src);
	getObjectDetails(object_id, src);*/
	
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (bw.ie && !document.documentElement.clientWidth) {
		width = document.body.offsetWidth;
	} else if (bw.ie7) {
		width = document.documentElement.clientWidth;
	}
	
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (bw.ie && !document.documentElement.clientHeight) {
		height = document.body.offsetHeight;
	} else if (bw.ie7) {
		height = document.documentElement.clientHeight;
	}
	

	pos_left = (width-feedBackLayerWidth)/2;
	pos_top	 = (height-feedBackLayerHeight)/2;
	pos_left 	= Math.ceil(pos_left);
	pos_top 	= Math.ceil(pos_top);
	
	if (pos_top < 0) pos_top = 0;
	
		
	$("select").css("visibility", "hidden");
	$("#lb-innercreditsProfile select").css("visibility", "visible");	
	$("#affilliate_webgains2").css("display", "none");
	$("#affilliate_webgains3").css("display", "none");
	$("#lb-overlay").css("height", height);
	$("body").css("position", "relative");
	$("body").css("overflow","hidden");
	$("body").css("height", height);
	$("#lb-feedBack1").fadeIn(500);
	
	$("#lb-overlay").css("display", "block");
	$("#lb-overlay").css("filter", "alpha(opacity=70)");
	$("#lb-feedBack1").css("left", pos_left+"px");
	$("#lb-feedBack1").css("top", getScrollY()+pos_top+"px");
	
	setTimeout("hideGalleryInfos()",3000);
	
	$(".hot-links > #link").css("display", "none");
	
	
}

function getScrollY()
{
    scrOfY = 0;
 
    if(typeof(window.pageYOffset) == 'number')
    {
        //NS
        scrOfY = window.pageYOffset;
    }
    else if(document.body && (document.body.scrollLeft || document.body.scrollTop))
    {
        //DOM
        scrOfY = document.body.scrollTop;
    }
    else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
    {
        //IE6
        scrOfY = document.documentElement.scrollTop;
    }
    return scrOfY;
}

function showConfirmationLayer(target){

	
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (bw.ie && !document.documentElement.clientWidth) {
		width = document.body.offsetWidth;
	} else if (bw.ie7) {
		width = document.documentElement.clientWidth;
	}
	
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (bw.ie && !document.documentElement.clientHeight) {
		height = document.body.offsetHeight;
	} else if (bw.ie7) {
		height = document.documentElement.clientHeight;
	}
	

	pos_left = (width-feedBackLayerWidth)/2;
	pos_top	 = (height-feedBackLayerHeight)/2;
	pos_left 	= Math.ceil(pos_left);
	pos_top 	= Math.ceil(pos_top);
	
	if (pos_top < 0) pos_top = 0;
	
//height = 100;	
	$("select").css("visibility", "hidden");
	$("#lb-innercreditsProfile select").css("visibility", "visible");	
	//$("#affilliate_webgains2").css("display", "none");
	//$("#affilliate_webgains3").css("display", "none");
	$("#lb-overlay").css("height", height);
	$("body").css("position", "relative");
	$("body").css("overflow","hidden");
	$("body").css("height", height);
	$("#confirm_dialog").fadeIn(500);	
	$("#lb-overlay").css("display", "block");
	$("#lb-overlay").css("filter", "alpha(opacity=70)");
	$("#confirm_dialog").css("left", pos_left+"px");
	$("#confirm_dialog").css("top", getScrollY()+pos_top+"px");
	

	$(".hot-links > #link").css("display", "none");
	
	
}

function showNewsConfirmationLayer(){

	if ($('#sortable .layer_02').length != 0){
		
		
		sendNews();
		
		return true;
		
	}
	
	
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (bw.ie && !document.documentElement.clientWidth) {
		width = document.body.offsetWidth;
	} else if (bw.ie7) {
		width = document.documentElement.clientWidth;
	}
	
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (bw.ie && !document.documentElement.clientHeight) {
		height = document.body.offsetHeight;
	} else if (bw.ie7) {
		height = document.documentElement.clientHeight;
	}
	

	pos_left = (width-feedBackLayerWidth)/2;
	pos_top	 = (height-feedBackLayerHeight)/2;
	pos_left 	= Math.ceil(pos_left);
	pos_top 	= Math.ceil(pos_top);
	
	if (pos_top < 0) pos_top = 0;
	
		
	$("select").css("visibility", "hidden");
	$("#lb-innercreditsProfile select").css("visibility", "visible");	
	$("#affilliate_webgains2").css("display", "none");
	$("#affilliate_webgains3").css("display", "none");
	$("#lb-overlay").css("height", height);
	$("body").css("position", "relative");
	$("body").css("overflow","hidden");
	$("body").css("height", height);
	$("#confirm_dialog_news").fadeIn(500);
	
	$("#lb-overlay").css("display", "block");
	$("#lb-overlay").css("filter", "alpha(opacity=70)");
	$("#confirm_dialog_news").css("left", pos_left+"px");
	$("#confirm_dialog_news").css("top", getScrollY()+pos_top+"px");
	

	$(".hot-links > #link").css("display", "none");
	
	
}

function showNewsAbortLayer(){

	
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (bw.ie && !document.documentElement.clientWidth) {
		width = document.body.offsetWidth;
	} else if (bw.ie7) {
		width = document.documentElement.clientWidth;
	}
	
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (bw.ie && !document.documentElement.clientHeight) {
		height = document.body.offsetHeight;
	} else if (bw.ie7) {
		height = document.documentElement.clientHeight;
	}
	

	pos_left = (width-feedBackLayerWidth)/2;
	pos_top	 = (height-feedBackLayerHeight)/2;
	pos_left 	= Math.ceil(pos_left);
	pos_top 	= Math.ceil(pos_top);
	
	if (pos_top < 0) pos_top = 0;
	
		
	$("select").css("visibility", "hidden");
	$("#lb-innercreditsProfile select").css("visibility", "visible");	
	$("#affilliate_webgains2").css("display", "none");
	$("#affilliate_webgains3").css("display", "none");
	$("#lb-overlay").css("height", height);
	$("body").css("position", "relative");
	$("body").css("overflow","hidden");
	$("body").css("height", height);
	$("#confirm_abort_news").fadeIn(500);
	
	$("#lb-overlay").css("display", "block");
	$("#lb-overlay").css("filter", "alpha(opacity=70)");
	$("#confirm_abort_news").css("left", pos_left+"px");
	$("#confirm_abort_news").css("top", getScrollY()+pos_top+"px");
	

	$(".hot-links > #link").css("display", "none");
	
}


function showUploadLayer(src, jumper){

 	
 	$('#ajax_btn_upload').click(function(){
 		ajaxFileUpload(src);
 		hideGalleryInfos();
 	});
 	
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (bw.ie && !document.documentElement.clientWidth) {
		width = document.body.offsetWidth;
	} else if (bw.ie7) {
		width = document.documentElement.clientWidth;
	}
	
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (bw.ie && !document.documentElement.clientHeight) {
		height = document.body.offsetHeight;
	} else if (bw.ie7) {
		height = document.documentElement.clientHeight;
	}
	

	pos_left = (width-uploadLayerWidth)/2;
	pos_top	 = (height-uploadLayerHeight)/2;
	pos_left 	= Math.ceil(pos_left);
	pos_top 	= Math.ceil(pos_top);
	
	if (pos_top < 0) pos_top = 0;
	
		
	$("select").css("visibility", "hidden");
	$("#lb-innercreditsProfile select").css("visibility", "visible");
	$("#affilliate_webgains2").css("display", "none");
	$("#affilliate_webgains3").css("display", "none");
	$("#lb-overlay").css("height", height);
	$("body").css("position", "relative");
	$("body").css("overflow","hidden");
	$("body").css("height", height);
	$("#lb-fileUpload1").fadeIn(500);
	
	$("#lb-overlay").css("display", "block");
	$("#lb-overlay").css("filter", "alpha(opacity=70)");
	$("#lb-fileUpload1").css("left", pos_left+"px");
	$("#lb-fileUpload1").css("top", pos_top+"px");
	
	$(".hot-links > #link").css("display", "none");
	
	if(undefined  === jumper) jumper = '';
	$("#lb-fileUpload1 a").attr({ href: "#"+ jumper});


}



/*
Ajax Request für Bildinformationen
*/

function getObjectDetails(id, src, isinbox, form) {
//console.log('form: '+form);	
	if (isinbox){
		$.getJSON("/ajax/getobjectdetails/", {id: id,isinbox: isinbox}, function(data) {
			
			writeObjectData(data, src);
			
		});
	}else{
//console.log(form);
		
		$.getJSON("/ajax/getobjectdetails/", {id: id, form: form}, function(data) {
			
			writeObjectData(data, src, form);
			
		});
	}
	
	
	

}

// TOM 04.2010 
function writeObjectData(data, src, form){
		
//console.log('write src:' + src);	
//console.log('frm:' + form);
//console.dir(data);


/*
	if (data.type == 3){

		if (src == 'credits_image') {
			// wenn type = 3 (film) und kommt aus Medienarchiv wird das Form creditsThreeMedia im Layer angesprochen
			// sonst gibt es Konflickte in JQuery beim auf ruf des nächsten Objekts wenn dies ein Image ist (Film Felder im Speicher) 
			src = 'credits_image_film';
		}
		
			
		//Tom Workaround alter Media Server Pfad
		var scpath = data['screenshot_path'];
		if(data['screenshot_path'] == '/media/flv') {
			scpath = '/images/content2';
		} 
		
		$('#image_film').attr('src', 'http://www.gosee.de/prev/150x150'+scpath+"/"+data['screenshot_file']);
		
		$.each(data, function (i, field){
		
			if (i == 'imagesearch'){
				if (field == '1'){
					$('#credits_film_'+i).check();
					$('#credits_film_'+i).val('1');
				}else{
					$('#credits_film_'+i).uncheck();
					$('#credits_film_'+i).val('1');
				}
			}else{
//console.log('credits_film_'+i+' _'+field);				
				$('#credits_film_'+i).val(field);
			}
			$('#credits_film_'+i).attr('name', 'f['+src+']['+i+']');
			
		});
		
// hier fkt für ThreeMedia wenn src credits image

		if (src == 'credits_image_film') {
		
			$('#lb-creditsThreeMedia form').attr('id', 'form_'+src);
			// wenn type = 3 (film) und kommt aus Medienarchiv wird das Form creditsThreeMedia im Layer angesprochen
		
			
		
				$('#lb-creditsThreeMedia-save_btn').one("click", function(e){
					saveApp(src, form);
				});
			
			
		} else if (src = 'inbox_object') {
			
			$('#lb-creditsSendNews form').attr('id', 'form_'+src);
			
		
				$('#lb-creditsSendNews-save_btn').one("click", function(e){
					saveApp(src, form);
				});
			
		} else {
			
			$('#lb-creditsThree1 form').attr('id', 'form_'+src);
			
		
				$('#lb-creditsThree1-save_btn').one("click", function(e){
					saveApp(src, form);
				});
			
		}

		
		
	}else{

	
		$('#image_img').attr('src', '/prev/150x150'+data['path']+"/"+data['file']);
		
		$.each(data, function (i, field){
				
			if (i == 'imagesearch') {
				if (field == '1') {
					$('#credits_image_' + i).check();
					$('#credits_image_' + i).val('1');
				}
				else {
					$('#credits_image_' + i).uncheck();
					$('#credits_image_' + i).val('1');
				}
			}else if (i == 'imagesearch_type' && field > 0) {

//select für credts news cat setzen
			$("#credits_image_imagesearch_type").val(field);	
				
			}else {
console.log(i);	
console.log(field);	
				$('#credits_image_' + i).val(field);
			}
			
			$('#credits_image_'+i).attr('name', 'f['+src+']['+i+']');
			
		});
		
		if (src = 'inbox_object') {
		
			$('#lb-creditsSendNews form').attr('id', 'form_' + src);
console.log('HIER: '+src);			
			
			$('#lb-creditsSendNews-save_btn').one("click", function(e){
				saveApp(src, form);
			});
			
		}
		else {
		
			$('#lb-creditsTwo1 form').attr('id', 'form_'+src);
	//console.log('form:'+form);		
		
			$('#lb-creditsTwo1-save_btn').one("click", function(e){
				saveApp(src, form);
			});
		
		
		}	
		
	
		
	}

*/	
	
// neues Form aus layer.phtml für Images und Film	
// lb-creditsSendNews
	
	$('#image_img').attr('src', '/prev/150x150'+data['path']+"/"+data['file']);
		
		$.each(data, function (i, field){
				
			if (i == 'imagesearch') {
				if (field == '1') {
					$('#credits_' + i).check();
					$('#credits_' + i).val('1');
				}
				else {
					$('#credits_' + i).uncheck();
					$('#credits_' + i).val('1');
				}
			}else if (i == 'imagesearch_type' && field > 0) {

//select für credts news cat setzen
			$("#credits_imagesearch_type").val(field);	
				
			}else {
//console.log(i);	
//console.log(field);	
				//var fieldclean = field.replace(/\&amp;/g,"");
				$('#credits_' + i).val(field);
			}
			
			$('#credits_'+i).attr('name', 'f['+src+']['+i+']');
			
		});
		
		if (src = 'inbox_object') {
		
			$('#lb-creditsSendNews form').attr('id', 'form_' + src);
//console.log('HIER: '+src);			
			
			$('#lb-creditsSendNews-save_btn').one("click", function(e){
				saveApp(src, form);
			});
			
		}
		else {
	/*	
			$('#lb-creditsTwo1 form').attr('id', 'form_'+src);
	//console.log('form:'+form);		
		
			$('#lb-creditsTwo1-save_btn').one("click", function(e){
				saveApp(src, form);
			});
		
	*/	
		}	
	
	
	
}

function cleanFields(src){
	
	$('#form_'+src+' :input').val('');
	
}


// ***** CALLBACKS ***** //


function contact_me(){
	
	var text_de = "Deine Kontaktanfrage wurde gesendet." 
	var text_en = "Your contact request was sent." 
	var text_fr = "Message sent." 
	
	$('#feedback_text').text(eval("text_"+language));
	
	showFeedBackLayer();

}

function verstoss(){
	
	var text_de = "Deine Meldung wurde gesendet." 
	var text_en = "Advice was sent." 
	var text_fr = "Advice was sent." 
	
	$('#feedback_text').text(eval("text_"+language));
	
	showFeedBackLayer();

}


