
function theRotator() {
	//Set the opacity of all images to 0
	$('div#content-slide ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#content-slide ul li:first').css({opacity: 1.0});
		
	
	
	//Set the opacity of all images to 0
	$('div#button-slide ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#button-slide ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',4000);
	
}

function rotate() {	

	//var current5 = ($('div#content-slide ul li.hide')?  $('div#content-slide ul li.hide') : $('div#content-slide ul li:first'));
	//var isithidden = ((current5.isithidden().length) ? ((current5.isithidden().hasClass('hide')) ? $('div#content-slide ul li:first') :current5.isithidden()) : $('div#content-slide li:first'));	
	
	//Get the first image
	var current = ($('div#content-slide ul li.show')?  $('div#content-slide ul li.show') : $('div#content-slide ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#content-slide ul li:first') :current.next()) : $('div#content-slide li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	next.removeClass('hide');
	
	
	//Get the first image
	var current2 = ($('div#button-slide ul li.show')?  $('div#button-slide ul li.show') : $('div#button-slide ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next2 = ((current2.next().length) ? ((current2.next().hasClass('show')) ? $('div#button-slide ul li:first') :current2.next()) : $('div#button-slide li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next2.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	//Hide the current image
	current2.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	
};

$(document).ready(function() {		
	//Load the slideshow
	theRotator();
	
});

function inABCities() {
	document.write('<div style="position:absolute;z-index:100;"><a href="#" onfocus="if(this.blur)this.blur()"><img src="bilder/start/cover-slider/btn-hh.gif" width="42" height="30" alt="" class="btn"></a>									<a href="#" onfocus="if(this.blur)this.blur()"><img src="bilder/start/cover-slider/btn-hl.gif" width="42" height="30" alt="" class="btn"></a><a href="#" onfocus="if(this.blur)this.blur()"><img src="bilder/start/cover-slider/btn-mh.gif" width="42" height="30" alt="" class="btn"></a><a href="#" onfocus="if(this.blur)this.blur()"><img src="bilder/start/cover-slider/btn-nbr.gif" width="42" height="30" alt="" class="btn"></a><a href="#" onfocus="if(this.blur)this.blur()"><img src="bilder/start/cover-slider/btn-hro.gif" width="42" height="30" alt="" class="btn"></a><a href="#" onfocus="if(this.blur)this.blur()"><img src="bilder/start/cover-slider/btn-sn.gif" width="42" height="30" alt="" class="btn"></a></div>');
	}
	
	
	
	
	
	/* by Jeremy Keith */
function insertAfter(newElement, targetElement) {
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	}
	else {
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
}

/* http://www.dustindiaz.com/getelementsbyclass/ */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function buttonEndings() {
	if (!document.getElementsByTagName) {
		return false
	}
	
	var buttons = getElementsByClass("buttons");
	/* loop through all buttons and attach a child div */
	for (i=0; i < buttons.length; i++) {
		var div = document.createElement("div");
		div.className = "buttonEnding";
		insertAfter(div, buttons[i]);
	}
}
