var minWidth = 146;
var minHeight = 146;

var bigWidth = 512;
var bigHeight = 512;

var animateSpeed = 1000;

var selectedId = 'item-4';

function insertTextFromID(id) {
	var contentId = '#' + id + '-content';

	$('.jScrollPaneDrag').mouseup();
	
	$('#hi-content').removeClass("small");

	$('#hi-container').html( $( contentId ).html() );

	if ( $('#hi-container').height() < 211 ) {
		$('#hi-content').addClass("small");
	}

	$('.scroll-pane').jScrollPane( {showArrows:true, scrollbarOnLeft:true} );
	$('.scroll-pane')[0].scrollTo(0);
}

function prepareTransition(elem) {
	returnObject();
	
	$('.swipe-holder', elem).removeClass("overflowing");	
}

function returnObject() {
	if ( selectedId == 'item-1' ) {
		$('#' + selectedId).animate({
			left: '193px',
			top: '-81px'
		}, animateSpeed);
	}
	else if ( selectedId == 'item-2' ) {
		$('#' + selectedId).animate({
			left: '-41px',
			top: '175px'
		}, animateSpeed);	
	}
	else if ( selectedId == 'item-3' ) {
		$('#' + selectedId).animate({
			left: '292px',
			top: '210px'
		}, animateSpeed);
	}
	else if ( selectedId == 'item-4' ) {
		$('#' + selectedId).animate({
			left: '83px',
			top: '62px'
		}, animateSpeed);
	}


	$('#' + selectedId + ' img').animate({
		height: minHeight,
		width: minWidth
	}, animateSpeed);

/* 	$('#' + selectedId + ' div.link-text').removeClass("noborder"); */

	$('#' + selectedId + ' div.link-text').animate({
		top: 0
	}, animateSpeed);

}

function handleFocus(id) {
	$('.promo div.art div a,.promo div.art div img').unbind();

	$('.swipe-holder').addClass("overflowing");

	returnObject();
	
	if ( id == 'item-1' ) {
		$('#item-1').css("z-index", '400');
		$('#item-2').css("z-index", '403');
		$('#item-3').css("z-index", '403');
		$('#item-4').css("z-index", '403');
	}
	else if ( id == 'item-2' ) {
		$('#item-1').css("z-index", '403');
		$('#item-2').css("z-index", '400');
		$('#item-3').css("z-index", '403');
		$('#item-4').css("z-index", '403');
	}
	else if ( id == 'item-3' ) {
		$('#item-1').css("z-index", '403');
		$('#item-2').css("z-index", '403');
		$('#item-3').css("z-index", '400');
		$('#item-4').css("z-index", '403');
	}
	else if ( id == 'item-4' ) {
		$('#item-1').css("z-index", '403');
		$('#item-2').css("z-index", '403');
		$('#item-3').css("z-index", '403');
		$('#item-4').css("z-index", '400');
	}
		
	$( '#' + id ).animate({
		left: 696 - bigWidth,
		top: -146
	}, animateSpeed );
	
	$('#' + id + ' div.link-text').animate({
		top: 136
	}, animateSpeed);


	$( '#' + id + ' img' ).animate({
				height: bigHeight,
				width: bigWidth		
			},
			animateSpeed,
			function() {
						insertTextFromID(id);
						selectedId = id;
						bindPromoElements();
					 }
	);

 

}

function bindPromoElements() {
	$('.promo div.art div a').bind(
		'mouseover',
		function(event)
		{
			if ( $(this).parent().parent().attr('id') != selectedId ) {
				handleFocus($(this).parent().parent().attr('id'));
			}
		}
	);
	$('.promo div.art div img').bind(
		'mouseover',
		function(event)
		{
			if ( $(this).parent().attr('id') != selectedId ) {
				handleFocus($(this).parent().attr('id'));
			}
		}
	);


}



$(document).ready(function() {

   

})
