//$.blockUI( { backgroundColor: '#f00', color: '#fff'} );

$().ajaxStart(function() { $( '#loading_page' ).show() } ).ajaxStop(function() { $( '#loading_page' ).hide() } );

$( document ).ready( function()
{
	$( 'ul#nav li a' ).each( function() {
		if( $( this ).attr( 'href' ) == current_url || $( this ).attr( 'href' ) == complete_url || selected_category == $( this ).attr( 'rel' ) ) 
		{
			$( this ).parent().addClass( 'active' );
		}
	} );
	
	if( popup_question ) { $( '#popup_question' ).show(); }
	
	if( popup_question_ok )	{ alert( 'Thank you for your message' ); }
	
	$( '.zebra' ).zebra();
	
	ajaxProduct();
	
	/**
	 * A warning message appears everytime you click an object in the page which has
	 * a warning class attached to it
	 */
	$( '.warning' ).click( function()
	{
		if( ! confirm( 'Are you sure? This cannot be undone!' ) )
		{
			return false;
		}
		
		return true;
	});
});

function openWindow( theURL, winName, features )
{
	window.open( theURL, winName, features );
}

function ajaxProduct()
{
	$( '#product_list a' ).bind( 'click', function( e ) {
			$( '#page' ).load( $( this ).attr( 'href' ) + '/ajax', function() { ajaxProduct(); } );
			return false;
	} );
	
	$( '#prod_name a' ).bind( 'click', function( e ) { $( '#page' ).load( $( this ).attr( 'href' ) + '/ajax', function() { ajaxProduct(); } ); return false; } );
	
	$( '.close_popup_question' ).click( function() { $( '#popup_question' ).hide(); return false; } );
	$( '.show_popup_question' ).click( function() { $( '#popup_question' ).show(); return false; } );
	
	$( '#list a' ).click( function() {
		
		var image = $( this ).attr( 'rel' );

		$('.photo a img').attr( 'src', '/files/products/medium_' + image );
		var href_print = $('.photo a').attr( 'href' ) + '/image/' + image;
		$('.photo a').attr( 'href', href_print );
		$('#print a').attr( 'href', href_print );
	
		return false;
	} );
	
	$( '#enlarge a' ).click( function() { openWindow( $( this ).attr( 'href' ), '', 'scrollbars=yes,width=840,height=760' ); return false; } );
	
	$( '#photo a' ).click( function() { openWindow( $( this ).attr( 'href' ), '', 'scrollbars=yes,width=840,height=760' ); return false; } );
}

