/* References Accordion START */

	var running=false;

	function accordion() {
		this.selected_id;
		this.intervalWidth;
		this.fullWidth;
		this.ready;
		this.ready2;
		this.shrinkWidth;
		this.speed;
		this.isLoaded=false;
		this.intervalOpen;
		this.intervalClose;
		this.multiplier=1;
	}
	
	accordion.prototype.init=function()
	{
		this.setIntervalWidth(70);
		this.setFullWidth(560);
		this.setReady(0);
		this.setReady2(0);
		this.setShrinkWidth(560);
		this.setSpeed(1);
	}
	accordion.prototype.setMultiplier=function(value) {
		this.multiplier=value;
	}
	accordion.prototype.getMultiplier=function() {
		return this.multiplier;
	}
	accordion.prototype.setIntervalWidth=function(value) {
		this.intervalWidth=value;
	}
	accordion.prototype.getIntervalWidth=function() {
		return this.intervalWidth;
	}
	accordion.prototype.setFullWidth=function(value) {
		this.fullWidth=value;
	}
	accordion.prototype.setReady=function(value) {
		this.ready=value;
	}
	accordion.prototype.getReady=function() {
		return this.ready;
	}
	accordion.prototype.setReady2=function(value) {
		this.ready2=value;
	}
	accordion.prototype.getReady2=function() {
		return this.ready2;
	}
	accordion.prototype.setShrinkWidth=function(value) {
		this.shrinkWidth=value;
	}
	accordion.prototype.getShrinkWidth=function() {
		return this.shrinkWidth;
	}
	accordion.prototype.setSpeed=function(value) {
		this.speed=value;
	}
	accordion.prototype.getSpeed=function() {
		return this.speed;
	}

	accordion.prototype.setStyle=function(object,parameter,value) {
		document.getElementById(object).style[parameter]=value;		
	}
	
	accordion.prototype.setSelectedPost=function() {
		var component=document.getElementById("nlrx_posts_accordion");
		var allDivs=component.getElementsByTagName("div");
		for (var i=0;i<allDivs.length;i++) {
			if (allDivs[i].className.indexOf("selectedPost")!=-1) {
				this.selected_id=allDivs[i].id.split("_")[2];
			}
		}
	}
	
	accordion.prototype.getRunning=function() {
		return this.running;
	}
	accordion.prototype.setRunning=function(value) {
		this.running=value;
	}
	accordion.prototype.getSelectedId=function() {
		return this.selected_id;
	}
	


	accordion.prototype.startOpenPostContent=function(id,div) {
			
		this.init();
		
		//block the function while it is running
		running=true;
			
		//Get selected Post
		this.setSelectedPost();

		//Wenn nicht bereits aufgeklappter Post ausgewŠhlt wird
		if (this.getSelectedId()!=id) {
			//Date als aktiv markieren
			div.className=div.className+" selectedDate";
			//Content Wrapper als aktiv markieren
			document.getElementById("accordion_post_"+id+"").className=document.getElementById("accordion_post_"+id+"").className+" selectedPost";
			//den aktiven Content Wrapper als inaktiv markieren
			document.getElementById("accordion_post_"+this.getSelectedId()+"").className=document.getElementById("accordion_post_"+this.getSelectedId()+"").className.split(" ")[0];
			//aktives Date als inaktiv markieren
			document.getElementById("accordion_post_date_"+this.getSelectedId()+"").className=document.getElementById("accordion_post_date_"+this.getSelectedId()+"").className.split(" ")[0];
			//ausgewŠhlten Post šffnen
			this.openPostContent(id);
		} else {
			running=false;
		} 
		
	}
	
	accordion.prototype.openPostContent=function (id) {
		
		this.setStyle("accordion_post_"+id+"","width",this.getIntervalWidth()+"px");
		
		//Wenn maximalbreite erreicht ist interval lšschen, intervalWidth zurŸck setzen, running zurŸck setzen
		if ((this.getIntervalWidth()>=560)  || (this.getReady()==1)) {
			this.closePostContent(this.getSelectedId(),id);
		//Wenn maximalbreite noch nicht erreicht ist intervalwidth exponentiell erhšhen
		} else {
			if ((this.getIntervalWidth()+this.getSpeed())>560) {
				this.setIntervalWidth(560);
				this.setReady(1);
				this.closePostContent(this.getSelectedId(),id);
			} else {
				this.setIntervalWidth(this.getIntervalWidth()+this.getSpeed());
				this.closePostContent(this.getSelectedId(),id);
			}
		}
	}
	
	accordion.prototype.closePostContent=function(id,openId) {
		
		this.setStyle("accordion_post_"+id+"","width",this.getShrinkWidth()+"px");

		if (this.getShrinkWidth()<=70 || this.getReady2()==1) {
			this.clearAll();
		} else {
			if (this.getShrinkWidth()-(this.getSpeed())<70) {
				this.setShrinkWidth(70);
				this.setReady2(1);
				var t=this;
				window.setTimeout(function() {t.openPostContent(openId);}, 30);
			} else {
				this.setShrinkWidth(this.getShrinkWidth()-this.getSpeed());
				var t=this;
				window.setTimeout(function() {t.openPostContent(openId);}, 30);
			}
			this.setSpeed(this.getSpeed()+2*this.getMultiplier());
			this.setMultiplier(this.getMultiplier()+1);
		}		
	}
	accordion.prototype.clearAll=function() {
		this.setReady(0);
		this.setReady2(0);
		running=false;
	}
	
	function startAccordionOpen(id,div) {
		if (!running) {
			var accordionObject=new accordion();
			accordionObject.startOpenPostContent(id, div);
		}
	}

