
/* Fullad 0.99
 **************
 * Fullscreen-Werbeform die auch für eine Fullscreen Flash-Galerie verwendet werden kann ;-)
 * NEU: Werbeform "Bandarole"
 *
 * Abhängigkeiten:
 * global/functions.inc.php
 * global/js/fullad/fullad.js
 * ladies/css/PRODUKT/style.css
 * ladies/images/head/LDGB/head.png
 * ladies/images/site/PRODUKT/head_bg.png
 * ladies/includes/global/vars.inc.php
 * ladies/includes/PRODUKT/elements/foot.inc.php
 * ladies/includes/PRODUKT/elements/jsfiles.inc.php
 *
 * Autor: Peter Navrodt
 * Letzte Änderung: 29.09.10, PN
 *
 * http://www.ladies.de                 (c) 2009-2010 RTO GmbH
 **************************************************************/

var fullad_add_height = 0;
var fullad_add_width = 4;
var fullad_min_y = 0;
var fullad_x_b;
var fullad_y_b;
var fullad_x;
var fullad_y;
var fullad_trans_interval = 50;

function fullad_open(width, height, varobj, auftragsid, fotoid) {
	if(typeof(varobj.cssclass_main) == 'undefined')
		varobj.cssclass_main = 'fullad_main';
	if(typeof(varobj.cssclass_ad) == 'undefined')
		varobj.cssclass_ad = 'fullad_ad';
	if(typeof(varobj.bandarole) == 'undefined')
		varobj.bandarole = false;
	if(typeof(varobj.fixed) == 'undefined')
		varobj.fixed = false;
		
	div_fullad = document.createElement("div");
	div_fullad.setAttribute("class", varobj.cssclass_main);
	div_fullad.setAttribute("className", varobj.cssclass_main);
	div_fullad.setAttribute("id", "fullad_main");
	div_body = document.getElementsByTagName("body")[0];
	div_body.appendChild(div_fullad);
	
	fullad_get_bodyxy();
	div_fullad.style.width = fullad_x_b+"px";
	div_fullad.style.height = fullad_y_b+"px";
	div_fullad.style.zIndex = "1110";
	
	content = '';
	
	if(typeof(varobj.show_head) == 'undefined')
		varobj.show_head = true;

	if(varobj.show_head == true) {
		content += '<div class="fullad_head">';
		content += '  <div class="fullad_subhead" style="background-image: url(/images/head/'+varobj.ldgb+'/head.png);" align="center"><div style="padding-top:75px;"><img src="http://ladies.de/images/site/btn_blaettern.gif" /> <a href="javascript:fullad_close();" class="fullad_link">weiter zu '+varobj.prod_name+'</a></div></div>';
		content += '</div>';
	}
	
	div_fullad.innerHTML = content;
	
	div_fullad_ad = document.createElement("div");
	div_fullad_ad.setAttribute("class", varobj.cssclass_ad);
	div_fullad_ad.setAttribute("className", varobj.cssclass_ad);
	div_fullad_ad.setAttribute("id", "fullad_ad");
	div_fullad_ad.setAttribute("align", "center");
	div_fullad.appendChild(div_fullad_ad);
	
	fullad_get_xy(width, height);
	if(fullad_y < fullad_min_y) {
		fullad_y = fullad_min_y;
	}
	
	if(varobj.bandarole == true) {
		div_fullad_ad.style.left = '0px';
		div_fullad_ad.style.width = '100%';
		div_fullad_ad.style.height = height+'px';
		//div_fullad_ad.style.paddingLeft = fullad_x+'px';
	} else {
		div_fullad_ad.style.left = fullad_x+'px';
	}
	div_fullad_ad.style.top = fullad_y+'px';
	div_fullad_ad.style.display = 'block';
	
	var use_content = varobj.ad_content;
	if(!empty(auftragsid)) {
		use_content = use_content.replace(/AuftragsID=/g,'AuftragsID='+auftragsid);
	}
	if(!empty(fotoid)) {
		use_content = use_content.replace(/FotoID=/g,'FotoID='+fotoid);
	}
	
	div_fullad_ad.innerHTML = use_content;
	
	if(typeof(varobj.effect) == 'undefined')
		varobj.effect = 'none';
		
	if(varobj.effect == 'fade') {
		zeit = fullad_fade("fullad_main", 0);
		setTimeout('fullad_main.style.display = "block"', zeit);
	} else {
		div_fullad.style.display = "block";
	}
	
	window.onresize = function() { fullad_resize(width, height, varobj.bandarole||varobj.fixed, varobj.fixed); }
	
	if(typeof(varobj.scroll_top) == 'undefined')
		varobj.scroll_top = true;
	if(varobj.scroll_top)
		fullad_scroll_top();
}

function fullad_close() {
	window.onresize = function() {}
	div_fullad = document.getElementById("fullad_main");
	div_fullad_ad = document.getElementById("fullad_ad");
	div_fullad.removeChild(div_fullad_ad);
	div_body = document.getElementsByTagName("body")[0];
	div_body.removeChild(div_fullad);
}

