
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
	
    jQuery('#mycarousel').jcarousel({
        auto: null,
        scroll: 1,
		wrap: null,
        initCallback: mycarousel_initCallback
    });
    
    //Calculate contect box position
    var t = jQuery('#messagePopup');
    t.css({
        position:    'absolute', 
        left:        '50%', 
        top:        '50%', 
        zIndex:        '100'
    }).css({
        marginLeft:    '-' + (650 / 2) + 'px', 
        marginTop:    '-' + (500 / 2) + 'px'
    });
	jQuery('#messagePopup').hide();
	
	if(window.location.hash){
		OpenContent(window.location.hash.substr(1));
	}

});

function isIE(){
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}


function OpenContent(gameName){
	gameName = gameName.replace(/ /g, '%20');
	if(gameName=='Paradude'){ gameName='Paradudes'; }
	currentProjectPage=gameName;
	
	jQuery('#messagePopup').show("normal");
	
	var url = 'page.php?project='+gameName;
	$('#messagePopup').load(url);
	
	//Fade bg
	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlayM'></div><div id='TB_window'></div>");
			//	$("#TB_overlayM").click(close_M); IE MESSED THIS UP
			}
	}else{//all others
		if(document.getElementById("TB_overlayM") === null){
			$("body").append("<div id='TB_overlayM'></div><div id='TB_window'>");
			if(isIE()){
				//Sorry IE; you suck
			}else{
				$("#TB_overlayM").click(HideContent);
			}
		}
	}
	
}

function HideContent(){
	jQuery('#messagePopup').hide("normal");
	
	//remove bg
	tb_removeM();
	tb_remove();
}

var projectsArray=new Array();
var currentProjectPage;

function PreviousProject(){
	var nr = GetProjectNr(currentProjectPage)-1;
	if(nr<0){
		nr=projectsArray.length-1;
	}
	OpenContent(projectsArray[nr]);
}
function NextProject(){
	var nr = GetProjectNr(currentProjectPage)+1;
	if(nr>=projectsArray.length){
		nr=0;
	}
	OpenContent(projectsArray[nr]);
}
function GetProjectNr(name){
	for(var i =0;i<projectsArray.length;i++){
		if(projectsArray[i]==name){
			return i;
		}
	}
	alert('error browsing!');
	return -1;	
}

