function $GE(element) {
	if (arguments.length > 1) {
		for ( var i = 0, elements = [], length = arguments.length; i < length; i++)
			elements.push($GE(arguments[i]));
		return elements;
	}
	if (typeof element == 'string')
		element = document.getElementById(element);
	return element;
}

function $MYF(element) {
	var element = $GE(element);
	if (element.type == "select-one") {
		value = element.options[element.selectedIndex].value;
		return value;
	}
	return element.value;
}

function $MYS(element, value) {
	var element = $GE(element);
	if (element.type == "select-one") {
		for ( var i = 0; i < element.options.length; i++) {
			if (element.options[i].value == value)
				element.options[i].selected = true;
		}
	} else if (element.type == "checkbox") {
		if (value == 1 || value == true)
			element.checked = true;
		else
			element.checked = false;
	} else {
		element.value = value;
	}
}

function getRealLeft(el) {
	xPos = document.getElementById(el).offsetLeft;
	tempEl = document.getElementById(el).offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

function getRealTop(el) {
	yPos = document.getElementById(el).offsetTop;
	tempEl = document.getElementById(el).offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}


/**
 * Edycja administracyjna
 */

function showEditObject(id) {
	did = "edit-"+id;;
	trueX = getRealLeft(did);
	trueY = getRealTop(did);

	addx = 0
	if(trueX-400 < 0){
		addx = -(trueX-400)
	}
	
	$GE('popup').style.left = (trueX-400+addx)+"px";
	$GE('popup').style.top = trueY+"px";
	popupWindow('popup', true);
	
	var req = mint.Request();
	
    req.OnSuccess  = function(){
    	for(var i = 0; i < this.responseJSON.length; ++i) {
            $MYS('form-id',this.responseJSON[i].id);
            $MYS('form-value',this.responseJSON[i].value_polish);
            $MYS('form-type',this.responseJSON[i].type);
            if(this.responseJSON[i].file){
            	$GE('row-field-view').style.display = '';
            	if(this.responseJSON[i].type == "img"){
            		if(this.responseJSON[i].f_size[0] > 400 )
            			size = 'style="width: 400px"';
            		else
            			size = '';
            		$GE('field-view').innerHTML = '<img src="'+ this.responseJSON[i].file +'" '+size+' />';
            	}
            }
            changeFormDisplay();
        }
    	
    }
    req.getJSON = true;
    req.Send("index.php?arrowDataRequest=5&object=application.AppObject&id="+id+"&template=1");
    
    return false;

}


function SendRequest() {
    var req = mint.Request();
               
    req.OnSuccess = function() {
    	$GE("container-"+$MYF("form-id")).innerHTML = $MYF('form-value').replace( /\n/, "<br />" );
    	popupWindow('popup', false);
    }
    
    if( $MYF('form-type') == "img"  || $MYF('form-type') == "flash" ){
    	$GE("form-obj").submit();
    	return;
    }
               
    req.SendForm("form-obj");
} 


function changeFormDisplay(){
	if( $MYF('form-type') == "img"  || $MYF('form-type') == "flash" ){
		$GE('row-text-title').style.display = 'none';
		$GE('row-text-value').style.display = 'none';
		$GE('row-field').style.display = '';
	}else{
		$GE('row-text-title').style.display = '';
		$GE('row-text-value').style.display = '';
		$GE('row-field').style.display = 'none';
		$GE('row-field-view').style.display = 'none';
	}
	if( $MYF('form-type') == "none"){
		$GE('row-text-title').style.display = 'none';
		$GE('row-text-value').style.display = 'none';
		$GE('row-field').style.display = 'none';
		$GE('row-field-view').style.display = 'none';
	}
}

//-------------------------------------------


function cycle(frame, skipSlide){
	var cycle = function(){ $('#cycle').cycle( frame ); };
	if($('html,body').scrollTop()!=100 && skipSlide != true)
		$('html,body').animate({scrollTop: 0}, { duration: 1000,  complete: cycle });
	else
		cycle(0);
}

function cycle2(frame, skipSlide){
	var cycle = function(){ $('#cycle2').cycle( frame ); };
	if($('html,body').scrollTop()!=100 && skipSlide != true)
		$('html,body').animate({scrollTop: 100}, { duration: 1000,  complete: cycle });
	else
		cycle(0);
} 


function cycle22(frame, skipSlide){
	var cycle = function(){ $('#cycle22').cycle( frame ); };
	if($('html,body').scrollTop()!=100 && skipSlide != true)
		$('html,body').animate({scrollTop: 100}, { duration: 1000,  complete: cycle });
	else
		cycle(0);
} 

 
$(function(){
	$(".pasek3,.pasek33").attr("href", "images/dojazd_mapa.png");
	$(".pasek3,.pasek33").fancybox();
	$(".link3").each(function(){
		if($(this).html() == "powrót »" || $(this).html() == "back »"){
			$(this).css({position: 'absolute', 'bottom': '15px', display: 'block'});
		
		}
	});
	 
});
