function tvontop(){ $('#tv').css('z-index','50'); }
function tvback(){ $('#tv').css('z-index','1'); }

function homepageactions()
{
	rootpath=$('#tv a').attr('rel');
	$('.reveal').delay(1000).fadeOut(2000,function() { });
	$("#object2").mouseover(function(e){ $("#tooltipforobject2").css('display','block');});
	$("#object2").mouseout(function(e){ $("#tooltipforobject2").css('display','none');});	

	
	$("#homelinks .homelink img").zoomImgRollover();
	$("#homelinks .homelink img").zoomImgRollover();	
		
	$(".homelink").mouseover(function(e){
			$("#topmenu li#"+$(this).attr('rel')).addClass('highlight');
	});
	$(".homelink").mouseout(function(e){
			$("#topmenu li.highlight").removeClass('highlight'); 
			$("#topmenu li#home").addClass('highlight');
	});	

}

function string_subtract(str1, str2)
{
  var pos = str1.indexOf(str2);
  if( pos == -1 )
    return str1;
  var result = str1.substr(0, pos) + str1.substr(pos + str2.length);
  return result;
}

/*ROTATOR*/
function theRotator() {
	//Set the opacity of all images to 0
	$('div.rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div.rotator 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() {	
	//Get the first image
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));

    if ( current.length == 0 ) current = $('div.rotator 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.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
    //var rndNum = Math.floor(Math.random() * sibs.length );
    //var next = $( sibs[ rndNum ] );
			

	//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');
	
};


var resize_winWidth = $(window).width();

$(function(){


var winWidth = $(window).width(),
winHeight = $(window).height();
var resizeTimeout = '';
var setWrapperPosition = '';

$(window).resize(function(){

onResize = function() {
//The method which sets the LEFT css property which triggers window.resize again and it was a infinite loop
}

//New height and width
var winNewWidth = $(window).width(),
winNewHeight = $(window).height();

// compare the new height and width with old one
if(winWidth!=winNewWidth || winHeight!=winNewHeight)
{
window.clearTimeout(resizeTimeout);
resizeTimeout = window.setTimeout(onResize, 10);
}
//Update the width and height
resize_winWidth = winNewWidth;

$(".slideshow-content").css('width', resize_winWidth);

});
/**************************************************************************/	

var totalSlides = -1; 
var currentSlide = 0;
var contentSlides = "";

 $(document).ready(function(){
   $(".slideshow-content").css('width', resize_winWidth);
   $("#slideshow-previous").click(showPreviousSlide);
   $("#slideshow-next").click(showNextSlide);

   var totalWidth = 0;
   contentSlides = $(".slideshow-content");
   contentSlides.each(function(i){
     totalSlides++;
     //each element is hidden until needed
     $(this).css('left', -100000);  
   });

   //set the position of the first slide
   $(contentSlides[0]).css('left', 0);  

   updateButtons();
 });

function showPreviousSlide()
{
  updateSlides( -1 );
  currentSlide--;
  if (currentSlide < 0) currentSlide = totalSlides; 
  updateButtons();
 }

 function showNextSlide()
 {
   updateSlides( 1 );
   currentSlide++;
   if (currentSlide > totalSlides) currentSlide = 0;   
   updateButtons();
 }

 function updateSlides( direction )
 {
    var scrollAmount = 0;

    var currSlideObj = contentSlides[ currentSlide ];       
    var nextSlideObj = contentSlides[ getNextSlide( direction ) ];

    $( contentSlides ).each( function(){
        if ( this != currSlideObj && this != nextSlideObj ) {
            //each element is hidden until needed
            $(this).css('left', -100000);   
        }
    });

    if ( direction > 0 ) {
        //set the position of the next slide when 'next' pushed
        $( nextSlideObj ).css('left', parseInt($( currSlideObj ).css('left')) + $( currSlideObj ).width());
        //set the amount to animate
        scrollAmount = parseInt($( currSlideObj ).css('left')) - $( currSlideObj ).width();
    } else {
        //set the position of the next slide when 'previous' pushed
        $( nextSlideObj ).css('left', parseInt($( currSlideObj ).css('left')) - $( nextSlideObj ).width());
        //set the amount to animate
        scrollAmount = parseInt($( currSlideObj ).css('left')) + $( currSlideObj ).width();
    }

    // we'll animate the slide objects independently
    $( currSlideObj ).animate({left: scrollAmount}, 1000);
    $( nextSlideObj ).animate({left: 0}, 1000); 

 }

 function getNextSlide( direction ) 
 {
    if ( ( currentSlide + direction ) > totalSlides ) {
        return 0;
    } else if ( ( currentSlide + direction ) < 0 ) {
        return totalSlides;     
    }

    return  currentSlide + direction;

 }

 function updateButtons()
 {
 if(currentSlide < totalSlides) {
   $("#slideshow-next").show();}

 if(currentSlide > 0) {
   $("#slideshow-previous").show();}
   else {
	   $("#slideshow-previous").show();
	   }
 }

	
/*************************************************************************/	
});
