var _tickLength = 300;
var _newsTimer;
var defaultWidth = 195;//242
var minWidth = 160;//160
var maxWidth = 331;//488
//var curSizeArray = new Array( defaultWidth, defaultWidth, defaultWidth, defaultWidth );
//var newSizeArray = new Array( new valueObj(defaultWidth), new valueObj(defaultWidth), new valueObj(defaultWidth), new valueObj(defaultWidth) );
//var newSizeArray = new Array( new Object(value=defaultWidth), defaultWidth, defaultWidth, defaultWidth );
var selectedCell = -1;

var mainCells;
	
var cells;

//var tweenIntArray = new Array(defaultWidth, defaultWidth, defaultWidth, defaultWidth);
//var tweenIntArray = new Array( new valueObj(defaultWidth), new valueObj(defaultWidth), new valueObj(defaultWidth), new valueObj(defaultWidth) );
var tweenIntArray = new Array( {value:defaultWidth}, {value:defaultWidth}, {value:defaultWidth}, {value:defaultWidth}, {value:defaultWidth} );
//¡ö
var debugArray = new Array();

/*function valueObj(p_default){
	
	this.value = p_default;	
	
}*/

function tick(){
	
	clearTimeout( _newsTimer );
	
	tweenFrame();
	
	_newsTimer = setTimeout( 'tick()', _tickLength );
		
}

function tweenFrame(){
	
	var from = curSizeArray[selectedCell];
	var to = newSizeArray[selectedCell];
	
}

function setWidths(p1, p2, p3, p4, P5){
	
	/*$(debugArray[0]).text(p1);
	$(debugArray[1]).text(p2);
	$(debugArray[2]).text(p3);
	$(debugArray[3]).text(p4);
	$(debugArray[4]).text(p5);*/
	
	
	
	
}

$(document).ready(function(){
	$('#interact .markup').hide();
	$('#interact .cell>span').hide();
	
	$('#interact').css('maxWidth', '976px');
	
	
	
	
	mainCells = $('#interact .cell');
	
	resizeElements();
	
	/*debugArray.push( $("#cellA h2") );
	debugArray.push( $("#cellB h2") );
	debugArray.push( $("#cellC h2") );
	debugArray.push( $("#cellD h2") );
	debugArray.push( $("#cellE h2") );	   
	setWidths(1, 2, 3, 4, 5);*/
	
	$('#interact').bind('mouseleave',function(){
											  
		//tweenIntArray = new Array( {value:defaultWidth}, {value:defaultWidth}, {value:defaultWidth}, {value:defaultWidth} );
		JSTweener.removeAllTweens();
		//resizeStart();
		//resizeElements();
		
		//tweenIntArray = new Array( {value:defaultWidth}, {value:defaultWidth}, {value:defaultWidth}, {value:defaultWidth} );
		
		cells = $('#interact .cell');
		//alert(cells.length);
		
		selectedCell = -1;
		
		for ( i=0; i<cells.length; i++ ){
		
			JSTweener.addTween( tweenIntArray[i], {
				time: 0.6,
				transition: 'easeInOutQuintFloor', //easeNoneFloor
				value: defaultWidth,
				onUpdate: resizeElements,
				onStart: resizeStart  						
			});
			
		}
											  
	});
	
	
		
	$('#interact .cell').bind('mouseenter',function(){				
		
		cells = $(this).parent().children('.cell');
		
		var thisID = $(this).attr("id");		
		
		JSTweener.removeAllTweens();
		
		var tweenNeeded = true;
		
			
		for ( i=0; i<cells.length; i++ ){
			
			if (i!=cells.length-1){
			
				if ( thisID==$( cells[i] ).attr("id") ){
				
					selectedCell = i;				
					
					JSTweener.addTween( tweenIntArray[i], {
						time: 0.6,
						transition: 'easeInOutQuintFloor', //easeNoneFloor
						value: maxWidth						
					});
					
				}else{
					
					JSTweener.addTween( tweenIntArray[i], {
						time: 0.6,
						transition: 'easeInOutQuintFloor', //easeNoneFloor
						value: minWidth  						
					});				
					
				}
			
			}else{
				
				if ( thisID==$( cells[i] ).attr("id") ){
				
					selectedCell = i;				
					
					JSTweener.addTween( tweenIntArray[i], {
						time: 0.6,
						transition: 'easeInOutQuintFloor', //easeNoneFloor
						value: maxWidth,
						onUpdate: resizeElements,
						onComplete: resizeFinished,
						onStart: resizeStart
					});
					
				}else{
					
					JSTweener.addTween( tweenIntArray[i], {
						time: 0.6,
						transition: 'easeInOutQuintFloor', //easeNoneFloor
						value: minWidth,
						onUpdate: resizeElements,
						onComplete: resizeFinished,
						onStart: resizeStart  						
					});				
					
				}
				
			}
			
		}
		
		
	});
	
	if ('\v'!='v'){
		setupAdverts();
	}
	
});

