// BACKGROUND SLIDESHOW

var bg_imgs = [];

function slideSwitch() {
	var $active = $( '#slides img.active' );

	if( $active.length == 0 ) {
		$active = $( '#slides img:last' );
	}

	// use this to pull the divs in the order they appear in the markup
	var $next =  $active.next().length ? $active.next() : $( '#slides img:first' );

	// uncomment below to pull the divs randomly
	/*
	var $sibs  = $active.siblings();
	var rndNum = Math.floor( Math.random() * $sibs.length );
	var $next  = $( $sibs[rndNum] );
	*/

	$active.addClass( 'last-active' );

	$next.css( {opacity: 0.0} ).addClass( 'active' ).animate( {opacity: 1.0}, 2555, function() {
		$active.removeClass( 'active last-active' );
	} );
}

// INSERT FLASH

function insertFlash( node, url, width, height, params ) {
	var object, param, key;
	function newParam( name, value ) {
		if( 0 /*@cc_on + 1 @*/ ){
			return ['<param name="', name, '" value="', value, '" />'].join( '' );
		} else {
			param = document.createElement( 'param' );
			param.name = name;
			param.value = value;
			return param;
		}
	}
	if( 0 /*@cc_on + 1 @*/ ) {
		object = ['<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="', width, '" height="', height, '"><param name="movie" value="', url, '" />'];
		if( params ) {
			for( key in params ) {
				if( params.hasOwnProperty( key ) ) {
					object.push( newParam( key, params[key] ) );
				}
			}
		}
		object.push( '</object>' );
		node.innerHTML = object.join( '' );
	}
	else {
		object = document.createElement( 'object' );
		object.type = 'application/x-shockwave-flash';
		object.data = url;
		object.width = width;
		object.height = height;
		if( params ){
			for( key in params ) {
				if( params.hasOwnProperty( key ) ) {
					object.appendChild( newParam( key, params[key] ) );
				}
			}
		}
		while( node.firstChild ) {
			node.removeChild( node.firstChild )
		}
		node.appendChild( object );
	}
}

// NAVIGATION IN PAGBOX

function navPrev( obj, len ) {
	var _jr = $( obj ).next().children();
	var left = parseInt( _jr.css( 'margin-left' ) );
	if( left + len <= 0 ) {
		var full_shift = left + len;
		_jr.animate( { marginLeft: full_shift + 'px' }, 333 );
	}
}
function navNext( obj, len ) {
	var _jr = $( obj ).prev().children();
	var w = parseInt( _jr.width() );
	var left = parseInt( _jr.css( 'margin-left' ) );
	if( left - len > -w ) {
		var full_shift = left - len;
		_jr.animate( { marginLeft: full_shift + 'px' }, 333 );
	}
}

// -------------------------------------------------------------------------------------------------
// DOCUMENT READY
// -------------------------------------------------------------------------------------------------

$( document ).ready( function() {

	// HOVER ON HORIZONTAL MENU : COLOR ANIMATION
	$( "p.h-menu > a" ).not( '.active' ).hover(
		function() { $( this ).stop().animate( { color: "#00ffff" }, { duration: 555 } ); },
		function() { $( this ).stop().animate( { color: "#ffffff" }, { duration: 555 } ); }
	);

	// SHOW LOGIN BOX
	$( '#h-login' ).click( function() {
		if( jQuery.browser.msie ) { $( '#h-loginbox' ).css( { display: 'block' } ) }
		else { $( '#h-loginbox' ).fadeIn( 444 ) }
	} );
	// HIDE LOGIN BOX
	$( '#h-loginbox-x' ).click( function() {
		if( jQuery.browser.msie ) { $( '#h-loginbox' ).css( { display: 'none' } ) }
		else { $( '#h-loginbox' ).fadeOut( 444 ) }
	} )
	
} )