// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function linkMe(which) {
    var link = which.getElementsByTagName("a")[which.getElementsByTagName("a").length-1];
    if(!link.onclick) location.href=link.href;
    else link.onclick();
}

function setClass(which) {
	if (document.getElementById('upload').className != which) {
		document.getElementById('upload').className = which;
		document.getElementById('closeBtn').style.display = "none";
		document.getElementById('buttonRow').style.display = "none";
	}
	else {
		document.getElementById('upload').className = '';
		document.getElementById('closeBtn').style.display = "block";
		document.getElementById('buttonRow').style.display = "block";
	}
}

function setClass2(which) {
	if (document.getElementById('upload2').className != which) {
		document.getElementById('upload2').className = which;		
		document.getElementById('closeBtn2').style.display = "none";
		document.getElementById('buttonRow2').style.display = "none";
	}
	else {
		document.getElementById('upload2').className = '';		
		document.getElementById('closeBtn2').style.display = "block";
		document.getElementById('buttonRow2').style.display = "block";
	}
}

function checkTextlength(length, myLabel, myElement) {
	// Checkt Bandbeschreibungslänge
	var theLength = length;
	inputString = document.getElementById(myElement).value;
	if (inputString.length > theLength) {
		inputString = inputString.substring(0, theLength);
		document.getElementById(myElement).value = inputString;
	}	
	document.getElementById(myLabel).innerHTML = theLength - inputString.length;
}

function roundCorners() {
	settingsAll = {
		tl: { radius: 7 },
		tr: { radius: 7 },
		bl: { radius: 7 },
		br: { radius: 7 },
		antiAlias: true,
		autoPad: true,
		validTags: ["ul", "li", "div", "form"]
	}
	settingsLeft = {
		tl: { radius: 7 },
		tr: false,
		bl: { radius: 7 },
		br: false,
		antiAlias: true,
		autoPad: true,
		validTags: ["ul", "li", "div", "form"]
	}
	var myBoxObject = new curvyCorners(settingsAll, "roundedFull");
	myBoxObject.applyCornersToAll();
	var myBoxObject2 = new curvyCorners(settingsAll, "roundedHalf");
	myBoxObject2.applyCornersToAll();
	var myBoxObject3 = new curvyCorners(settingsAll, "comments");
	myBoxObject3.applyCornersToAll();	
	var myBoxObject4 = new curvyCorners(settingsAll, "formularContent");
	myBoxObject4.applyCornersToAll();
	var myBoxObject5 = new curvyCorners(settingsAll, "inBox");
	myBoxObject5.applyCornersToAll();	
	var myBoxObject6 = new curvyCorners(settingsAll, "cle");
	myBoxObject6.applyCornersToAll();	
	var myBoxObject7 = new curvyCorners(settingsAll, "formOnTop");
	myBoxObject7.applyCornersToAll();	
	var myBoxObject8 = new curvyCorners(settingsLeft, "sponsor");
	myBoxObject8.applyCornersToAll();
	var myBoxObject9 = new curvyCorners(settingsAll, "howitworks");
	myBoxObject9.applyCornersToAll();
	var myBoxObject10 = new curvyCorners(settingsAll, "stuffBoxInner");
	myBoxObject10.applyCornersToAll();	
	//var myBoxObject11 = new curvyCorners(settingsAll, "rounded");
	//myBoxObject11.applyCornersToAll();	
	var myBoxObject12 = new curvyCorners(settingsAll, "equalBox");
	myBoxObject12.applyCornersToAll();
	var myBoxObject13 = new curvyCorners(settingsAll, "spamFormFooter");
	myBoxObject13.applyCornersToAll();
	var myBoxObject14 = new curvyCorners(settingsAll, "concertBox");
	myBoxObject14.applyCornersToAll();
	var myBoxObject15 = new curvyCorners(settingsAll, "infoPageBoxInner");
	myBoxObject15.applyCornersToAll();	
	var myBoxObject16 = new curvyCorners(settingsAll, "equalList");
	myBoxObject16.applyCornersToAll();
	var myBoxObject17 = new curvyCorners(settingsAll, "notice");
	myBoxObject17.applyCornersToAll();	
	var myBoxObject18 = new curvyCorners(settingsAll, "welcomeBox");
	myBoxObject18.applyCornersToAll();	
	var myBoxObject19 = new curvyCorners(settingsAll, "albumBox");
	myBoxObject19.applyCornersToAll();	
	var myBoxObject20 = new curvyCorners(settingsAll, "regBox");
	myBoxObject20.applyCornersToAll();	
	var myBoxObject21 = new curvyCorners(settingsAll, "calendarBox");
	myBoxObject21.applyCornersToAll();
	var myBoxObject21 = new curvyCorners(settingsAll, "tourBox");
	myBoxObject21.applyCornersToAll();
}

function closeCurtainAd(which) {
	document.getElementById('ad').style.display = "none";	
}

function claim() {
	/*if (document.getElementById('claim').style.visibility == "visible") {
		document.getElementById('claim').style.visibility = "hidden";}
	else {document.getElementById('claim').style.visibility = "visible";}*/
}

function changeHeigth(a, b) {
	if (document.getElementById(a).offsetHeight > document.getElementById(b).offsetHeight) {
		document.getElementById(b).style.height = document.getElementById(a).offsetHeight +"px";
	}
	else if (document.getElementById(b).offsetHeight > document.getElementById(a).offsetHeight) {
		document.getElementById(a).style.height = document.getElementById(b).offsetHeight +"px";	
	}
	return false;
}

