// Persian-designers.ir 
function ulRotator (id, delay, transition)
	{
	this.rotate = function ( closure ) 
		{
		if( closure )
			{
			return (function() {thisObj.rotate();});		
			}
		if( this.id == "" )
			{
			return;	
			}
	
		clearInterval( this.interval );
		this.interval = setInterval( this.rotate( true ) , this.delay);
		
		ulItems = jQuery("#" + this.id + " li");
		ulItems.slice( this.index, this.index + 2 ).animate({left: "-" + this.width + "px", opacity: 'hide'}, this.transition);
		this.index += 2;
		if( this.index >= ulItems.length ) 
			{
			this.index = 0;	
			}
		ulItems.slice( this.index, this.index + 2 ).css('left',this.width).animate({left: 0, opacity: 'show'}, this.transition);
		}
		
	this.mouseOver = function ( closure )
		{
		if( closure )
			{
			return (function() {thisObj.mouseOver();});		
			}	
		clearInterval( this.interval );
		}
		
	
	this.mouseOut = function ( closure )
		{
		if( closure )
			{
			return (function() {thisObj.mouseOut();});		
			}
		this.interval = setInterval( this.rotate( true ) , this.delay);
		}
	

	if( !id ) 
		{
		return;	
		}
	this.id = id;
	this.delay = (delay) ? delay : 8000;
	this.transition = (transition) ? transition : 2000;
	this.width = jQuery("#" + this.id).width();
	this.index = 0;
	var thisObj = this;
	
	ulItems = jQuery("#" + this.id + " li");
	

	largest = 0;
	for( x = 0, ulLength = ulItems.length; x < ulLength; x += 2)
		{
		if( ( ulItems.slice(x, x + 1).height() + ulItems.slice(x + 1, x + 2).height() ) > largest )
			{
			largest = ( ulItems.slice(x, x + 1).height() + ulItems.slice(x + 1, x + 2).height() );
			}
		}

	this.ulHeight = largest + 20;
	jQuery("#" + this.id).height( this.ulHeight );
	
	jQuery("#" + this.id).css("position", "relative");
	ulItems.css("position", "absolute");
	

	lastElementHeight = 0;
	for( x = 0, ulLength = ulItems.length; x < ulLength; x++)
		{
		if( ( x % 2) ==  0 )
			{
			ulItems.slice(x, x + 1).css( "top", 0 );
			lastElementHeight = ulItems.slice(x, x + 1).height();
			}
		else
			{
			ulItems.slice(x, x + 1).css( "top", lastElementHeight + 10 );	
			}
		}
	
	ulItems.slice( this.index + 2 ).hide();
	
	jQuery("#" + this.id).hover( this.mouseOver(true), this.mouseOut(true) );
	

	this.interval = setInterval( this.rotate( true ) , this.delay);
	
	}

function alt_site_menu_init()
	{
	if( typeof(jQuery) == "function" )
		{
	
		newsRotator = new ulRotator( "whats_new_ul" );
		eventsRotator = new ulRotator( "events_ul" );
		}
	}
	
function fixPageHeight()
	{

	pageFooter = jQuery("#page_footer");
	textWrapper = jQuery("#text_wrapper");
	var textHeight =  pageFooter.height() - 320;
	textWrapper.height( textHeight );	
	}
	
if( typeof(jQuery) == "function" )
	{
	jQuery(document).ready( alt_site_menu_init );
	}
	
window.onload = function()
	{
	setTimeout( fixPageHeight, 200 );
	};