var jsonObject = {};
var lBoxJson = {};

var dropDownMenu = $.inherit({
	__constructor: function(parent, menu ,options) {
		var item = this;

		this.element = $("#"+parent);
		this.options = $.extend({
			timeout: 200,
			zIndex: 99990
		},options);
		this.lock = 0;

		this.menu = $("#"+menu);
		this.menu.css({
			zIndex: this.options.zIndex
		});

		this.element.mouseover(function() {
			item.open();
		});
		this.menu.mouseover(function() {
			item.open();
		});
		this.element.mouseout(function() {
			item.close();
		});
		this.menu.mouseout(function() {
			item.close();
		});
	},
	open:function() {
		this.lock = 1;
		var item = this;
		setTimeout(function(){
			item.open2(item)
			}, this.options.timeout);
	},
	open2:function(item) {
		if (item.lock == 1) {
			item.menu.show();
			if (typeof item.options != "undefined") {
				if(item.options.triggerClassAct) item.element.addClass(item.options.triggerClassAct);
				if(item.options.toggleTriggerImage) over(item.options.toggleTriggerImage);
				if(item.options.parentMenu) item.options.parentMenu.open();
			}
		}
	},
	close: function() {
		this.lock = 0;
		var item = this;
		setTimeout(function(){
			item.close2(item)
			}, this.options.timeout);
	},
	close2: function(item) {
		if (item.lock==0){
			item.menu.hide();
			if (typeof item.options != "undefined" ) {
				if(item.options.triggerClassAct) item.element.removeClass(item.options.triggerClassAct);
				if(item.options.toggleTriggerImage) out(item.options.toggleTriggerImage);
			}
		}
	}
});

function formFocus(field,active,word) {
	if (active && field.value == word) field.value='';
	else if (field.value == "") field.value=word;
}


function GetJSON(jsonId) {
	if(typeof jsonObject[jsonId] != "object") return null;
	else {
		return jsonObject[jsonId];
	}
}

function newCaptcha(id, colors) {
	var time = new Date();
	id.src = "/fileadmin/inc/class.captcha.php?&stamp=" + time.getMilliseconds() + "&color=" + colors;
}

function getLightboxJSON(id) {
    return lBoxJson[id];
}

function replacecontent(content,id) {
	$("#"+id).html(content);
	$('select.styled').sexyCombo({
		skin: 'select_253',
		suffix: 'sel',
		hiddenSuffix: 'selhid'
	});
}

function updateCheckboxValue(id, value, checked) {

	var tmp = $("#"+id)[0];
	if (checked)
		tmp.value = parseInt(tmp.value) + parseInt(value);
	else
		tmp.value = parseInt(tmp.value) - parseInt(value);
}


function updateCheckboxValue2(id, value, checked) {

	var tmp = $("#"+id)[0];
	var values = [];
	if (tmp.value.length > 0)
		values = tmp.value.split(',');

	if (checked)
		values.unshift(value);
	else {
		var idx = values.indexOf(value);
		values.splice(idx, 1);
	}

	tmp.value = values.join(',');
}

$(document).ready(function () {
	var origTitle = document.title;
	$("#outer-container").height($("body").height());
	$("div.featurebox").height($(".content-inner").height());
	$(".ui-accordion-header a").click(function(){
		var p = $(this).parent();
		if (p.hasClass("ui-state-active")) {
			SWFAddress.setValue("");
			SWFAddress.setTitle(origTitle);
			$(".ui-accordion-content").slideUp(400,function(){p.removeClass("ui-state-active");}).removeClass("ui-state-active");
			return false;
		}
		return true;
	});
	SWFAddress.addEventListener(SWFAddressEvent.CHANGE, function(event){
		var uid = event.pathNames[2]*1;
		if (uid) {
			var elem = $("#header-app"+uid);
			var pTitle = $("#header-app"+uid+" .noprint img").attr("alt");
			if ($("#content-app"+uid).length == 0) {
				var data = {
					eID: "accordion",
					type: t3Type,
					id: t3ID,
					appId: uid
				};
				$.get("index.php", data, function(returnData){
					if ($("#content-app"+uid).length == 0) {
						$(elem).after(returnData);
					}
					showContent(uid,pTitle);
				});
			} else {
				showContent(uid,pTitle);
			}
		}

		function showContent(uid,pTitle) {
			$(".ui-accordion-content").slideUp().removeClass("ui-state-active");
			$("#content-app"+uid).slideDown().addClass("ui-state-active");
			$(".ui-accordion-header").removeClass("ui-state-active");
			$("#header-app"+uid).addClass("ui-state-active");
			SWFAddress.setTitle(pTitle+ " - " + origTitle);
		}
	});

	$("a[rel^='lightbox']").colorbox({
		current:'',
		loop:false,
		opacity: 0.7,
		iframe:function(){return getMovieParams(this,"iframe")},
		innerWidth:function(){return getMovieParams(this,"innerWidth")},
		innerHeight:function(){return getMovieParams(this,"innerHeight")}
	});
	$('select.styled').sexyCombo({
		skin: 'select_253',
		suffix: 'sel',
		hiddenSuffix: 'selhid'
	});

//	$("a[rel^='movie']").colorbox({
//		iframe:true, innerWidth:628, innerHeight:395,current:'',opacity: 0.7
//  	});


	$("a[id^='thumb-'], .over-img, .over-movie").mouseover(function(e){
		$("#overimg-"+e.currentTarget.id.split("-")[1]).show();
	});

	$("a[id^='thumb-'], .over-img, .over-movie").mouseout(function(e){
		$("#overimg-"+e.currentTarget.id.split("-")[1]).hide();
	});

	prM = new dropDownMenu("products-trigger","product-menu");

	$("#products-trigger").click(function(){
		if (prM.lock == 0) {
			$("#product-menu").toggle();
		}
		return false;
	});

})


function flashCallback(e) {
	if(!e.success && e.id == 'home-flash') {
		$("#home-flash").show();
		$("#home-flash-noflash").height($("#"+e.id+" div:first").height());
//		$("#"+e.id).html("")
	}
}

/**
 * Comment
 */
function getMovieParams(element,property) {
	var result = false;
	if ($(element).attr("href").indexOf(".php") != -1) {
		switch (property) {
			case 'iframe':
				result = true;
				break;
			case 'innerWidth':
				result = 628;
				break;
			case 'innerHeight':
				result =  395;
				break;
		}
	}

	return result;
}