function fullad_resize(ad_width, ad_height, not_change_left, not_change_top) {
	div_fullad_main = document.getElementById("fullad_main");
	div_fullad_ad = document.getElementById("fullad_ad");
	fullad_get_bodyxy();
	div_fullad_main.style.width = fullad_x_b+"px";
	div_fullad_main.style.height = fullad_y_b+"px";
	fullad_get_xy(ad_width, ad_height);
	if(fullad_y < fullad_min_y) {
		fullad_y = fullad_min_y;
	}
	if(empty(not_change_left) || !not_change_left) {
		div_fullad_ad.style.left = fullad_x+'px';
	}
	if(empty(not_change_top) || !not_change_top) {
		div_fullad_ad.style.top = fullad_y+'px';
	}
}

function fullad_scroll_top() {
	setTimeout("window.scrollTo(0, 0)", 500);
}

function fullad_fade(divid, direction) {
	c = 1;
	zeit = 0;
	if(direction == 1) {
		setTimeout(''+divid+'.style.visibility = "visible"', fullad_trans_interval*(c+1));
	}
	for (var i=10;i>=0;i--) {
		zeit = fullad_trans_interval*c;
		if(direction == 1) {
			setTimeout('set_opacity('+c+', '+divid+')',zeit);
		} else {
			setTimeout('set_opacity('+i+', '+divid+')',zeit);
		}
		c++;
	}
	if(direction == 0) {
		setTimeout(divid+'.style.visibility = "hidden"', fullad_trans_interval*(c+1));
	}
	return zeit;
}

function set_opacity(value, div_bg)
{
	div_bg.style.opacity = value/10;
	div_bg.style.filter = 'alpha(opacity=' + value*10 + ')';
}

function fullad_get_xy(ad_width, ad_height) {
	arr_x = new Array;
	arr_y = new Array;
	ipos = 0;

	/* Innere Maße (des sichtbaren Bereichs)
	 *****************************************/
	// Width
	if (typeof(document.body.clientWidth) != "undefined") {
		arr_x.push(document.body.clientWidth);
	}
	if (typeof(self.innerWidth) != "undefined") {
		arr_x.push(self.innerWidth);
	}
	if (document.documentElement && document.documentElement.clientWidth) {
		arr_x.push(document.documentElement.clientWidth);
	}
	if(arr_x.length > 0) {
		// Kleinsten Wert verwenden, wenn nicht 0 (ohne Scrollbalken)
		arr_x.sort(Numsort);
		for(i = 0; i < arr_x.length; i++) {
			if(arr_x[i] != 0) {
				ipos = i;
				break;
			}
		}
		x_w = arr_x[ipos];
	} else {
		x_w = 950;
	}
	// Height
	ipos = 0;
	if (typeof(document.body.clientHeight) != "undefined") {
		arr_y.push(document.body.clientHeight);
	}
	if (typeof(self.innerHeight) != "undefined") {
		arr_y.push(self.innerHeight);
	}
	if (document.documentElement && document.documentElement.clientHeight) {
		arr_y.push(document.documentElement.clientHeight);
	}
	if(arr_y.length > 0) {
		// Kleinsten Wert verwenden, wenn nicht 0 (ohne Scrollbalken)
		arr_y.sort(Numsort);
		for(i = 0; i < arr_y.length; i++) {
			if(arr_y[i] != 0) {
				ipos = i;
				break;
			}
		}
		y_w = arr_y[ipos];
	} else {
		y_w = 780;
	}

	/* Scroll Offset
	 *****************************************/
	if (self.pageYOffset) { // all except Explorer
		x_o = self.pageXOffset;
		y_o = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		// Explorer 6 Strict
		x_o = document.documentElement.scrollLeft;
		y_o = document.documentElement.scrollTop;
	} else if (document.body) { // all other Explorers
		x_o = document.body.scrollLeft;
		y_o = document.body.scrollTop;
	}
	
	// Mitte berechnen
	fullad_x = Math.round(x_w/2 - (ad_width+fullad_add_width)/2 + x_o);
	fullad_y = Math.round(y_w/2 - (ad_height+fullad_add_height)/2 + y_o);
	if(fullad_y < 0) {
		fullad_y = 0;
	}
	if(fullad_x < 0) {
		fullad_x = 0;
	}
}

function fullad_get_bodyxy() {
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight;

	if (test1 > test2) { // all but Explorer Mac
		fullad_x_b = document.body.scrollWidth;
		fullad_y_b = document.body.scrollHeight;
	} else { // Explorer Mac;
		//would also work in Explorer 6 Strict, Mozilla and Safari
		fullad_x_b = document.body.offsetWidth;
		fullad_y_b = document.body.offsetHeight;
	}
	
	var strMarginLeft = getCurrentStyle(document.body, 'margin-left');
	var strMarginRight = getCurrentStyle(document.body, 'margin-right');
	
	if(strMarginLeft != '' && strMarginLeft.match(/px/)) {
		fullad_x_b = fullad_x_b + parseInt(strMarginLeft.replace(/px/, ''));
	}
	if(strMarginRight != '' && strMarginRight.match(/px/)) {
		fullad_x_b = fullad_x_b + parseInt(strMarginRight.replace(/px/, ''));
	}	
}
