/*wymaga event.js*/
//-----------------------------------------------------------------------------
/*Wszystkie linki z rel="external" otwierają się w nowym oknie/zakładce */

function externalLinks()
{
	var external = 'external';
	
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName('a');

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		
		var relAttribute = String(anchor.getAttribute('rel'));		
		if( anchor.getAttribute('href') && relAttribute.toLowerCase().match(external) ){
			anchor.target = "_blank"; 
		}	
	}		
}
function editPage(name){	 
	Shadowbox.open({
        content:    'index.php?template=31&rewrite_name='+name,
        player:     "iframe",
        title:      "Edycja treści",
        height:     450,
        width:      700
    });
}

function editText(lang,group,key,event){	 
	Shadowbox.open({
        content:    'index.php?template=49&lang='+lang+'&grp='+group+'&key_name='+key,
        player:     "iframe",
        title:      "Edycja tekstu",
        height:     450,
        width:      700
    });
}

function editGallery(id){	 
	Shadowbox.open({
        content:    'index.php?template=51&galleryId='+id,
        player:     "iframe",
        title:      "Edycja zdjęć w galerii",
        height:     450,
        width:      700
    });
}

function editFolder(id){	 
	Shadowbox.open({
        content:    'index.php?template=56&folderId='+id,
        player:     "iframe",
        title:      "Edycja plików w folderze",
        height:     450,
        width:      700
    });
}

function editFlatPhoto(name){	 
	Shadowbox.open({
        content:    'index.php?template=66&name='+name,
        player:     "iframe",
        title:      "Edycja planu mieszkania",
        height:     450,
        width:      700
    });
}

function editFlat(id){	 
	Shadowbox.open({
        content:    'index.php?template=69&id='+id,
        player:     "iframe",
        title:      "Edycja mieszkania",
        height:     450,
        width:      700
    });
}

function editInvest(id){	 
	Shadowbox.open({
        content:    'index.php?hideMenu=true&template=85&id='+id,
        player:     "iframe",
        title:      "Edycja treści",
        height:     450,
        width:      800
    });
}

function addInvest( ){	 
	Shadowbox.open({
        content:    'index.php?hideMenu=true&template=85',
        player:     "iframe",
        title:      "Edycja treści",
        height:     450,
        width:      800
    });
}


var gallery_off = false;

function gallery(a,b,photo_list,delay ){
	a = $(a);
	b = $(b);	
	load(a,b,photo_list,1,delay);
}

var current_photo_obj = null;
function showPhoto(id, src, obj){
	if (current_photo_obj)
		current_photo_obj.className = "kwadrat";
	current_photo_obj = $(obj);
	current_photo_obj.className = "kwadrat_on";
	
	gallery_off = true;
	var img = $(id);
	img.src = src;
	img.style.zIndex = 100;	
	obj
}

function load(a,b,photo_list,photo_id,delay){	
	if (!gallery_off){
		var len = photo_list.length;
		if (photo_id >= len) photo_id = 0;
		var add = new Image();
		add.src = photo_list[photo_id];
		add.onLoad = show(a,b,add);
		setTimeout( function(){load(b,a,photo_list,photo_id+1,delay);},delay);
	}
}

function show(destination, add_element, source)
{	
	setOpacity(destination,0);
	destination.style.zIndex = 20;
	destination.src = source.src;
	
	setOpacity(add_element,100);
	add_element.style.zIndex = 10;

	fadeIn(destination,0);
	delete source;
}

function setOpacity(obj, opacity) {
	  opacity = (opacity == 100)?99.999:opacity;
	  
	  // IE/Win
	  obj.style.filter = "alpha(opacity:"+opacity+")";
	  
	  // Safari<1.2, Konqueror
	  obj.style.KHTMLOpacity = opacity/100;
	  
	  // Older Mozilla and Firefox
	  obj.style.MozOpacity = opacity/100;
	  
	  // Safari 1.2, newer Firefox and Mozilla, CSS3
	  obj.style.opacity = opacity/100;
	}

	function fadeIn(obj,opacity) {
	    if (opacity <= 100) {
	      setOpacity(obj, opacity);
	      opacity += 10;
	      window.setTimeout(function(){fadeIn(obj,opacity);}, 75);
	  }
	}

	function fadeOut(obj,opacity) {
	    if (opacity >= 0) {
	      setOpacity(obj, opacity);
	      opacity -= 10;
	      window.setTimeout(function(){fadeOut(obj,opacity);}, 75);
	  }
	}
//-----------------------------------------------------------------------------
function front_init(){
	externalLinks();
}
hookEvent(window,'load',front_init);

