String.prototype.reverse = function(){
	splitext = this.split('');
	revertext = splitext.reverse();
	reversed = revertext.join('');
	return reversed;
}

function slideSwitch() {
	var $active = $('#yui-sldshw-displayer2 DIV.yui-sldshw-active');

	if ( $active.length == 0 ) {
		$active = $('##yui-sldshw-displayer2 DIV:first');
	}

	var $next = $active.next('DIV').length ? $active.next('DIV') : $('#yui-sldshw-displayer2 DIV:first');

	//	$(this).animate({ dummy: 1 }, duration);
	$active.fadeOut(500, function(){
		$active.removeClass('yui-sldshw-active')
		$active.addClass('yui-sldshw-cached');
	})
	
	$next.fadeIn(1300, function(){
		$next.removeClass('yui-sldshw-cached')
		$next.addClass('yui-sldshw-active');
	})
	
	//	Highlight current position
	current_slideshow =  parseInt($next.attr('id').reverse());
	$("img[id^='navigation']").each(function(i){
		if ($(this).attr('id') == 'navigation_' + current_slideshow) {
			//$("img[id='navigation_1']").css('border', '2px solid #005fdc');
			$(this).css('border', '2px solid #005fdc');
		}
		else {
			$(this).css('border', '');
		}
	});
}

function slideSwitch_(switchSpeed) {
	var $active = $('#yui-sldshw-displayer2 DIV.yui-sldshw-active');

	if ( $active.length == 0 )
		$active = $('##yui-sldshw-displayer2 DIV:first');
	var $next = $active.next('DIV').length ? $active.next('DIV') : $('#yui-sldshw-displayer2 DIV:first');
	$next.css({opacity: 0.0})
		.removeClass('yui-sldshw-cached')
		.animate({opacity: 1.0}, 500, function() {
			$active.removeClass('yui-sldshw-active')
			$active.addClass('yui-sldshw-cached')
		})
		.addClass('yui-sldshw-active');
}

function goto_slideshow(id) {
	clearInterval(slide_pictures);

	$("div[id^='frame_slide']").each(function(i){
		if ($(this).attr('id') == 'frame_slide' + id) {
			$(this).css('display', 'block');
			$(this).attr("class", 'yui-sldshw-active');
		}
		else {
			$(this).css('display', 'none');
			$(this).attr("class", 'yui-sldshw-cached');
		}
	});
	
	slide_pictures = setInterval ( "slideSwitch()", 4000 );

//	activate_slideshow(id);
//	slideshow2.set_current_frame(document.getElementById('frame_fd'+id+'slide'));
}


function activate_slideshow(id) {		
	switch(id){
		case 1:
			document.getElementById('frame_slide1').className='yui-sldshw-active';
			document.getElementById('frame_slide1').style.display  ='block';
			document.getElementById('frame_slide2').className='yui-sldshw-cached';
			document.getElementById('frame_slide3').className='yui-sldshw-cached';
			document.getElementById('frame_slide4').className='yui-sldshw-cached';
			document.getElementById('frame_slide5').className='yui-sldshw-cached';
		break;
		
		
		case 2:
			document.getElementById('frame_slide1').className='yui-sldshw-cached';
			document.getElementById('frame_slide2').className='yui-sldshw-active';
			document.getElementById('frame_slide2').style.display  ='block';
			document.getElementById('frame_slide3').className='yui-sldshw-cached';
			document.getElementById('frame_slide4').className='yui-sldshw-cached';
			document.getElementById('frame_slide5').className='yui-sldshw-cached';
		break;
		
		case 3:
			document.getElementById('frame_slide1').className='yui-sldshw-cached';
			document.getElementById('frame_slide2').className='yui-sldshw-cached';
			document.getElementById('frame_slide3').className='yui-sldshw-active';
			document.getElementById('frame_slide3').style.display  ='block';
			document.getElementById('frame_slide4').className='yui-sldshw-cached';
			document.getElementById('frame_slide5').className='yui-sldshw-cached';
		break;
		
		case 4:
			document.getElementById('frame_slide1').className='yui-sldshw-cached';
			document.getElementById('frame_slide2').className='yui-sldshw-cached';
			document.getElementById('frame_slide3').className='yui-sldshw-cached';
			document.getElementById('frame_slide4').className='yui-sldshw-active';
			document.getElementById('frame_slide4').style.display  ='block';
			document.getElementById('frame_slide5').className='yui-sldshw-cached';
		break;
		
		case 5:
			document.getElementById('frame_slide1').className='yui-sldshw-cached';
			document.getElementById('frame_slide2').className='yui-sldshw-cached';
			document.getElementById('frame_slide3').className='yui-sldshw-cached';
			document.getElementById('frame_slide4').className='yui-sldshw-cached';
			document.getElementById('frame_slide5').className='yui-sldshw-active';
			document.getElementById('frame_slide5').style.display  ='block';
		break;
	}
}
	

function init_slideshow() {
	activate_slideshow(1);

	slideshow2 = new YAHOO.myowndb.slideshow("yui-sldshw-displayer2", {effect: YAHOO.myowndb.slideshow.effects.none, interval: 4000});
	slideshow2.loop();
}

function slide(navigation_id, pad_out, pad_in, time, multiplier) {
	// creates the target paths
	var list_elements = navigation_id + " li.sliding-element";
	var link_elements = list_elements + " a";
	
	// initiates the timer used for the sliding animation
	var timer = 0;
	
	// creates the slide animation for all list elements 
	$(list_elements).each(function(i)
	{
		// margin left = - ([width of element] + [total vertical padding of element])
		$(this).css("margin-left","-180px");
		// updates timer
		timer = (timer*multiplier + time);
		$(this).animate({ marginLeft: "0" }, timer);
		$(this).animate({ marginLeft: "15px" }, timer);
		$(this).animate({ marginLeft: "0" }, timer);
	});

	// creates the hover-slide effect for all link elements 		
	$(link_elements).each(function(i)
	{
		$(this).hover(
		function()
		{
			$(this).animate({ paddingLeft: pad_out }, 150);
		},		
		function()
		{
			$(this).animate({ paddingLeft: pad_in }, 150);
		});
	});
}
