function trigLoadProdPane(id) {

	jQuery("ul.prodNav li").removeClass("aktiv");
	jQuery("#prodNav"+id).addClass("aktiv");
	jQuery(".prodPane").hide();
	jQuery("#prodPane" + id).show();

}

function trigStepPreviewLeft() {

	if(curPrevPos>0) {

		jQuery("#prodImageTumb" + (curPrevPos+4)).hide("fast");
		curPrevPos--;
		jQuery("#prodImageTumb" + curPrevPos).show("fast");

	}

}

function trigStepPreviewRight() {
	
	if(curPrevPos+5<previewImages) {

		jQuery("#prodImageTumb" + (curPrevPos)).hide("fast");
		curPrevPos++;
		jQuery("#prodImageTumb" + (curPrevPos+4)).show("fast");

	}
	
}

function trigSystemStatus(lang) {

	jQuery.post('/code/systemstatus.php',{'lang':lang},function(data) {
	
		if(data=='ok') {
			
			jQuery("#systemstatus").removeClass("error");
			jQuery("#systemstatus").addClass("ok");
			jQuery("#displayStatus").html("All systems running");
			
		}
		
		else if(data=='error') {
		
			jQuery("#displayStatus").html("timeout..");

		} else {
		
			jQuery("#systemstatus").removeClass("ok");
			jQuery("#systemstatus").addClass("error");
			jQuery("#displayStatus").html(data);
		
		}
	
	});
	
	window.setTimeout("trigSystemStatus('" + lang + "')" , 60000);

}

function trigPrevCampaign() {
	
	if(curCampaign > 0) {
		curCampaign--;
		stepActive=0;

		if(stepWait == 0) {
			window.setTimeout("trigStepActivate()",30000);
			stepWait=1;
		}
		
		jQuery("#campImage").css("background-image","url(" + c_images[curCampaign] + ")");
		
		jQuery("#campImage img").hide("puff",function() {
		
			var btnMore = '';
			if(c_links[curCampaign] != '') {
				btnMore = '<p><ul class="button"><li><a href="' + c_links[curCampaign] + '">' + c_linktxt[curCampaign] + '</a></li></ul></p>';
			}

			jQuery("#campContent").html(c_articles[curCampaign] + btnMore);
			jQuery("#campImage").html('<img src="' + c_images[curCampaign] + '" alt="" />');

		});
		
	}
	
}

function trigNextCampaign() {

	if( (curCampaign+1) < nrCampaign) {
		curCampaign++;
		stepActive=0;
		
		if(stepWait == 0) {
			window.setTimeout("trigStepActivate()",30000);
			stepWait=1;
		}

		jQuery("#campImage").css("background-image","url(" + c_images[curCampaign] + ")");
		
		jQuery("#campImage img").hide("puff",function() {
		
			var btnMore = '';
			if(c_links[curCampaign]!='') {
				btnMore = '<p><ul class="button"><li><a href="' + c_links[curCampaign] + '">' + c_linktxt[curCampaign] + '</a></li></ul></p>';
			}
		
			jQuery("#campContent").html(c_articles[curCampaign] + btnMore);
			jQuery("#campImage").html('<img src="' + c_images[curCampaign] + '" alt="" />');

		});
		
	}

}

var stepActive = 1;
var stepWait = 0;

function trigStepCampaign() {

	if(nrCampaign>1 && stepActive == 1) {
		
		if( (curCampaign+1) >= nrCampaign) {
		
			curCampaign = 0;
	
		} else {
		
			curCampaign++;
		
		}
	
		jQuery("#campImage").css("background-image","url(" + c_images[curCampaign] + ")");
			
		jQuery("#campImage img").hide("puff",function() {
			
			var btnMore = '';
			if(c_links[curCampaign]!='') {
				btnMore = '<p><ul class="button"><li><a href="' + c_links[curCampaign] + '">' + c_linktxt[curCampaign] + '</a></li></ul></p>';
			}

			jQuery("#campContent").html(c_articles[curCampaign] + btnMore);
			jQuery("#campImage").html('<img src="' + c_images[curCampaign] + '" alt="" />');
	
		});
		
	}
	window.setTimeout("trigStepCampaign()",10000);

}

function trigStepActivate() {
	stepActive=1;
	stepWait=0;
}

var popupContent = false;
var popupShow = false;
var beingShown = false;

