var photos_Gal_qty;
var super_Gal_started = false;//czy była już zainicjowana galeria w tym odświeżeniu strony?

var previous_Gal_ID;
var current_Gal_ID;
var current_Gal_ID_null_details = false;
var current_Gal_ID_null_details_hov = false;
var current_Gal_BIG;
var current_Gal_THUMB;
var current_Gal_Title;
var current_order_ID;

var imgAlreadyLoaded = false;

btns_width = 0;
var carWidthMain;// = (photos_Gal_qty*photo_mini_width)+(2*btns_width);
var carWidthInner;// = (photos_Gal_qty*photo_mini_width)+25;

var car_innerWidth;// = photos_Gal_qty * photo_mini_width;
super_gal_MarginLeft = 0;
var car_margin;
current_photo_id = 1;



function super_Gal_select(event,photo_id){
	if ((photos_Gal_Title[photo_id] != '') && (photos_Gal_Descr[photo_id] != '')){
		current_Gal_ID_null_details = false;
	} else if ((photos_Gal_Title[photo_id] != '') && (photos_Gal_Descr[photo_id] == '')){
		current_Gal_ID_null_details = false;
	} else if ((photos_Gal_Title[photo_id] == '') && (photos_Gal_Descr[photo_id] == '')){
		current_Gal_ID_null_details = true;
	}	
	if (current_Gal_ID_null_details == false) new Effect.Move($('bg_fade_descr'), { duration:0.5, x: 0, y: 300, mode: 'absolute' });
	previous_Gal_ID = current_Gal_ID;
	current_Gal_ID = photos_Gal_ID[photo_id];
	current_order_ID = photo_id;
	
	removeAllCssClasses('quick_gal_thumb_id_'+previous_Gal_ID);
	$('quick_gal_thumb_id_'+current_Gal_ID).addClassName('active');//sup_gal_li 
	//alert('previous_Gal_ID : '+previous_Gal_ID+'    , current_Gal_ID  : '+current_Gal_ID);
	
	//ruch na caruzeli
	
	el = $('quick_gal_carousel_inner');
	elDim = el.getDimensions();
	el_ul = $('quick_gal_car');

	var temp_margin_pos = Math.round(elDim.width/2);
	var temp_photo_pos = (photo_mini_width * photos_Gal_ID[photo_id]) - temp_margin_pos;
	
	var h2 = (temp_photo_pos * (-1));	
	el_ul.morph('margin-left:'+h2+'px;');
	
	$('quick_gal_big_photo').setStyle({'background':'url(files/photos/gal_pict_'+current_Gal_ID+'.jpg)'});
	
	if ((photos_Gal_Title[photo_id] != '') && (photos_Gal_Descr[photo_id] != '')){
		$('bg_fade_descr').innerHTML = '<div class="inner"> \
											<h2>'+photos_Gal_Title[photo_id]+'</h2> \
											<hr /> \
											<span>'+photos_Gal_Descr[photo_id]+'</span> \
										</div>';
		current_Gal_ID_null_details = false;
		current_Gal_ID_null_details_hov = false;
		setTimeout(function(){ new Effect.Move($('bg_fade_descr'), { duration:0.5, x: 0, y: 400, mode: 'absolute' });},3000);
		
	} else if ((photos_Gal_Title[photo_id] != '') && (photos_Gal_Descr[photo_id] == '')){
		$('bg_fade_descr').innerHTML = '<div class="inner"> \
											<h2>'+photos_Gal_Title[photo_id]+'</h2> \
										</div>';
		current_Gal_ID_null_details = false;
		current_Gal_ID_null_details_hov = false;
		setTimeout(function(){ new Effect.Move($('bg_fade_descr'), { duration:0.5, x: 0, y: 400, mode: 'absolute' });},3000);
			
	} else if ((photos_Gal_Title[photo_id] == '') && (photos_Gal_Descr[photo_id] == '')){
		$('bg_fade_descr').innerHTML = '';
		$('bg_fade_descr').setStyle({'top':'400px'});
		current_Gal_ID_null_details_hov = true;
		//setTimeout(function(){ new Effect.Move($('bg_fade_descr'), { duration:0.5, x: 0, y: 400, mode: 'absolute' });},3000);		
	}
	
	//setTimeout(function(){ new Effect.Move($('bg_fade_descr'), { duration:0.5, x: 0, y: 400, mode: 'absolute' });},3000);
	super_Gal(current_Gal_ID);
}

