// JavaScript Document

$(document).ready(function() {	
						   
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		//OLD//document.getElementById('website').setAttribute('wmode', 'opaque');
		//OLD//$("object").append('<param name="wmode" value="opaque">');
		//OLD//$("object").attr("wmode", "opaque");

		$('#website').css('visibility', 'hidden');
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(document).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeTo("fast",0.9);			
		/*$('#mask').fadeIn(10);	
		$('.window').fadeIn(10);	*/

	
		//Get the window height and width
		var winH = $(document).height();
		var winW = $(document).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(10);

		  scroller  = new jsScroller(document.getElementById("c_mentions"), 500, 440);		  
		  scrollbar = new jsScrollbar (document.getElementById("Scrollbar-Container"), scroller, true, scrollbarEvent); 

	});
	
	//if close button is clicked	
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		$('#website').css('visibility', 'visible');
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();		
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$('#website').css('visibility', 'visible');
		$(this).hide();
		$('.window').hide();
	});			
	
});


var scroller  = null;
var scrollbar = null;

function scrollbarEvent (o, type) {
	if (type == "mousedown") {
		if (o.className == "Scrollbar-Track") o.style.backgroundColor = "";
		else o.style.backgroundColor = "";
	} else {
		if (o.className == "Scrollbar-Track") o.style.backgroundColor = "";
		else o.style.backgroundColor = "";
	}
}

function swapIt(o) {
	o.blur();
	if (o.className == "current") return false;
  
	var list = document.getElementById("Navigation").getElementsByTagName("a");
	for (var i = 0; i < list.length; i++) {
		if (list[i].className == "current") {
			list[i].className = "";
			document.getElementById(list[i].title).y = -scroller._y;
		}
		if (list[i].title == o.title) o.className = "current";
	}
  
	list = document.getElementById("Container").childNodes;
	for (var i = 0; i < list.length; i++) {
		if (list[i].tagName == "DIV") list[i].style.display = "none";
	}
  
	var top = document.getElementById(o.title);
	top.style.display = "block";
	scrollbar.swapContent(top);
	if (top.y) scrollbar.scrollTo(0, top.y);
  
	return false;
}