jQuery(document).ready(function() {

	jQuery(document).ready(function(){ 
        jQuery(document).pngFix(); 
    }); 

	jQuery(".mainmenu").droppy();
	trigSystemStatus("no");
	
	var width = 0;
	
	for(var i=1;i<=6;i++) {
	
		try {
			width = jQuery(".mainmenu" + i).width();
			if(width!==false && width!='auto') {
				width = width - 6;
		
				var offset = '-' + ( width - 27);
	
				jQuery(".dropdown" + i).css("width", width + 'px');
				jQuery(".dropdown" + i + " li").css("width", width + 'px');
				jQuery(".dropdown" + i).css("left" , offset + 'px');
			}
	
		} catch(Error) {}
	
	}

	jQuery(function(){
	   
		jQuery("#btnKontakt").each(function() {

			var distance = 20;
			var time = 250;
			var hideDelay = 500;

			var hideDelayTimer = null;

			jQuery("#btnKontakt").mouseup(function() {
			
				if( popupShow == false && beingShown == false ) {
					
					popupContent = 1;
					
					jQuery(".popup .bb img").css("padding-left","85px");
					
					jQuery(".popupContent").load("/blocks/kontaktform.php",{},function(){
																	
						beingShown = true;
						jQuery("#popupContainer").css({
							top: -250,
							left: 550,
							width: 350,
							display: 'block'
						}).animate({
							top: '-=' + distance + 'px'
						}, time, 'swing', function() {
							beingShown = false;
							popupShow = true;
						});
						
					});

				} else if(popupContent == 2) {
				
					popupContent = 1;
					jQuery(".popup .bb img").css("padding-left","85px");
					jQuery("#popupContainer").css({width:350,top:-270});
					jQuery(".popupContent").load("/blocks/kontaktform.php");
				
				} else {

					jQuery("#popupContainer").animate({
						top: '-=' + distance + 'px'
					}, time, 'swing', function () {
						popupShow = false;
						jQuery("#popupContainer").css('display', 'none');
					});

				}
			});

		});

		jQuery("#btnOppringt").each(function() {
			var distance = 20;
			var time = 250;
			var hideDelay = 500;

			var hideDelayTimer = null;

			jQuery("#btnOppringt").mouseup(function() {
			
				if( popupShow == false && beingShown == false ) {
					
					popupContent = 2;

					jQuery(".popup .bb img").css("padding-left","170px");

					jQuery(".popupContent").load("/blocks/oppringtform.php",{},function() {
						
						beingShown = true;
						jQuery("#popupContainer").css({
							top: -260,
							left: 550,
							width: 280,
							display: 'block'
						}).animate({
							top: '-=' + distance + 'px'
						}, time, 'swing', function() {
							beingShown = false;
							popupShow = true;
						});
					});
											
				} else if(popupContent == 1) {
				
					popupContent = 2;
					jQuery(".popup .bb img").css("padding-left","170px");
					jQuery("#popupContainer").css({width:280,top:-280});
					jQuery(".popupContent").load("/blocks/oppringtform.php");
				
				} else {

					jQuery("#popupContainer").animate({
						top: '-=' + distance + 'px'
					}, time, 'swing', function () {
						popupShow = false;
						jQuery("#popupContainer").css('display', 'none');
					});

				}
			});
		});
	   
	});
});

function trigLoadNews(id) {

	jQuery("#newsContainer .content").load('/code/news.php' , {"id" : id} , function(data) {
	
		jQuery("#newsContainer ul.tabs li").removeClass("aktiv");
		jQuery("li#newsTab" + id).addClass("aktiv");
	
		if(data=='error') {
		
			jQuery("#newsContainer .content").html("<p>Error: couldnt load content.</p>");
		
		}
	
	});

}

function trigLogArticle(id) {

	if(id > 0) {
		jQuery.post('/code/log_article.php',{'id':id},function(data) {
		
			if(data!='ok') {
				
				alert(data);
				
			}
		
		});
	}
}

function trigToggleApps(id) {
	if(id>0) {
		if(appsMenu>0) {
			jQuery("#appsmenu" + appsMenu).hide("blind");
			jQuery("#submenulink" + appsMenu).attr("class","menu");
		}
		if(appsMenu!=id) {
			jQuery("#submenulink" + id).attr("class","menuAktiv");
			jQuery("#appsmenu" + id).show("blind");
			appsMenu = id;
		} else {
			jQuery("#submenulink" + id).attr("class","menu");
			appsMenu = 0;
		}
	}
}

function trigSendKontaktForm() {

	var navn = jQuery("#kontaktNavn").attr("value");
	var epost = jQuery("#kontaktEpost").attr("value");
	var mailto = jQuery("#kontaktMailto").attr("value");
	var melding = jQuery("#kontaktMelding").attr("value");
	
	if(navn != '' && epost.indexOf("@")!==false && mailto.indexOf(":at:")!==false) {
	
		jQuery.post("/code/postkontaktform.php" , {'navn':navn,'epost':epost,'mailto':mailto,'melding':melding},function(data) {
		
			if(data=='ok') {
			
				var distance = 20;
				var time = 250;
				var hideDelay = 500;
				
				jQuery("#popupContainer").animate({
					top: '-=' + distance + 'px'
				}, time, 'swing', function () {
					popupShow = false;
					jQuery("#popupContainer").css('display', 'none');
				});
			
			} else {
				alert(data);
			}
		
		});
		
	
	}

}