function setupAdverts(){
	
	$('#adverts a img').css("opacity", 0.6);
	
	$('#adverts a img').bind('mouseenter',function(){
													
		//$(this).css("opacity", 1);
		$(this).fadeTo( 400, 1 );
													
	});
	
	$('#adverts a img').bind('mouseleave',function(){
													
		//$(this).css("opacity", 0.7);												
		$(this).fadeTo( 250, 0.6 );
		
	});
	
}

function resizeElements(){
	
	changeWidths();
		
}

function resizeStart(){
	
	$('#interact').children(".cell").children(".markupHolder").children(".markup").slideUp('normal');
	$('#interact').children(".cell").children("span").slideUp('normal');
	
}

function resizeFinished(){
	
	for (i=0; i<5; i++){//¡ö
		
		
		if ( selectedCell!=-1){
			
			tweenIntArray[i].value = (selectedCell==i) ? maxWidth : minWidth;	
			
		}else{
			
			tweenIntArray[i].value = defaultWidth;
			
		}
		
		
		
		if ( selectedCell==i ){
			
			$( cells[i] ).children(".markupHolder").children(".markup").slideDown('fast');
			$( cells[i] ).children("span").slideDown('fast');
			
		}
		
		/*try{
			console.log( i + " ---> " + tweenIntArray[i].value );
		}catch(err){
				
		}*/
		
	}
	
	
	
	
	resizeElements();
	
	
	
}



function changeWidths(){
	
	//console.log("changeWidths:- " + tweenIntArray[0].value + " - " + tweenIntArray[1].value + " - " + tweenIntArray[2].value + " - " + tweenIntArray[3].value);
	/*$(mainCells[0]).width(tweenIntArray[0].value);
	$(mainCells[1]).width(tweenIntArray[1].value);
	$(mainCells[2]).width(tweenIntArray[2].value);
	$(mainCells[3]).width(tweenIntArray[3].value);*/
	
	/*mainCells[0].width(tweenIntArray[0].value);
	mainCells[1].width(tweenIntArray[1].value);
	mainCells[2].width(tweenIntArray[2].value);
	mainCells[3].width(tweenIntArray[3].value);*/
	
	/*$(mainCells[0]).children('.markupHolder').children('h2').width( ( parseInt(tweenIntArray[0].value) - 20 )  + "px" );
	$(mainCells[1]).children('.markupHolder').children('h2').width( ( parseInt(tweenIntArray[1].value) - 20 )  + "px" );
	$(mainCells[2]).children('.markupHolder').children('h2').width( ( parseInt(tweenIntArray[2].value) - 20 )  + "px" );
	$(mainCells[3]).children('.markupHolder').children('h2').width( ( parseInt(tweenIntArray[3].value) - 20 )  + "px" );*/
	
//¡ö
	$(mainCells[0]).children('.markupHolder').width( ( parseInt(tweenIntArray[0].value) )  + "px" );
	$(mainCells[1]).children('.markupHolder').width( ( parseInt(tweenIntArray[1].value) )  + "px" );
	$(mainCells[2]).children('.markupHolder').width( ( parseInt(tweenIntArray[2].value) )  + "px" );
	$(mainCells[3]).children('.markupHolder').width( ( parseInt(tweenIntArray[3].value) )  + "px" );
	$(mainCells[4]).children('.markupHolder').width( ( parseInt(tweenIntArray[4].value) )  + "px" );

	$(mainCells[0]).css("width", tweenIntArray[0].value + "px" );
	$(mainCells[1]).css("width", tweenIntArray[1].value + "px" );
	$(mainCells[2]).css("width", tweenIntArray[2].value + "px" );
	$(mainCells[3]).css("width", tweenIntArray[3].value + "px" );
	$(mainCells[4]).css("width", tweenIntArray[4].value + "px" );
	
	
	
	
	//console.log( " ----> " + $(mainCells[0]).children('.markupHolder').children('h2').width() + ", " +  $(mainCells[1]).children('.markupHolder').children('h2').width() + ", " +  $(mainCells[2]).children('.markupHolder').children('h2').width() + ", " +  $(mainCells[3]).children('.markupHolder').children('h2').width() );
	
	
	
	
	
	
	
	
	/*$(mainCells[1]).width(tweenIntArray[1].value);
	$(mainCells[2]).width(tweenIntArray[2].value);
	$(mainCells[3]).width(tweenIntArray[3].value);
	$(mainCells[4]).width(tweenIntArray[4].value);*/
	
	//console.log( $(mainCells[0]).width() );
	
	//console.log( $(mainCells[0]).children('.markupHolder').children('h2') );
	
	/*$(mainCells[0]).children('.markupHolder h2').width(tweenIntArray[0].value + "px" );
	$(mainCells[1]).children('.markupHolder h2').width(tweenIntArray[1].value + "px" );
	$(mainCells[2]).children('.markupHolder h2').width(tweenIntArray[2].value + "px" );
	$(mainCells[3]).children('.markupHolder h2').width(tweenIntArray[3].value + "px" );*/	
	
	
}






