/* ROOM Javascript page handling 
 *
 * ae nov.2009
*/

$(document).ready(function() {

/* ------- handle menu logo ------- */

$('#menu18 a').css({'background-color' : 'red', 'color' : 'white', 'border' : '1px solid white', 'margin-top' : '2px', 'padding' : '1px 1px 1px 3px', 'line-height' : '12px'});
$('#menu18 a').hover(function() {
$(this).css({'background-color' : '#ddd', 'color' : '#333', 'border' : '1px solid red'});} , function() {
$(this).css({'background-color' : 'red', 'color' : 'white', 'border' : '1px solid white'});}
);

/* ------- handle table click + hover ------- */

// save product description
var prod_descr = $('#prod_description p').html();
var row_clicked = -1;

	$('#qd_BL .stockTable_head tr')
		.livequery('click',function() {
			if ( row_clicked == $(this).parent().children().index($(this)) ) {
				$('#prod_description p').html(prod_descr);
				row_clicked = -1;
			} else {
				$('#prod_description p').html($(this).children('td:last').html());
				$('#prod_description table').show();
				row_clicked = $(this).parent().children().index($(this));
			}
	
			// remove ugly focus outline
			$(this).blur();
	});
	
	// table row hightlight
	$('#qd_BL .stockTable_head tr')
		.livequery('mouseover', function() {
			$(this).addClass('highlight');
			$(this).children('td:last-child').addClass('row_over');
		})
		.livequery('mouseout', function() {
			$(this).removeClass('highlight');
			$(this).children('td:last-child').removeClass('row_over');
		});

/* ------- handle grid ------- */

	// remove href from grid
	$('#qd_BR a:lt(12)').attr( { href: '#' } );

	// grid click, get ajax data
	$('#qd_BR img').click(function(){
		$("#qd_UL img").attr({ src: $(this).attr('src') });		// load image
		$('#prod_description').html( $(this).parent().next().html() );	// load meta data
		prod_descr = $('#prod_description p').html();
		$('#qd_BL h3').text("Loading..");
		$('#progressIndicator').show();
		$("#qd_BL").load("ajaxGet",
   				{ditto_parents: $(this).attr('id')},
   				function() { // callback
//					$("#qd_UL img").attr({ src: $('#ajax_data_img').text() });
//					$('#prod_description').html($('#ajax_data').html());
					$('#progressIndicator').hide(); // done!
   				});
/*		$("#prod_description").load("ajaxGet2",
   				{ditto_documents: $(this).attr('id')},
   				function() { // callback]
   				prod_descr = $('#prod_description').html();
   				$('#progressIndicator').hide(); // done!
   				
   				}); */
   			$('#qd_BR a').blur();
   			return false; // to prevent click thru
 	});

	$('#qd_BR').append('<div id="label"> </div>');

	// populate first cell 
	$('#qd_BR img:first').attr({ src: $('#qd_BR img:eq(1)').attr('src') });
	$('#qd_BR a:first').attr({ href: $('#qd_BR a:eq(1)').attr('href') });
	$('#qd_BR div.meta_data:eq(0)').html( $('#qd_BR img:eq(1)').parent().next().html() );
	$('#label').text( $('#qd_BR img:eq(1)').attr('alt'));

	// mouse over
	$('#qd_BR img:gt(0)').mouseover(function() {
		$('#qd_BR img:first').attr({ src: $(this).attr('src') });
		$('#qd_BR a:first').attr({ href: $(this).parents('a').attr('href') });
		$('#qd_BR div.meta_data:eq(0)').html( $(this).parent().next().html() );
		$('#label').html($(this).attr('alt'));
	}); 

/* ------- slideshow ------- */

	function slideSwitch() {
		var $active = $('#prod_slides IMG.active');
	
		if ( $active.length == 0 ) $active = $('#prod_slides IMG:last');
	
		var $next =  $active.next().length ? $active.next()
			: $('#prod_slides IMG:first');
	
		$active.addClass('last-active');
	
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
			});
	}
	
	var playSlideshow = setInterval( slideSwitch, 6000 );

	$('#prod_slides').hover(	
		function() {
		clearInterval(playSlideshow);
		},
		function() {
		playSlideshow = setInterval( slideSwitch, 6000 );
	});	


}); // end $(document).ready(function() 
