var Wcms = Class.create({
	initialize: function() {
		this.default_kam = "linky";
		this.rolovaci_zoznam = "rol_zoznam";
		this.rolovaci_zoznam_timeout = 1; //cas v sekundach kolko po odideni mysou este zoznam zostane otvoreny
	},
	rolovaciZoznam: function(event,styl,linka,nazov) {
		if ($(this.rolovaci_zoznam)) {
			$(this.rolovaci_zoznam).remove()
		}
		else {
			elem=Event.element(event)
			pozicia=elem.positionedOffset()
			rozmery_objektu=elem.getDimensions()
			x=pozicia.left
			y=pozicia.top+rozmery_objektu.height
			y_mys=Event.pointerY(event)
			
			y=y>y_mys+rozmery_objektu.height?y_mys+rozmery_objektu.height:y;
			
			el=Builder.node('div',{id: this.rolovaci_zoznam},[
                Builder.node('iframe',{src:'http://www.facebook.com/plugins/like.php?href='+linka+'&amp;layout=button_count&amp;show_faces=false&amp;width=65&amp;action=like&amp;colorscheme=light&amp;height=22',scrolling: 'no', frameborder:'0', style:'border: none; overflow:hidden; width:90px; height:23px; margin: 5px; padding: 0;'}),
				Builder.node('ul',{},[
					Builder.node('li',{},[
						Builder.node('a',{href:'javascript:Wcms.pridajOblubenu(\''+nazov+'\',\''+linka+'\');',className:'oblubene',title:l_pridat_od_oblubenych},l_pridat_od_oblubenych)
					]),
					Builder.node('li',{},[
						Builder.node('a',{href:'javascript:location.href=\'http://www.facebook.com/sharer.php?u='+linka+'&t='+nazov+'\';',className:'facebook',title:l_pridat_na+' Facebook.com'},l_pridat_na+' Facebook.com')
					]),
					Builder.node('li',{},[
						Builder.node('a',{href:'javascript:location.href=\'http://vybrali.sme.sk/sub.php?url='+linka+'\';',className:'vybralisme',title:l_pridat_na+' vybrali.sme.sk'},l_pridat_na+' vybrali.sme.sk')
					]),
					Builder.node('li',{},[
						Builder.node('a',{href:'javascript:location.href=\'http://twitter.com/?status='+linka+'\';',className:'twitter',title:l_pridat_na+' twitter.com'},l_pridat_na+' twitter.com')
					]),
					Builder.node('li',{},[
						Builder.node('a',{href:'javascript:location.href=\'http://delicious.com/save?url='+linka+'&title='+nazov+'&share=yes\';',className:'delicious',title:l_pridat_na+' del.icio.us'},l_pridat_na+' del.icio.us')
					]),
					Builder.node('li',{},[
						Builder.node('a',{href:'javascript:location.href=\'http://www.linkedin.com/shareArticle?mini=true&url='+linka+'&title='+nazov+'\';',className:'linkedin',title:l_pridat_na+' linkedin.com'},l_pridat_na+' linkedin.com')
					])
				])
			]);
			$(this.default_kam).appendChild(el);
			
			if (styl) {
				$(this.rolovaci_zoznam).addClassName(styl);
			}
			var zcas
			$(this.rolovaci_zoznam).observe('mouseleave',function(){
				zcas=setTimeout('Wcms.rolovaciZoznam()',(Wcms.rolovaci_zoznam_timeout*1000));
			});
			$(this.rolovaci_zoznam).observe('mouseover',function(){
				clearTimeout(zcas);
			});
			
			this.umiestniPrvok(this.rolovaci_zoznam,x,y);
		}
	},
	umiestniPrvok: function(prvok,x,y) {
		if ($(prvok) && x && y) {
			prvok_sirka=$(prvok).getWidth();
			Okno=getPageSize();
			Posun=getPageScroll();
			x=(x+prvok_sirka)>=Okno[0]+Posun[0]?x-((x+prvok_sirka+25)-(Okno[0]+Posun[0])):x;
			y=y<0?0:y;
			$(prvok).setStyle('top: '+y+'px; left: '+x+'px');
		}
	},
	pridajOblubenu: function(nazov,linka) {
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(nazov, linka,"");
		}
		else if(window.external) { // IE Favorite
			window.external.AddFavorite(linka, nazov);
		}
		else if(window.opera && window.print) { // Opera Hotlist
            var elem = document.createElement('a');
            elem.setAttribute('href',url);
            elem.setAttribute('title',title);
            elem.setAttribute('rel','sidebar');
            elem.click();
            return false;
        }
	},
    skontrolujObsah: function() {
        a_href=$('c_obsah').select('a');
        for (i=0; i<a_href.length; i++) {
            if (a_href[i].href.indexOf(server)<0 && a_href[i].href.indexOf("javascript")<0) {
                a_href[i].title=a_href[i].title+" - "+l_externy_odkaz;
                //a_href[i].innerHTML=a_href[i].innerHTML+" <img src=\"http://www.stuba.sk/new/img/nove_okno.gif\" title=\""+l_externy_odkaz+"\" alt=\""+l_externy_odkaz+"\" />";
            }
        }
    }
});
var Wcms = new Wcms();



//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

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

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

