var new_bool = false;
jQuery(document).ready(function($)
{
	
	$( '.newbtn' ).click(function(){
		if ( !new_bool )
		{
			$( '#horiz_container_outer li a' ).css( 'display', 'none' );
			$( '.new' ).css( 'display', 'block' );
			$( '#new1' ).css( 'display', 'none' );
			$( '#new2' ).css( 'display', 'block' );
			new_bool = true;
		}
		else
		{
			$( '#horiz_container_outer li a' ).css( 'display', 'block' );
			$( '#new1' ).css( 'display', 'block' );
			$( '#new2' ).css( 'display', 'none' );
			new_bool = false;
		}
		$('#horiz_container_outer').horizontalScroll();
		return false;
	});
	
	$("input.buttonCAdd").click(function(){$("#links").load("load.html")});
	
	$('#slider').nivoSlider(
	{
		directionNav:	false,
		controlNav:		false,
		pauseOnHover:	false
	});
	
	$( '#horiz_container_outer li a' ).click(function()
	{
		clear();
		
		changeImage( $( this ).attr( 'rel' ), $( '#path' ).attr( 'value' ) );
		
		return false;
	});
	
	$('#horiz_container_outer').horizontalScroll();
});

function clear()
{
	$( '.col1' ).html( '' );
	$( '.col2' ).html( '' );
	$( '#detail a' ).attr( 'href', '' ).css( 'display', 'none' );
	$( '#model' ).html( '' );
	$( '#size' ).html( '' );
	$( '#description' ).html( '' );
}

function changeImage( id, url )
{
	$.getJSON( url + '?pid=' + id + '&amp;rand=' + Math.round( new Date().getTime() ), function( data )
	{
		//alert( data['face'] + '<br/>' + data['back'] + '<br/>' + data['detail'] + '<br/>' + data['info'] );
		$( '.col1' ).html( '<img src="'+data['face']+'" title="Model: '+data['title']+'" alt="Model: '+data['title']+'" />' );
		$( '.col2' ).html( '<img src="'+data['back']+'" title="Model: '+data['title']+'" alt="Model: '+data['title']+'" />' );
		$( '#detail a' ).attr( 'href', data['detail'] );
		if ( data['detail'] != '' )
			$( '#detail a' ).css( 'display', 'inline' );
		else
			$( '#detail a' ).css( 'display', 'none' );
		$( '#detail a' ).fancybox();;
		$( '#model' ).html( data['title'] );
		$( '#size' ).html( data['size'] );
		$( '#description' ).html( data['info'] );
		link = $( '#url' ).attr( 'value' ) + '#/' + id;
		$( '#copyLink a' ).attr( 'href', link );
		$( '#sendModel a' ).attr( 'href', "mailto:?body=" + link );
	});
}

/*
var scrollSpeed = 2;

function moveLeft()
{
	document.getElementById('thumbs').scrollLeft-=scrollSpeed;
	moveLeftMark=setTimeout("moveLeft()",scrollSpeed);
}

function moveRight()
{
	document.getElementById('thumbs').scrollLeft-=-scrollSpeed;
	moveRightMark=setTimeout("moveRight()",scrollSpeed);
}
*/
//clear();


$.address.init(function(event) {
  $('#horiz_container_outer li a').address(function() {
      return $(this).attr('rel').replace( location.pathname, '' );
  });
}).change(function(event) {
  clear();
  urlID = event.value.split("/");
  var pid = ( event.value.length > 1 ) ? urlID[1] : $( '#pid' ).attr( 'value' );
		//alert(id);
  if ( pid != undefined )
	{
		changeImage( pid, $( '#path' ).attr( 'value' ) );
	}
});