function openNewBrowserWindow(href)
{
	window.open(href,'_blank',
	'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
}

function linkInFrame(href)
{
    if (parent.frames.length > 0)
      {
          parent.location.href = href
      }
      else
      {
         location.href=href;
       }

}
function fullLink(which) {
    var theLink = which.getElementsByTagName("a")[0];
   if (theLink != null)
    {
      if(!theLink.onclick) 
      { 
         location.href=theLink.href;
      }
     else
      {
        theLink.onclick();
      }
    }
}

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Mark O'Sullivan :: http://lussumo.com/
 Jeff Larson :: http://www.jeffothy.com/
 Mark Percival :: http://webchicanery.com/ */
function copy_to_clipboard(text2copy) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text2copy);
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="/swf/clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}

/* a few functions for da media player */

function sendEvent(swf,typ,prm) { 
  thisMovie(swf).sendEvent(typ,prm); 
};
function getUpdate(typ,pr1,pr2,swf) {};
function thisMovie(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
};
var currentPlayerState;

var AutoPlayer = {
  contributionIds: new Array(),
  allContributionIds: new Array(),
  playerPosition: -1,
  illegalPlayerPosition: -1,
  // MediaPlayer state
  currentPlayerState: "",
  currentPlaylistItem:0,
  
  
  playing: false,
  // wrapping the MediaPlayer getUpdate method (minimizes non object code)
  queryParams: "",
  urlPrefix: "",
  
  playpause: function() { 
    if (this.playing) {
      this.stop();
    }   else {
      this.play();
    }
  },
  findNextLegalPosition: function() {
    var pos = this.illegalPlayerPosition;
    if (pos == -1) pos=0;
    for(;this.contributionIds.indexOf(this.allContributionIds[pos]) == -1 || 
            pos>this.allContributionIds.length;
          pos++);
    return(pos);
  },
  playerStateAsText: function() {
    if (this.playing) return "playing"
    return "stopped";
  },
  play: function() {
    // state variable
    this.playing = true
    // advancing to an non-illegal position
    if (this.illegalPlayerPosition != -1 || this.playerPosition == -1) {
      // alles wird gut
      this.jumpToContribution(this.findNextLegalPosition())
    } else {
      $('stagePlayer').sendEvent('next')      
    }
    // 
  },
  stop: function() {
    // that should be enough
    this.playing = false
  },
  
  getUpdate: function(type,param1,param2,playerId) {    
    // if (console && type == "state") console.log("type:" + type + " /P1: " + param1 + " /P2: " + param2 + " /PID: " + playerId)
    if (!this.playing) return;
  	if(playerId != "null") {
  	  if((type == "item") && (param1 != undefined)) { this.currentPlaylistItem = param1 }
  		if((type == "state") && (param1 != undefined)) { 
  			this.currentPlayerState = param1; 
  			if(this.currentPlayerState=="3") {
  			  var length = $(playerId).getLength()
  			  if (this.currentPlaylistItem == (length-1)) {
    			  var nextPosition = (this.playerPosition + 1) % this.contributionIds.length;
    			  // ugly fugly
    			  this.jumpToContribution(nextPosition)
    			  this.playerPosition = nextPosition  			    
  			  }
  			}
  		}
  	}  
  },
  jumpToContribution: function(position) {
	  var nextUrl = this.urlPrefix + this.contributionIds[position] + ".js" + this.queryParams
	  new Ajax.Request(nextUrl,{asynchronous:true, evalScripts:true, method:'get'})    
  },
  setPosition: function(id) {
    var index = this.contributionIds.indexOf(id)
    var allIndex = this.allContributionIds.indexOf(id)
    if (index != -1)  { 
      this.playerPosition = index
      this.illegalPlayerPosition = -1
    } else {
      this.illegalPlayerPosition = allIndex
    }
  }
}

/* this is the JW MediaPlayer callback, wrapped up by the AutoPlayer */
function getUpdate(typ,pr1,pr2,pid) {
  AutoPlayer.getUpdate(typ,pr1,pr2,pid)
}


/*Hover Effekt for Calendar*/
function hoverMe(element) {
  var cssClassNames = element.className.split(" "); // TODO vielleicht generischer machen, indem einfach bei whitespace gesplittet wird
  var hoverClass = "hov";
  if (!cssClassNames.include("hov2")) {
    if (cssClassNames.include(hoverClass)) {
      element.className = cssClassNames.without(hoverClass).join(" ");
    }
    else {
      cssClassNames.push(hoverClass);
      element.className = cssClassNames.join(" ");
    }
  }
}

/*Inputs leeren*/
	function clearInput(what, where) {
	//	where.style.color = "#002C52";
		if(where.value == what) where.value = "";
		else where.select();
	}
	
	function fillInput(what, where) {
	//	where.style.color = "#B2B2B2";
		if(where.value == "") where.value = what;
	}

/*Etwas ein- und ausblenden*/
	function showIt(thething) {
		if (document.getElementById(thething).style.display != "none") {
			document.getElementById(thething).style.display = "none";
		}
		else {
			document.getElementById(thething).style.display = "block";
		}
	}

function openLocation(href)
{
    location.href=href;
}