function super_Gal_GOTO_photo(photo_id){
	el_ul = $('quick_gal_car');	
	var marginPhoto;
	var photoNr;
	
	for (i=0; i<photos_Gal_qty; i++) {
		if (photos_Gal_ID[i] == photo_id) {
			photoNr = i;	
		}
	}	

	var temp_margin_pos = 258;
	var temp_photo_pos = (photo_mini_width * photoNr) - temp_margin_pos;
	
	var h2 = (temp_photo_pos * (-1));	
	el_ul.setStyle('margin-left:'+h2+'px;');
	
	$('quick_gal_thumb_id_'+current_Gal_ID).addClassName('active');
	//setTimeout(function(){ new Effect.Move($('bg_fade_descr'), { duration:0.5, x: 0, y: 400, mode: 'absolute' });},3000);
	previous_Gal_ID = current_Gal_ID;	
}

function super_Gal_car_right(){
	el = $('quick_gal_carousel_inner');
	elDim = el.getDimensions();
	
	el_ul = $('quick_gal_car');
	var width = el_ul.scrollWidth;
    var height = el_ul.scrollHeight;
	super_gal_MarginLeft = parseFloat(el_ul.getStyle('margin-left'));
	
	if ((super_gal_MarginLeft*(-1)) < (car_innerWidth - elDim.width)) {
		var check = (car_innerWidth - elDim.width) - (super_gal_MarginLeft*(-1));
		if (check < car_margin) {
			var h2 = $(el_ul).getStyle('margin-left');
			h2 = parseFloat(h2) - check;
			$(el_ul).morph('margin-left:'+h2+'px;');
		} else {
			var h2 = $(el_ul).getStyle('margin-left');
			h2 = parseFloat(h2) - car_margin;
			$(el_ul).morph('margin-left:'+h2+'px;');			
		}
	} 

}

function super_Gal_car_left(){
	el = $('quick_gal_carousel_inner');
	el_ul = $('quick_gal_car');
	var width = el_ul.scrollWidth;
    var height = el_ul.scrollHeight;
	super_gal_MarginLeft = parseFloat(el_ul.getStyle('margin-left'));
	
	if (super_gal_MarginLeft != 0) {
		if ((super_gal_MarginLeft*(-1)) < car_margin) {
			h2 = 0;
			$(el_ul).morph('margin-left:'+h2+'px;'); 
		} else {
			var h2 = $(el_ul).getStyle('margin-left');
			h2 = parseFloat(h2) + car_margin;
			$(el_ul).morph('margin-left:'+h2+'px;');
		}
	} 
}


/* ####################################################################################### */
/* ####################################################################################### */
/* ####################   super_Gal_INIT    ################################# */
/* ####################################################################################### */
/* ####################################################################################### */
function super_Gal_INIT(id_photo){
	car_margin = 660;	
	
	photo_mini_width = 83+4;//szerokość zdjęcia w karuseli +4
	photos_Gal_qty = photos_Gal_ID.length;
	
	carWidthMain = (photos_Gal_qty*photo_mini_width);
	carWidthInner = (photos_Gal_qty*photo_mini_width);//+20
	
	car_innerWidth = photos_Gal_qty * photo_mini_width;	

	super_Gal(id_photo);
}


function super_Gal(id_photo){
	current_Gal_ID = id_photo;
	current_Gal_BIG = current_Gal_ID;
	current_Gal_THUMB = current_Gal_ID;	
	
	if (super_Gal_started == false){
		$('quick_gal_big_photo').setStyle({'background':'url(files/photos/gal_pict_'+current_Gal_ID+'.jpg)'});
		super_Gal_GOTO_photo(current_Gal_ID);
		super_Gal_started = true;
	}
}

function viewPort() {
	var h = window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
	var w = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
	
	return { width : w , height : h }
}

function removeAllCssClasses(el) {
	var classArray = $(el).classNames().toArray();
	for (var index = 0, len = classArray.size(); index <len; ++index) {
		$(el).removeClassName(classArray[index]);
	}
} 


