window.addEvent('load', function () {
	
	if ($('panes')) 
	{
		myTabs = new SlidingTabs(false, 'panes');
	
		// this sets up the previous/next buttons, if you want them
		if ($('arrow-left-link')) $('arrow-left-link').addEvent('click', myTabs.previous.bind(myTabs));
		if ($('arrow-right-link')) $('arrow-right-link').addEvent('click', myTabs.next.bind(myTabs));
		
		// this sets it up to work even if it's width isn't a set amount of pixels
		window.addEvent('resize', myTabs.recalcWidths.bind(myTabs));
		$('panes').setStyle('visibility', 'visible');
		
	}
	if ($('left-characters'))
	{
		MM_preloadImages('images/alexa_scully-over.png', 'images/alonzo_bell-over.png', 'images/cecil_bratano-over.png', 'images/chooch_sandoval-over.png', 'images/juan_chacon-over.png', 'images/ophelia_love-over.png', 'images/ricky_ross-over.png', 'images/shane_scully-over.png');
		
	}
	if ($('right-home'))
	{
		MM_preloadImages('images/book-tour-over.png', 'images/character_profile-over.png', 'images/sweep-stakes-over.png', 'images/excerpts-over.png');
	}
	if ($('content1'))
	{
		makeScrollbar( $('content1'), $('scrollbar1'), $('handle1'), $('arrow-up1'), $('arrow-down1') );
	}
	
	var flashvars = {  };
	var params = {wmode: 'transparent'};
	var attributes = {};

	swfobject.embedSWF("01-home.swf", "flashHomeContainer", "480", "270", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
});

function makeScrollbar(content,scrollbar,handle, arrowUp, arrowDown, horizontal,ignoreMouse){
	
	var steps = (horizontal?(content.getSize().scrollSize.x - content.getSize().size.x):(content.getSize().scrollSize.y - content.getSize().size.y));
	
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			// Scrolls the content element in x or y direction.
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
		}
	}).set(0);
	
	var upPeriodical;
	var downPeriodical;
	arrowUp.addEvent('mouseover', function(e){  upPeriodical = (function(){
													if(this.step <= 0) $clear(upPeriodical);
													this.step = this.step - 5;
													if (this.step < 0) this.step = 0;
													this.set(this.step);
												}).periodical(1, slider);
										   });
	arrowUp.addEvent('mouseleave',function(){ $clear(upPeriodical); });
	arrowDown.addEvent('mouseover', function(e){ 
											 	downPeriodical = (function(){
													if(this.step == this.options.steps) $clear(downPeriodical);
													this.step = this.step + 5;
													if (this.step > this.options.steps) this.step = this.options.steps;
													this.set(this.step);
												}).periodical(1, slider);
											});
	arrowDown.addEvent('mouseleave',function(){ $clear(downPeriodical); });
	
	if( !(ignoreMouse) ){
		// Scroll the content element when the mousewheel is used within the 
		// content or the scrollbar element.
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
	}
	// Stops the handle dragging process when the mouse leaves the document body.
	$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}


function varDump(variable, maxDeep)
{
        var deep = 0;
        var maxDeep = maxDeep || 5;

        function fetch(object, parent)
        {
                var buffer = '';
                deep++;

                for (var i in object) {
                        if (parent) {
                                objectPath = parent + '.' + i;
                        } else {
                                objectPath = i;
                        }

                        buffer += objectPath + ' (' + typeof object[i] + ')';

                        if (typeof object[i] == 'object') {
                                buffer += "\n";
                                if (deep < maxDeep) {
                                        buffer += fetch(object[i], objectPath);
                                }
                        } else if (typeof object[i] == 'function') {
                                buffer += "\n";
                        } else if (typeof object[i] == 'string') {
                                buffer += ': "' + object[i] + "\"\n";
                        } else {
                                buffer += ': ' + object[i] + "\n";
                        }
                }

                deep--;
                return buffer;
        }

        if (typeof variable == 'object') {
                return fetch(variable);
        }

        return '(' + typeof variable + '): ' + variable + "\n";
}
