/**
 * Lexcom.Custom - JS + jQuery custom function collection
 * Copyright (C) Copyright 2008, All rights reserved!
 * @author Oliver Robl, LexCom Informations GmbH
 */

function init(elementId) {
	var content = $(elementId);
	var conWidth = content.width();
	var conHeight = content.height();
	var winWidth = $().width();
	var winHeight = $().height();
	
	// Percent calculate
	winWidth = ((((winWidth / 2) - (conWidth / 2)) * 100) / winWidth) + "%";
	winHeight = (((winHeight / 2) - (conHeight / 2)) * 100) / winHeight + "%";
	
	// Pixel calculate
	//winWidth = ((winWidth / 2) - (conWidth / 2)) + "px";
	//winHeight = ((winHeight / 2) - (conHeight / 2)) + "px";
	
	// Center content
	content.css({
		left: winWidth,
		top: winHeight
	});
}


function getBrowserName(elementId) {
	var eBn = $(elementId);
	
	// Get the name of the client browser
	if ($.browser.mozilla) {
		eBn.val("mozilla");
	}
}


function tmplLoader() {
	var imageExt = ".png"; // Imagename extension
	var imagePath = "custom/images/"; // Path to the image
	var images = [ "etc0001", "etc0002", "etc0003", "etc0004", "etc0005", "etc0006",
					"etc0007", "etc0008", "etc0009", "etc0010", "etc0011", "etc0012",
					"etc0013", "etc0014", "etc0015", "etc0016", "etc0017" ];
	
	for (var i = 0; i < images.length; i++) {
		var currItem = images[i];
		var currId = "#" + currItem;
		
		// Preload images
		var image = new Image;
		image.src = imagePath + currItem + imageExt; // Set image source
		
		// Transparent png in IE6
		if ($.browser.msie && $.browser.version < 7 && i > 2) {
			$(currId).append("<div></div>");
			$(currId + " div").attr("id", image.src);
			cssFilter(currId, currId + " div", "true", "image", image.src);
		} else {
			$(currId).append(image);
		}
	}
	
	// Do submit function
	$("#etc0004").click(function() {submitForm("F", getPicture($(this).attr("id")))});
	$("#etc0005").click(function() {submitForm("Q", getPicture($(this).attr("id")))});
	$("#etc0006").click(function() {submitForm("C", getPicture($(this).attr("id")))});
	$("#etc0007").click(function() {submitForm("B", getPicture($(this).attr("id")))});
	$("#etc0008").click(function() {submitForm("E", getPicture($(this).attr("id")))});
	$("#etc0009").click(function() {submitForm("D", getPicture($(this).attr("id")))});
	$("#etc0010").click(function() {submitForm("G", getPicture($(this).attr("id")))});
	$("#etc0011").click(function() {submitForm("M", getPicture($(this).attr("id")))});
	$("#etc0012").click(function() {submitForm("A", getPicture($(this).attr("id")))});
	$("#etc0013").click(function() {submitForm("P", getPicture($(this).attr("id")))});
	$("#etc0014").click(function() {submitForm("O", getPicture($(this).attr("id")))});
	$("#etc0015").click(function() {submitForm("N", getPicture($(this).attr("id")))});
	$("#etc0016").click(function() {submitForm("L", getPicture($(this).attr("id")))});
	$("#etc0017").click(function() {submitForm("T", getPicture($(this).attr("id")))});
}


function isImgLoad() {
	if ($("#etc0001 > img").attr("complete")) {
		$("#etc0001").css("visibility", "visible");
		window.clearInterval(aktiv);
	}
}


function cssFilter(id, value, status, method, imgSrc){
	// status	=	String[true, false]
	// method	=	String[crop, image, scale]
	
	$(value).css({
		background: "none",
		width: $(id).css("width"),
		height: $(id).css("height"),
		filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='" + status + "', sizingMethod='" + method + "', src='" + imgSrc + "')"
	});
}


function getPicture(id) {
	var picPath = "";
	
	if ($.browser.msie && $.browser.version < 7) { // Case IE6
		picPath = $("#" + id + " div").attr("id");
	} else { // Case IE7 > + Mozilla
		picPath = $("#" + id + " img").attr("src");
	}
	
	return picPath;
}


function submitForm(value, logo){
	$("#brandLogo").val(logo);
	$("#brandSchema").val(value);
	$("form").submit();
}

