/* JAVASCRIPT COPYRIGHT BY HARTMUT BOESENER 2009 */
/* -- IT IS WRONG TO STEAL! -- BE FAIR AND DO NOT REMOVE THIS */

var i = 0;
var mime = '.jpg';
var imgname = 'webcam';
var pfad = 'http://www.frashier.de/webcam/';

AnzPic = 13-1;

function previmg()
{
	if (i != 0)
	{
	i --
	var h = $H({id:i});

	var file = 'http://www.frashier.de/webcam_ajax.php';
	new Ajax.Request(
		file,
		{
			method:'post',
			parameters:h.toQueryString(),
			onSuccess:function(xh)
			{
				var resp = xh.responseText;

				$('img').style.opacity=0;

				$('img').src = pfad+imgname+i+mime;
				globalFadeOn('img');
				webcamcount = i+1;
				$('webcamdate').innerHTML = resp;

				$('webcamcount').innerHTML = webcamcount+'/100';
		}	
		}
	);
	}
	if (i == 0)
		$('previous').value=""
}


function nextimg()
{
	if (i != AnzPic)
	{
	i ++;

	var h = $H({id:i});

	var file = 'http://www.frashier.de/webcam_ajax.php';
	new Ajax.Request(
		file,
		{
			method:'post',
			parameters:h.toQueryString(),
			onSuccess:function(xh)
			{
				var resp = xh.responseText;
				$('img').style.opacity=0;

				$('img').src = pfad+imgname+i+mime;
				globalFadeOn('img');
				webcamcount = i + 1;
				$('webcamdate').innerHTML = resp;
				$('webcamcount').innerHTML = webcamcount+'/100';
			}	
		}
	);
	}

	if (i ==AnzPic)
		document.getElementById('next').value="";

}

function ScrollTo(id) {
	Effect.ScrollTo(id);
}

/* EMAIL CHECK
-------------------------------------------------------------------------------------------------------------- */
function checkEmail(s){var a=false;var res=false;if(typeof(RegExp)=='function'){var b=new RegExp('abc');if(b.test('abc')==true){a=true;}}if(a==true){reg=new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,4})$');res=(reg.test(s));}else{res=(s.search('@')>=1&&s.lastIndexOf('.')>s.search('@')&&s.lastIndexOf('.')>=s.length-5);}return(res);}


/* COOKIE SETZEN
-------------------------------------------------------------------------------------------------------------- */
function setCookie(cname,cvalue,cdays)
{
	var now = new Date();
	var expire = new Date(now.getTime() + (1000 * 60 * 60 * 24 * cdays));
	document.cookie = cname+'='+cvalue+'; path=/; expires='+expire.toGMTString()+';';
}

