/****************************************************************************************/
/*	main.js - Default script															*/
/*	Autore:		Max Kiusso - max AT kiusso DOT net										*/
/*	Data:		2009 11 28																*/
/*	Modified:	2010 01 14																*/
/****************************************************************************************/

if ( self.location == top.location ) {
	self.location.href = '/?ref=' + self.location.href;
}


$ (
	function () {
		mainSize();
		faceSize();
		bodySize();
		btphSize();
		
		$( window ).resize(
			function ( e ) {
				mainSize();
				faceSize();
				bodySize();
				btphSize();
			}
		);
		
		try { $( "#right ul.gallery a" ).lightBox(); } catch (e) {}
		
		if ( $( "#news" ).length ) {
			var summ = 0;
			$( "#news ul li" ).each(
				function () {
					summ += $( this ).outerHeight() + parseInt ( $( this ).css( "margin-bottom" ) );
				}
			);
			
			$( "#news ul li:eq(0)" ).css( { "margin-top": $( "#news ul" ).height() } );
			
			newsStart( summ );
		}
		
		if ( $( "ul.audio" ).length ) {
			$( "ul.audio li" ).click(
				function () {
					$( "ul.audio li" ).removeClass( "click" );
					$( this ).addClass( "click" );
					var txt = $( this ).text();
					var sTitle = encodeURIComponent ( txt );
					var sFile  = txt.replace( / /g , "_" ).replace( /[^\w\d]/g , "" ).toLowerCase();
					
					$( "#player" , parent.frames.menu.document ).html(
						"<object type=\"application/x-shockwave-flash\" width=\"400\" height=\"15\" data=\"/music/xspf_player_slim.swf?song_url=/music/" + sFile + ".mp3&autoplay=true&song_title=" + sTitle + "\">" + 
						"<param name=\"movie\" value=\"/music/xspf_player_slim.swf?song_url=/music/" + sFile + ".mp3&autoplay=true&song_title=" + sTitle + "\" />" + 
						"</object>" + 
						""
					);
				}
			);
		}
		
		if ( $( "#scrollLeft" ).length ) {
			$( "#scrollLeft" ).imageScroller();
		}
	}
);

/* Resize main box */
function mainSize () {
	$( "#main" ).height( $( document ).height() );
}

/* Resize main box */
function faceSize () {
	$( "#face" ).height( $( document ).height() - $( "#menu" ).height() );
}

/* Resize body box */
function bodySize () {
	//$( "#left" ).height( $( window ).height() );
	$( "#right" ).height( $( window ).height() );
}

/* Resize left photo box */
function btphSize () {
	try {
		var oset = $( "#left div.btphoto" ).offset();
		$( "#left div.btphoto" ).height( $( window ).height() - oset.top );
	} catch (e) {}
}

function newsStart ( summ ) {
	$( "#news ul li:eq(0)" ).animate(
		  { marginTop: "-" + summ + "px" }
		, 15000
		, "linear"
		, function () {
			$( "#news ul li:eq(0)" ).css( { "margin-top": $( "#news ul" ).height() } );
			
			newsStart( summ );
		}
	);
}
