var ie = false;

var preloadThese = new Array(
	'media/images/home.jpg',
	'media/images/bio.jpg',
	'media/images/music.jpg',
	'media/images/clientele.jpg',
	'media/images/press.jpg',
	'media/images/gallery.jpg',
	'media/images/soon.jpg',
	'media/images/blog.jpg',
	'media/images/contact.jpg',
	'media/images/iframe.png'
);

window.onload = function() {
	var preload = new Array();

	for( var x = 0; x<preloadThese.length; x++ ) {
		preload[x] = new Image;
		preload[x].src = preloadThese[x];
	}

	var current = returnAnchor( location.href );
	if( typeof current == 'undefined' ) {
		current = 'home';
	}

	$('bodyImage').src = 'media/images/' + current + '.jpg';

	$$('.navi a').each(
		function( e ) {
			new Event.observe( e, 'click', function( o ) {
				clearAll();
				o.target.className = 'current';
				$('bodyImage').src = 'media/images/' + returnAnchor( o.target.href ) + '.jpg';
				
				loadUpContent( returnAnchor( o.target.href ) );
			} );
			
			new Event.observe( e, 'mouseover', function( o ) {
				$('bodyImage').src = 'media/images/' + returnAnchor( o.target.href ) + '.jpg';

				$$('.current').each(
					function( a ) {
						a.className = 'currentOld';
					}
				);
			} );
			
			if( current == returnAnchor( e.href ) && current != 'home' ) {
				e.className = 'current';
			}
		}
	);

	$$('.navi').each( function( e ) {
		new Event.observe( e, 'mouseleave', function( o ) {
			$$('.currentOld').each(
				function( a ) {
					a.className = 'current';
				}
			);
		} );
	} );

	loadUpContent( current );
}

function clearAll() {
	$$('.navi a').each(
		function( e ) {
			e.className = '';
		}
	);
}

function returnAnchor( href ) {
	var b = href.split('#');

	if( b.length == 2 ) {
		return b[1];
	}
}

function setupContent() {
	var maxy = (typeof window.innerHeight != 'undefined' ? window.innerHeight : document.body.offsetHeight);
	var maxx = (typeof window.innerWidth != 'undefined' ? window.innerWidth : document.body.offsetWidth);
	$('content').style.left = ( ( maxx - 600 ) / 2 ) + 'px';
}

function loadUpContent( target ) {
	if( $('track') ) {
		document.body.removeChild( $('track') );
		var slider1 = null;
	}

	if( target == 'home' || target == 'soon' ) {
		if( $('content') ) {
			document.body.removeChild( $('content') );
		}
	} else {
		if( !$('content') ) {
			var d = document.createElement('div');
			d.id = 'content';
			
			document.body.appendChild( d );
		}

		setupContent();
		
		$('content').innerHTML = '<div style="padding:10px;text-align:center;"><img src="highslide/graphics/loader.gif" /> Please hold while the content loads</div>';
		new Ajax.Updater( 'content', 'engine.php?page=' + target, {
			onComplete: function() {
				var d = document.createElement( 'div' );
				d.style.top = '20px';
				d.style.right = '20px';
				d.style.position = 'absolute';
				d.innerHTML = '<a href="#home">x</a>';
				d.style.fontSize = '20px';
				d.className = 'close';
				
				var e = document.getElementById('content').appendChild( d );

				new Event.observe( e, 'click', function( o ) {
					clearAll();
					o.target.className = 'current';
					$('bodyImage').src = 'media/images/' + returnAnchor( o.target.href ) + '.jpg';
					
					loadUpContent( returnAnchor( o.target.href ) );
				} );
				
				if( !ie ) {
					setupScrollBar();
				} else {
					$('scroll').style.overflow = 'auto';
					$('scroll').style.height = '330px';
				}
			}
		} );
	}
}

window.onresize = function() {
	if( $('content') ) {
		setupContent();

		if( $('track') ) {
			document.body.removeChild( $('track') );
			var slider1 = null;
		}

		if( !ie ) {
			setupScrollBar();
		} else {
			$('scroll').style.overflow = 'auto';
			$('scroll').style.height = '330px';
		}
	}
}

var storePopout;

function showItem( id ) {
	storePopout = window.open( 'store.php?mode=showAlbumInfo&id=' + id, 'DJ Vibe', 'height=400,width=570,scrollbars=yes' );
	
	if( window.focus ) {
		storePopout.focus();
	}
}