/************************************************************************************
* May 2010, mt
*
* This is called whenever we can detect that the design layout is based on boxes and a 
* defined height is given.
* While rendering boxes with a fixed height, we will move some of the sections within
* the layout to another position, as the layout then will appear a bit prettier on boxes
* with differences in descriptions length, discounts and variations
*
*
* Could have been done a lot easier fixing by absolute positioning, but it didn't work 
* out in Firefox and Webkit browsere
*
*************************************************************************************/
jQuery(document).ready(function() {//apply on document ready
	

	if(jQuery('.eshop_ng_box_design_class').length) {
		
		/*detect the highest height of rendered boxes
		Array.prototype.max = function () {
		    return Math.max.apply(Math, this);
		};
		var box_max = new Array();
		jQuery('.eshop_ng_box_design_class').each( function() {
			var eshop_ng_id = jQuery(this).attr('id');//locate each box
			var eshop_ng_height = jQuery('#' + eshop_ng_id).eq(0).height();//find height of box
			box_max.push(eshop_ng_height);	
		});
		var eshop_ng_height = box_max.max(); 
		*/
		jQuery('.eshop_ng_box_design_class').each( function() {//if height is set, this class will be set
			try {	
						
				var eshop_ng_id = jQuery(this).attr('id');//locate each box
				var eshop_ng_id_offset = GetTopPosition(eshop_ng_id);
		
				var eshop_ng_height = jQuery('#' + eshop_ng_id).eq(0).height();//find height of box
				var eshop_ng_id_bottom = (eshop_ng_id_offset + eshop_ng_height);
				
				//positioning buy section
				var buy_offset = GetTopPosition('eshop_ng_buy_section_' + eshop_ng_id);//find position of buy section
				var new_buy_offset = ((eshop_ng_id_bottom - buy_offset) - 25);//calculate new top position
				jQuery('#eshop_ng_buy_section_' + eshop_ng_id).css({'position':'relative','top':new_buy_offset + 'px'});
			
				//positioning variation section
				var variation_offset = GetTopPosition('eshop_ng_variation_section_' + eshop_ng_id);
				var variation_length = 0;
				if(variation_offset != 0) {
					//detect how many variationtypes
					variation_length = variationNamesNG[eshop_ng_id].length;//this array is taken from the main js scripting (eshop_ng.js.php)
					var sub_variation = (variation_length * 15);//add some substraction distance
					var new_variation_offset = ((eshop_ng_id_bottom - variation_offset) - 55) - sub_variation;
					jQuery('#eshop_ng_variation_section_' + eshop_ng_id).css({'position':'relative','top':new_variation_offset + 'px'});
			
					/*
					jQuery('select #variation_id').find('option').each(function() {
			                alert(jQuery(this).val());
			        });
			        */
				}
				//positioning url and nr section
				var new_pos_offset = ((eshop_ng_id_bottom - buy_offset) - 25);
				jQuery('#eshop_ng_url_section_' + eshop_ng_id).css({'position':'relative','top':new_pos_offset + 'px'});
				jQuery('#eshop_ng_nr_section_' + eshop_ng_id).css({'position':'relative','top':new_pos_offset + 'px'});
				
			
			}
			catch(e){
				//alert(e.description);
			}
		});
			
			
	}
	/******TOP POSITION *********************/
	function GetTopPosition(id) {
		var pos = jQuery('#' + id).offset();
		return pos.top;
	}


});

