//----------------------------------------------------------------------------------------------------------------
//										SLIDESHOW
//----------------------------------------------------------------------------------------------------------------
              
$(document).ready(function(){	
	
	//Decode email address
	if ( $("span.emailRewrite").length ) {
	  // variables, which will be replaced
	  var at = / AT /;
	  var dot = / DOT /g;
	
	  // function, which replaces pre-made class
	  $('span.emailRewrite').each(function () {
		var addr = $(this).text().replace(at, '@').replace(dot, '.');
		//$(this).after(addr);
		$(this).after('<a href="mailto:' + addr + '">' + addr + '</a>');
		$(this).remove();
	  });
	}
	
	/* SET TOP SLIDESHOW */
	if( $("#slider ul li").size()>1 ){
		var disableArrows = true;
	}else{
		var disableArrows = false;
	}
	
	$("#slider").easySlider({
		nextText: '',
		prevText: '',
		continuous: true,
		controlsShow: disableArrows	
	});
	
	if($(window).width()<960){
		$("html").css("overflow","auto");
	}
	
	$('input.checkbox').click(function() {
		$('input.checkbox').filter(':checked').not(this).removeAttr('checked');
		if($('input.checkbox').is(':checked')){
			$('input.vote').css('display','block');
		}else{
			$('input.vote').css('display','none');
		}
	});
	
   $('.numeric').keyup(function () { 
		this.value = this.value.replace(/[^0-9,.\.]/g,'');
	});

	if (navigator.appName == 'Microsoft Internet Explorer') {
		if($(document).width()>1280){
			var margin = ($(document).width()-960)/2;
			$('html').css("margin-left",margin+"px");
			$('div#slider').css("margin-left","auto");
			$('div#slider').css("margin-right","auto");
		}
	}
	
});
          
		  
		  $(function() {
        
                function filterPath(string) {
                        return string
                        .replace(/^\//,'')
                        .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
                        .replace(/\/$/,'');
                }
        
                var locationPath = filterPath(location.pathname);
                var scrollElem = scrollableElement('html', 'body');
        
                // Any links with hash tags in them (can't do ^= because of fully qualified URL potential)
                $('a[href*=#]').each(function() {
        
                        // Ensure it's a same-page link
                        var thisPath = filterPath(this.pathname) || locationPath;
                        if (  locationPath == thisPath
                                && (location.hostname == this.hostname || !this.hostname)
                                && this.hash.replace(/#/,'') ) {
        
                                        // Ensure target exists
                                        var $target = $(this.hash), target = this.hash;
                                        if (target) {
        
                                                // Find location of target
                                                var targetOffset = $target.offset().top;
                                                $(this).click(function(event) {
        
                                                        // Prevent jump-down
                                                        event.preventDefault();
        
                                                        // Animate to target
                                                        $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
        
                                                                // Set hash in URL after animation successful
                                                                location.hash = target;
        
                                                        });
                                                });
                                        }
                        }
        
                });
        
                // Use the first element that is "scrollable"  (cross-browser fix?)
                function scrollableElement(els) {
                        for (var i = 0, argLength = arguments.length; i <argLength; i++) {
                                var el = arguments[i],
                                $scrollElement = $(el);
                                if ($scrollElement.scrollTop()> 0) {
                                        return el;
                                } else {
                                        $scrollElement.scrollTop(1);
                                        var isScrollable = $scrollElement.scrollTop()> 0;
                                        $scrollElement.scrollTop(0);
                                        if (isScrollable) {
                                                return el;
                                        }
                                }
                        }
                        return [];
                }
        
        });
  
//----------------------------------------------------------------------------------------------------------------
//	END									SLIDESHOW
//----------------------------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------------------------
//										Show Player
//----------------------------------------------------------------------------------------------------------------
function setVideoPlayer(videoFile,imageFile,divID){
	  playerReady(jwplayer(divID).setup({
		  flashplayer: "mediaplayer/player.swf",
		  file: "files/videos/"+videoFile,
		  image: "files/videos/"+imageFile,
		  width: 763,
		  height: 338
	  }));
}

var players = [];

function playerReady(obj) {
  players.push(document.getElementById(obj.id));
};

function stopAll(){
	if($('video').length>0){ // HTML5 PLAYER
		for(var i=0; i<$('video').length;i++){
			$('video')[i].pause();
		}
	}else{ // FLASH PLAYER
		for (var player in players){
			players[player].sendEvent("STOP");
		}
	}
}
	
//----------------------------------------------------------------------------------------------------------------
//	END									Show Player
//----------------------------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------------------------
//										Show Spot
//----------------------------------------------------------------------------------------------------------------

function displaySpot(ID,nbrSpot){
	stopAll();
	
	for(var i=1; i<=nbrSpot;i++){
		$("img#icon"+i).attr("src",$("img#icon"+i).attr("src").replace("active_",""));
		$("img#icon"+i).removeClass("active");
	}
	
	currentSRC = $("img#icon"+ID).attr("src");
	var newSRC = currentSRC.replace("icons/","icons/active_");
	$("img#icon"+ID).attr("src",newSRC);
	$("img#icon"+ID).addClass("active");
	
	$('div.spotDescription').css("display","none");
	$('div#spot'+ID).css("display","block");
}

function iconOver(ID){
	if($("img#icon"+ID).hasClass('active')===false){
		currentSRC = $("img#icon"+ID).attr("src");
		var newSRC = currentSRC.replace("icons/","icons/active_");
		$("img#icon"+ID).attr("src",newSRC);
	}
}

function iconOut(ID){
	if($("img#icon"+ID).hasClass('active')===false){
		currentSRC = $("img#icon"+ID).attr("src");
		var newSRC = currentSRC.replace("active_","");
		$("img#icon"+ID).attr("src",newSRC);
	}
}
