$(document).ready(function() {
	if(!menu) menu = 'home';
	//if(menu == 'director') menu = 'directors';
	//$("#header ul.menu li." + menu).css({'background-image': 'url(images/nav_' + menu + '_o.png)'});
	//$.preloadCssImages();
    
    //$("#clientlogin").click(function() {
    //     window.open("login.php","Client Login","location=no");
    //     return false;
    //});

    // init prettyPhoto
    $("a.flashbook").each(function() {
        $(this).attr('rel','prettyPhoto[flash]');
        $(this).attr('href',$(this).attr('href') + "?width=840&height=590");
    });
    
	// open flashbook in extra window
	$('a.flashbook').click(function(){
		width = 840;
		height = 590;
		dx = ($(window).width() / 2) - (width / 2);
		dy = ($(window).height() / 2) - (height / 2);
		properties = "width=" + width + ",height=" + height + ",left=" + parseInt(dx) + ",top=" + parseInt(dy);
		//alert(properties);
		window.open(this.href, "Flashbook", properties );
		return false;
	});
	
	// open flashbook in overlay
	//$("a[rel^='prettyPhoto']").prettyPhoto();
    
	$("#header ul.menu li").click(function() {
		window.location.href = '/' + $(this).attr("class") + ".html";
	});

	$("#rightcol p.abouthead").toggle(function() {
		$("#rightcol div.aboutcontent").slideDown("slow");
		$("#rightcol p.abouthead").addClass("aboutheadup");
	}, function() {
		$("#rightcol div.aboutcontent").slideUp("slow");
		$("#rightcol p.abouthead").removeClass("aboutheadup");
	});
	
	//$("#rightcol div:first").css("height", $("body").innerHeight() + "px");
	$("div.rightcontentbox:last").css("border-bottom", "none");


	// Stuff for the scrollbox
	var items = $("#scrollbox ul li");
	var offset = 0;
	var visible = 3;
	var numitems = items.length;

	items.slice(0,offset).hide();
	items.slice(offset + visible).hide();

	$("#scrollbox p.down").click(function() {
		// rotate the list if the end is reached
		if(offset + visible == numitems) {
			$("#scrollbox ul li:first").appendTo($("#scrollbox ul"));
			items = $("#scrollbox ul li"); // re-index
			offset--; // step back the offset
		}
		// else move the slice
		if(offset + visible < numitems) {
			items.eq(offset).slideUp("slow");
			items.eq(++offset + visible -1).slideDown("slow");
			return false;
		}
	});

	$("#scrollbox p.up").click(function() {
		// rotate the list if the end is reached
		if(offset == 0) {
			$("#scrollbox ul li:last").prependTo($("#scrollbox ul"));
			items = $("#scrollbox ul li"); // re-index
			offset++; // step back the offset
		}
		// else move the slice
		if(offset > 0) {
			items.eq(--offset).slideDown("slow");
			items.eq(offset + visible).slideUp("slow");
		}
		return false;
	});
	
	$("#scrollbox img").click(function() {
		var projectid = $(this).attr("id");
        var type = $(this).attr("class");
        switch(type) {
            case 'video':   $("#stage").load("index.php?do=getvideo&id="+projectid);
                            break;
            case 'slideshow1':   $("#stage").load("index.php?do=getslide&show=1&id="+projectid,initslides);
                            break;
            case 'slideshow2':   $("#stage").load("index.php?do=getslide&show=2&id="+projectid,initslides);
                            break;
        }
        
	});
	// scrollbox end
	
	// initialize multiple slideshow boxes
    initslides();
    
	// initialize top offset of related Links in "others"
	if(menu=="others" || menu=="misc") {
		$("#maincol h1").each(function(index) {
			offsets = $(this).offset();
			//alert(offsets.top);
			$("#rightcol div.rlbox").eq(index).css( 'top', offsets.top+'px' );
		});
	}
	
	if($.browser.mozilla) {
        movies = $("object.video embed");
    } else {
        movies = $("object.video");
    }
	
    for (i=0;i<movies.length;i++) {
		movies[i].SetResetPropertiesOnReload(false);
		movies[i].SetKioskMode(true);
        //movies[i].SetIsLooping(false);
        //movies[i].SetControllerVisible(true);
	}

});

function initslides() {
    var slides = new Array();
    var slideoffset = new Array();
    var numslides = new Array();
    $("div.slidebox").each(function(index) {
        //alert(index);
        $(this).attr('id','slidebox'+index);
        slides[index] = $(this).find("li");
        slideoffset[index] = 0;
        numslides[index] = slides[index].length;
        slides[index].slice(slideoffset[index]+1).hide();
    });
    
    $("a.forward").click(function() {
        index = $(this).parent().prev().attr("id").substr(8);
        //alert("slideoffset="+slideoffset[index]+"; numslides="+numslides[index]);

        if(slideoffset[index] + 1 == numslides[index]) {
            slides[index].eq(slideoffset[index]).hide();
            slideoffset[index] = -1;
        }
        if(slideoffset[index] + 1 < numslides[index]) {
            slides[index].eq(slideoffset[index]).hide();
            slideoffset[index]++;
            slides[index].eq(slideoffset[index]).fadeIn("slow");
        }
        return false;
    });

    $("a.backward").click(function() {
        index = $(this).parent().prev().attr("id").substr(8);
        //alert("slideoffset="+slideoffset[index]+"; numslides="+numslides[index]);
        
        if(slideoffset[index] == 0) {
            slides[index].eq(slideoffset[index]).hide();
            slideoffset[index] = numslides[index];
        }
        if(slideoffset[index] > 0) {
            slides[index].eq(slideoffset[index]).hide();
            slideoffset[index]--;
            slides[index].eq(slideoffset[index]).fadeIn("slow");
        } else index = numslides[index];
        return false;
    });
}                