/* COOKIE AUSLESEN
-------------------------------------------------------------------------------------------------------------- */
function getCookie(c_name)
{
	if(document.cookie.length>0)
	{
		var c_start=document.cookie.indexOf(c_name + "=");
		if(c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			var c_end=document.cookie.indexOf(";",c_start);
			if(c_end==-1){
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

/* ACCORDION
-------------------------------------------------------------------------------------------------------------- */
function loadAccordions()
{
 	var commentAccordion = new accordion('content-container', {
  classNames : {
	 toggle : 'comment_toggle',
	 toggleActive : 'comment_toggle_active',
	 content : 'comment_content'
	},
	scrolling: 'yes'
	});
}

function loadActivAccordions()
{
 	var commentAccordion = new accordion('content-container', {
  classNames : {
	 toggle : 'comment_toggle',
	 toggleActive : 'comment_toggle_active',
	 content : 'comment_content'
	},
	scrolling: 'no'
	});
	
	commentAccordion.activate($$('#content-container .comment_toggle')[0]);

}


if (typeof Effect == 'undefined') 
	throw("accordion.js requires including script.aculo.us' effects.js library!");

var accordion = Class.create();
accordion.prototype = {

	//
	//  Setup the Variables
	//
	showAccordion : null,
	currentAccordion : null,
	duration : null,
	effects : [],
	animating : false,
	AlreadyActivated: [], //Added by Trey
	//  
	//  Initialize the accordions
	//
	initialize: function(container, options) {
	  if (!$(container)) {
	    throw(container+" doesn't exist!");
	    return false;
	  }
	  
		this.options = Object.extend({
			resizeSpeed : 8,
			classNames : {
				toggle : 'accordion_toggle',
				toggleActive : 'accordion_toggle_active',
				content : 'accordion_content'
			},
			defaultSize : {
				height : null,
				width : null
			},
			direction : 'vertical',
			onEvent : 'click',
			onActivate: null, //Added by Trey:  CallBack Function called when Tab is activated, sends elemet.
			RepeatActivate: {} //Added by Trey
		}, options || {});
		
		this.duration = ((11-this.options.resizeSpeed)*0.15);
		this.AlreadyActivated =[]; //Added by Trey
		var accordions = $$('#'+container+' .'+this.options.classNames.toggle);
		accordions.each(function(accordion) {
			Event.observe(accordion, this.options.onEvent, this.activate.bind(this, accordion), false);
			if (this.options.onEvent == 'click') {
			  accordion.onclick = function() {return false;};
			}
			
			if (this.options.direction == 'horizontal') {
				var options = {width: '0px'};
			} else {
				var options = {height: '0px'};			
			}
			//options.merge({display: 'none'});			
			Object.extend(options, {display: 'none'});
			
			this.currentAccordion = $(accordion.next(0)).setStyle(options);			
		}.bind(this));
	},
	
	//
	//  Activate an accordion 
	//
	activate : function(accordion) {
		if (this.animating) {
			return false;
		}
		
		this.effects = [];
	
		this.currentAccordion = $(accordion.next(0));
		this.currentAccordion.setStyle({
			display: 'block'
		});		
		
		this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive);

		if (this.options.direction == 'horizontal') {
			this.scaling = {
				scaleX: true,
				scaleY: false
			};
		} else {
			this.scaling = {
				scaleX: false,
				scaleY: true
			};			
		}
			
		if (this.currentAccordion == this.showAccordion) {
		  this.deactivate();
		} else {
		
//This was added by Trey Aughenbaugh
//Allows calling a function before activating a new Menu
		var bolCall = true;
		var elementid = $(this.currentAccordion).id
		var AA = this.AlreadyActivated.indexOf(elementid);
		var RA = this.options.RepeatActivate[elementid];
		if (RA != undefined)
		{
			if ( AA != -1 )
			{
				if ( RA != undefined )
				bolCall = RA;
			}
			else
			{
				this.AlreadyActivated.push(elementid);
			}
		}
 
		if (this.options.onActivate && bolCall)
			this.options.onActivate(this.currentAccordion) ;
	 
//My Code Updates End Here.......................Orig Call Below.		
  		  this._handleAccordion();
		}
	},
	// 
	// Deactivate an active accordion
	//
	deactivate : function() {
		var options = {
		  duration: this.duration,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			queue: {
				position: 'end', 
				scope: 'accordionAnimation'
			},
			scaleMode: { 
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			},
			afterFinish: function() {
				this.showAccordion.setStyle({
					height: '0px',
					display: 'none'
				});				
				this.showAccordion = null;
				this.animating = false;
			}.bind(this)
		};    
    //options.merge(this.scaling);
	Object.extend(options, this.scaling);

    this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
    
		new Effect.Scale(this.showAccordion, 0, options);
	},

  //
  // Handle the open/close actions of the accordion
  //
	_handleAccordion : function() {
		var options = {
			sync: true,
			scaleFrom: 0,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			scaleMode: { 
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			}
		};
		//options.merge(this.scaling);
		Object.extend(options, this.scaling);
		
		this.effects.push(
			new Effect.Scale(this.currentAccordion, 100, options)
		);

		if (this.showAccordion) {
			this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
			
			options = {
				sync: true,
				scaleContent: false,
				transition: Effect.Transitions.sinoidal
			};
			//options.merge(this.scaling);
			Object.extend(options, this.scaling);
			
			this.effects.push(
				new Effect.Scale(this.showAccordion, 0, options)
			);				
		}
		
    new Effect.Parallel(this.effects, {
			duration: this.duration, 
			queue: {
				position: 'end', 
				scope: 'accordionAnimation'
			},
			beforeStart: function() {
				this.animating = true;
			}.bind(this),
			afterFinish: function() {
				if (this.showAccordion) {
					this.showAccordion.setStyle({
						display: 'none'
					});				
				}
				$(this.currentAccordion).setStyle({
				  height: 'auto'
				});
								// NEW BY FRASHIER AKA HARTMUT BOESENER
				if(this.options.scrolling == 'yes') {
					new Effect.ScrollTo(this.currentAccordion, {offset: -60})
				}
				this.showAccordion = this.currentAccordion;
				this.animating = false;
			}.bind(this)
		});
	}
}

/* MAIL CRYP
-------------------------------------------------------------------------------------------------------------- */
function sendmail(vorn,hinten){location.href='mailto:'+vorn+'@'+hinten;}


/* BOOKMARKS
-------------------------------------------------------------------------------------------------------------- */
function showBookmarkOver(object, id)
{
 if(object.className == "bookmark")
 {
	object.className = "bookmark-over";
  document.getElementById(id).style.display=''; 
 }
}

function showBookmarkOut(object, id)
{
 if(object.className == "bookmark-over") {
  object.className = "bookmark";
	document.getElementById(id).style.display='none'; 
 }
}

function AddBookmark(name, u, t)
{

	 var title=encodeURIComponent(t);
 	var url=encodeURIComponent(u);

	switch(name)
	{
		case'oneview':
			window.open("http://beta.oneview.de:80/quickadd/neu/addBookmark.jsf?URL="+url+"&title="+title);
			break;
		case'twitter':
			window.open("http://twitter.com/home?status="+title+": "+url);
			break;
		case'google':
			window.open("http://www.google.com/bookmarks/mark?op=edit&bkmk="+url+"&title="+title);
			break;
		case'delicious':
			window.open("http://delicious.com/save?jump=yes&url="+url+"&title="+title);
			break;
		case'facebook':
			window.open("http://www.facebook.com/sharer.php?u="+u+"&t="+t);
			break;
		case'digg':
			window.open("http://digg.com/submit?phase=2&url="+url+"&title="+title);
			break;
		case'mr wong':
			window.open("http://www.mister-wong.de/index.php?action=addurl&bm_url="+url+"&bm_description="+title);
			break;
		case'yahoo':
			window.open("http://myweb2.search.yahoo.com/myresults/bookmarklet?u="+url+"&t="+title);
			break;
		case'yigg':
			window.open("http://yigg.de/neu?exturl="+url+"&exttitle="+title);
			break;
		case'stumbleupon':
			window.open("http://www.stumbleupon.com/submit?url="+url+"&title="+title);
			break;
		case'webnews':
			window.open("http://www.webnews.de/einstellen?url="+url+"&title="+title);
			break;
		case'blinklist':
			window.open("http://www.blinklist.com/index.php?Action=Blink/addblink.php&Url="+url+"&Title="+title);
			break;
		case'furl':
			window.open("http://furl.net/storeIt.jsp?u="+url+"&t="+title);
			break;
		case'reddit':
			window.open("http://reddit.com/submit?url="+url+"&title="+title);
			break;
		case'spurl':
			window.open("http://www.spurl.net/spurl.php?v=3&title="+title+"&url="+url);
			break;
		case'technorati':
			window.open("http://technorati.com/faves?add="+url);
			break;
	}

}

/* LINK TARGET FUNKTION
-------------------------------------------------------------------------------------------------------------- */
function blank(obj) {
	obj.target = '_blank';
}

/* TABMENU 
-------------------------------------------------------------------------------------------------------------- */
if(typeof(AC)=="undefined") { AC = { }; }

AC.ContentSwap=Class.create();

AC.ContentSwap.prototype=
{
 selectorList:null,
 contentList:null,
 contentSelectorHash:null,
 eventStr:null,

 initialize:function(selectorClass,contentClass,eventStr)
 {
  this.eventStr=eventStr;
  this.selectorList=document.getElementsByClassName(selectorClass);
  this.contentList=document.getElementsByClassName(contentClass);
 	this.setMouseover();
 },

 setMouseover:function()
 {
  for(var i=this.selectorList.length-1,selector;selector=this.selectorList[i];i--)
  {
   Event.observe(selector,this.eventStr,this.swapContent.bind(this,i),false);
  }
 },

 swapContent:function(selectorIndex)
 {
  var selector=this.selectorList[selectorIndex];
  var content=this.contentList[selectorIndex];

  if(!Element.hasClassName(selector,'active'))Element.addClassName(selector,'active');
  if(!Element.hasClassName(content,'active'))Element.addClassName(content,'active');

  for(var i=this.selectorList.length-1;i>=0;i--)
  {
   if(i!=selectorIndex)
   {
   if(Element.hasClassName(this.selectorList[i],'active'))Element.removeClassName(this.selectorList[i],'active');
   if(Element.hasClassName(this.contentList[i],'active'))Element.removeClassName(this.contentList[i],'active');
   }
	}
  return false;
 }
}

var FadeSwap = Class.create();

Object.extend(Object.extend(FadeSwap.prototype, AC.ContentSwap.prototype), {
	cs1IsAnimating: false,
 	cs2IsAnimating: false,
	
	initialize: function(selectorClass, contentClass, eventStr)
 	{
  	Element.addClassName('main', 'hasjs');
  	this.eventStr = eventStr;
		this.selectorList = document.getElementsByClassName(selectorClass);
		this.contentList = document.getElementsByClassName(contentClass);
		for (var i=0; i<this.contentList.length; i++)
		{
			if (Element.hasClassName(this.contentList[i], 'active')) {
	  		this.lastSelectorIndex = i;
	 		} else {
				this.contentList[i].style.display = 'none';
	 		}		
		}
		this.setMouseover();
	},
	
	swapContent: function(selectorIndex)
	{
		if(this.cs1IsAnimating == false && this.cs2IsAnimating == false)
		{
			this.cs1IsAnimating = true;
			this.cs2IsAnimating = true;
			var selector = this.selectorList[selectorIndex];
			var content = this.contentList[selectorIndex];
			// active class hinzufuegen
			if(!Element.hasClassName(selector, 'active')) Element.addClassName(selector, 'active');
			// active class von allen selectoren entfernen 
			for(var i=this.selectorList.length-1; i >= 0; i--)
			{
				if(i != selectorIndex)
				{
					if(Element.hasClassName(this.selectorList[i], 'active')) Element.removeClassName(this.selectorList[i], 'active');
				}
			}
			
			if(selectorIndex != this.lastSelectorIndex)
			{
				var lastContent = this.contentList[this.lastSelectorIndex];
				new Effect.Fade(lastContent, { duration:.25, queue:{position:'end', scope:'cs1'}, afterFinish:this.afterFade.bind(this, lastContent, content) });
				this.lastSelectorIndex = selectorIndex;
			} else {
				this.resetFlag('cs1IsAnimating');
				this.resetFlag('cs2IsAnimating');
			}
		}
		return false;
	},

	afterFade: function(lastContent, content)
	{
		this.resetFlag('cs1IsAnimating');

		new Effect.Appear(content, { duration:.25, queue:{position:'end', scope:'cs2'},
			afterFinish:this.afterAppear.bind(this, content)
		});
	},

	afterAppear: function(content)
	{
		this.resetFlag('cs2IsAnimating');
	},

	resetFlag: function(flagName)
	{
		if(flagName == 'cs1IsAnimating') this.cs1IsAnimating = false;
		if(flagName == 'cs2IsAnimating') this.cs2IsAnimating = false;
	}
});

Event.observe(window, 'load', function() { new FadeSwap('swapnav', 'swapcontent', 'click'); }, false);