/* References Accordion END */
	

function decryptEmail(email)
{
   var mysack = new sack("wp-content/themes/nlrx/components/component.nlrx_decrypt_email.php" );    

  mysack.execute = 1;
  mysack.method = 'POST';
  mysack.setVar( "email", email );
  mysack.onError = function() { alert('Ajax error in voting' )};
  mysack.runAJAX();

  return true;
} // end of JavaScript function myplugin_cast_vote

function sendEmail(email) {
	location.href = "mailto:"+email+"";
}


var isLoaded=false;

function siteLoad() {
	isLoaded=false;
}
siteLoad.prototype.setIsLoaded=function(value) {
	isLoaded=true;
}
siteLoad.prototype.getIsLoaded=function() {
	return isLoaded;
}
function set_laoded_true() {
	var siteLoadObject=new siteLoad();
	siteLoadObject.setIsLoaded(true);
}
function clearValue(object,standardText) {
	if (object.value==standardText) {
		object.value="";
	}
}
function resetValue(object,standardText) {
	value = object.value;
	if (value == "" || value.replace(/(^\s+)(\s+$)/, "") == "") {
		object.value = standardText;
	}
}

/* navigation functions */
function nlrx_handle_navigation() {
	if (screen.width <= 1024 && navigator.userAgent.toLowerCase().indexOf('iphone') == -1) {
		var object = getObject(nlrx_sh1024_id);
		if(isObject(object))
		  object.className = object.className+' '+nlrx_sh1024_class;
	}
}

/* common object functions */
function getObject(id) {
	return document.getElementById(id);
}
function isObject(element)
{
	var result = false;
	if(typeof(element) == 'object' && element != null)
	  result = true;
	return result;
}

/* Onload function */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function addSocialFlyout()
{
	$('#socialsharelink').click(function() {
		if ($('#socialbookmarks').is(":hidden")) {
			$('#socialbookmarks').slideDown('slow');
		} else {
			$('#socialbookmarks').slideUp('slow');
		}
	});
}

function highlight_commentForm()
{
	$('.comment-input').focus(function() {
		$('.comment-input').removeClass('comment-highlight-active');
		$(this).addClass('comment-highlight-active');
	});
}
function changePostButtonClass()
{
	$('#post_previous_btn').hover(function() {
		$(this).addClass('lefthover');
	});
	$('#post_overview_btn').hover(function() {
		$(this).addClass('middlehover');
	});
	$('#post_next_btn').hover(function() {
		$(this).addClass('righthover');
	});
	
	$('#post_previous_btn').mouseout(function() {
		$(this).removeClass('lefthover');
	});
	$('#post_overview_btn').mouseout(function() {
		$(this).removeClass('middlehover');
	});
	$('#post_next_btn').mouseout(function() {
		$(this).removeClass('righthover');
	});
}

function moduleHighlight()
{
	$('#tagcloud').mouseenter(function() {
		$(this).addClass('activeComponent');
	});
	$('#tagcloud').mouseleave(function() {
		$(this).removeClass('activeComponent');
	});
	
	$('#bilderbuch').mouseenter(function() {
		$(this).addClass('activeComponent');
		$(this).find('div').addClass('activeComponent');
	});
	$('#bilderbuch').mouseleave(function() {
		$(this).removeClass('activeComponent');
		$(this).find('div').removeClass('activeComponent');
	});
	
	$('.post-background-front').mouseenter(function() {
		$(this).addClass('activeComponent');
	});
	$('.post-background-front').mouseleave(function() {
		$(this).removeClass('activeComponent');
	});
	
	$('.refcomp').mouseenter(function() {
		$(this).addClass('activeRefComp');
	});
	$('.refcomp').mouseleave(function() {
		$(this).removeClass('activeRefComp');
	});
	
	$('.accordion_post').mouseenter(function() {
			$(this).find('a').addClass('accordion_hover');
	});
	
	$('.accordion_post').mouseleave(function() {
		$(this).find('a').removeClass('accordion_hover');
	});
}
function openLink(url)
{
	window.location.href = url;
}

function fixBlogRows()
{
	if ($('#view-blog')) {
		var count=0;
		var finalHeight;
		$('.right_column > .wrapper').find('.doubled').each(function() {
			if (count==0) {
				finalHeight=$(this).height()+1;
			} else {
				if ($(this).height()<=finalHeight) {
					$('.right_column > .wrapper').find('.relative').css('height',finalHeight+'px');
				} else {
					$('.right_column > .wrapper').find('.relative[style]').removeAttr('style');
				}
			}
			count=count+1;
		});
	}
}

function tweetHighlight()
{
	if ($('.tweet').length>0) {
		$('#tweets').find('.tweet').mouseenter(function() {
			$(this).addClass('activeComponent');
		});
		$('#tweets').find('.tweet').mouseleave(function() {
			$(this).removeClass('activeComponent');
		});
	} else {
		window.setTimeout("tweetHighlight()",500);
	}
}