function trigSendOppringtForm() {

	var navn = jQuery("#oppringtNavn").attr("value");
	var telefon = jQuery("#oppringtTelefon").attr("value");
	var mailto = jQuery("#oppringtMailto").attr("value");
	
	if(navn != '' && is_numeric(telefon) && mailto.indexOf(":at:")!==false) {
	
		jQuery.post("/code/postkontaktform.php" , {'navn':navn,'telefon':telefon,'mailto':mailto},function(data) {
		
			if(data=='ok') {
			
				var distance = 20;
				var time = 250;
				var hideDelay = 500;
				
				jQuery("#popupContainer").animate({
					top: '-=' + distance + 'px'
				}, time, 'swing', function () {
					popupShow = false;
					jQuery("#popupContainer").css('display', 'none');
				});
			
			} else {
				alert(data);
			}
		
		});
		
	
	}

}

function setContentHeight(c,t) {

	var antall = jQuery(c).children().length;
	var height = 0;
	
	for(var i=0;i<antall;i++) {
	
		if( jQuery(c + ' ' + t).eq(i).height() > height ) {
		
			height = jQuery(c + ' ' + t).eq(i).height();
		
		}
	
	}
	
	height += 5;
	
	for(i = 0;i<antall;i++) {
	
		jQuery(c + ' ' + t).eq(i).height(height);
	
	}

}

function urldecode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous
    // %          note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    var hash_map = {}, ret = str.toString(), unicodeStr='', hexEscStr='';
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The hash_map is identical to the one in urlencode.
    hash_map["'"]   = '%27';
    hash_map['(']   = '%28';
    hash_map[')']   = '%29';
    hash_map['*']   = '%2A';
    hash_map['~']   = '%7E';
    hash_map['!']   = '%21';
    hash_map['%20'] = '+';
    hash_map['\u00DC'] = '%DC';
    hash_map['\u00FC'] = '%FC';
    hash_map['\u00C4'] = '%D4';
    hash_map['\u00E4'] = '%E4';
    hash_map['\u00D6'] = '%D6';
    hash_map['\u00F6'] = '%F6';
    hash_map['\u00DF'] = '%DF';
    hash_map['\u20AC'] = '%80';
    hash_map['\u0081'] = '%81';
    hash_map['\u201A'] = '%82';
    hash_map['\u0192'] = '%83';
    hash_map['\u201E'] = '%84';
    hash_map['\u2026'] = '%85';
    hash_map['\u2020'] = '%86';
    hash_map['\u2021'] = '%87';
    hash_map['\u02C6'] = '%88';
    hash_map['\u2030'] = '%89';
    hash_map['\u0160'] = '%8A';
    hash_map['\u2039'] = '%8B';
    hash_map['\u0152'] = '%8C';
    hash_map['\u008D'] = '%8D';
    hash_map['\u017D'] = '%8E';
    hash_map['\u008F'] = '%8F';
    hash_map['\u0090'] = '%90';
    hash_map['\u2018'] = '%91';
    hash_map['\u2019'] = '%92';
    hash_map['\u201C'] = '%93';
    hash_map['\u201D'] = '%94';
    hash_map['\u2022'] = '%95';
    hash_map['\u2013'] = '%96';
    hash_map['\u2014'] = '%97';
    hash_map['\u02DC'] = '%98';
    hash_map['\u2122'] = '%99';
    hash_map['\u0161'] = '%9A';
    hash_map['\u203A'] = '%9B';
    hash_map['\u0153'] = '%9C';
    hash_map['\u009D'] = '%9D';
    hash_map['\u017E'] = '%9E';
    hash_map['\u0178'] = '%9F';
 
    for (unicodeStr in hash_map) {
        hexEscStr = hash_map[unicodeStr]; // Switch order when decoding
        ret = replacer(hexEscStr, unicodeStr, ret); // Custom replace. No regexing
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}

function is_numeric (mixed_var) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: David
    // +   improved by: taith
    // +   bugfixed by: Tim de Koning
    // *     example 1: is_numeric(186.31);
    // *     returns 1: true
    // *     example 2: is_numeric('Kevin van Zonneveld');
    // *     returns 2: false
    // *     example 3: is_numeric('+186.31e2');
    // *     returns 3: true
    // *     example 4: is_numeric('');
    // *     returns 4: false
 
    if (mixed_var === '') {
        return false;
    }
 
    return !isNaN(mixed_var * 1);
}