function checkInfo()
{
	if( $( 'div#info' ).text() == '' )
		$( 'div#info' ).hide()
} // checkInfo

function showInfo( el )
	{	
		if( $( 'div#' + el + '_info' ).html() != '' )
		{
			$( 'div#info' )
				.fadeIn()
				.append( $( 'div#' + el + '_info' ).html() )
			
			setTimeout( "checkInfo()", 500 )
			
		} // if
		
		else
			$( 'div#info' ).hide()
		
	} // showInfo

function checkForUpdates()
{
	$.getJSON(
		'check_for_updates.php',
		function( json )
		{	
			new_deal = false
			
			for( var x in json )
			{
				if( $( 'div#' + json[x].site + '_info span.product_title' ).text() != json[x].product_title[0] )
				{
					var link = ''
					switch( json[x].site )
					{
						case 'sac':
							link = "http://www.avantlink.com/click.php?tt=cl&amp;mi=10268&amp;pw=30951&amp;url=http%3A%2F%2Fwww.steepandcheap.com%2F";
							break;
						
						case 'wm':
							link = "http://www.avantlink.com/click.php?tt=cl&amp;mi=10269&amp;pw=30951&amp;url=http%3A%2F%2Fwww.whiskeymilitia.com%2F";
							break;
						
						case 'td':
							link = "http://www.avantlink.com/click.php?tt=cl&amp;mi=10062&amp;pw=30951&amp;url=http%3A%2F%2Fwww.tramdock.com%2F";
							break;
						
						case 'cl':
							link = "http://www.avantlink.com/click.php?tt=cl&amp;mi=10271&amp;pw=30951&amp;url=http%3A%2F%2Fwww.chainlove.com%2F";
							break;
						
						case 'bs':
							link = "http://www.avantlink.com/click.php?tt=cl&amp;mi=10417&amp;pw=30951&amp;url=http%3A%2F%2Fwww.brociety.com%2F";
							break;
						
						case 'bt':
							link = "http://www.avantlink.com/click.php?tt=cl&amp;mi=10381&amp;pw=30951&amp;url=http%3A%2F%2Fwww.bonktown.com%2F";
							break;
							
					} // switch
					
					
					$( 'div#' + json[x].site ).fadeOut().fadeIn()
					$( 'div#' + json[x].site + ' a' ).attr( 'href', link )
					$( 'div#' + json[x].site + ' img' ).attr( 'src', json[x].large_image[0] )
					
					$( 'div#' + json[x].site + '_info span.product_title' ).text( json[x].product_title[0] )
					$( 'div#' + json[x].site + '_info span.price' ).text( '$' + json[x].price[0] )
					$( 'div#' + json[x].site + '_info span.reduced' )
						.text( Math.round( ( (json[x].regular[0]-json[x].price[0] )/ json[x].regular[0])*100 ) + '% Off' )
					$( 'div#' + json[x].site + '_info span.original' ).text( 'Originally $' + json[x].regular[0] )
					$( 'div#' + json[x].site + '_info span.site' ).text( json[x].full_name.replace( ' ', '' ) + '.com' )
					
					new_deal = true
				} // if
			} // for
			
			if( new_deal )
				changeTitle()
		} // function
	) // get
} // checkForUpdates

function changeTitle()
{
	document.title = '**' // clear it
	setTimeout( 'document.title = "**"', 1000 ) // 1 second show new deal
	setTimeout( 'document.title = "Hey Gear Whore!"', 2000 ) // 2 seconds clear it
	setTimeout( 'document.title = "**"', 3000) // 3 seconds new deal
	setTimeout( 'document.title = "New Deal!!"', 4000 ) // 4 seconds clear it
	setTimeout( 'document.title = "**"', 5000 ) // 5 seconds back to normal
	setTimeout( 'document.title = "You Gear Whore"', 6000 ) // 6 seconds back to normal
	
} // changeTitle

function stop()
{
	clearInterval( interval )
}

$( document ).ready(
	
	function()
	{
		$( 'div.image_wrapper img' ).hover(
			function()
			{
				//t = setTimeout( "showInfo('" + $( this ).parents( 'div.image_wrapper' ).attr('id') + "')", 750 )
				showInfo( $( this ).parents( 'div.image_wrapper' ).attr( 'id' ) )
			},
			function()
			{
				//clearTimeout( t )
				$( 'div#info' ).hide().empty()
			}
		) // hover
		
		interval = setInterval( "checkForUpdates()", 15000 ) // currently every 15 seconds
		
		// force refresh in case i make changes - every hour
		setTimeout( 'location.reload()', 1000 * 60 * 60 )
		
		/* $( window ).focus( function(){ document.title = 'werd'}) */
		
		$( '#about' )
		.click(
			function()
			{
				if( ! $( this ).hasClass( 'active' ) )
				{
					$( this ).addClass( 'active' )
					$( '#info_and_stuff' ).slideDown( 400 )
				} // if
				
				else
				{
					$( this ).removeClass( 'active' )
					$( '#info_and_stuff' ).slideUp(400)
				} // else
			} // function
		) // click
		
		$( '#info_and_stuff' ).click(
			function()
			{
				$( this ).slideUp( 400 )
				$( '#about' ).removeClass( 'active' )
			}
		)

	} // function
) // ready
