var YF = window.YF || {};	

YF.confirmDelete = function(title)
{	
	var yes=confirm(str_delete_confirm+" «" + title + "»?");
	if(yes){ return true; }
	else{ return false; }
}

YF.confirmToggleVisibility = function(title)
{	
	var yes=confirm(str_toggle_visibility_confirm+" «" + title + "»?");
	if(yes){ return true; }
	else{ return false; }
}

YF.doToggle = function(title, id, type)
{
	YF.confirmToggleVisibility(title);
}

YF.doDelete = function(title, id, type)
{
	YF.confirmDelete(title);	
}

YF.yellowfade = function()
{
	var element = $('message');

	if (element){
		var myColorFx = new Fx.Color(element, 'background-color', {duration: 2500});
		myColorFx.toColor('f3f3e3');
	}
}

YF.zebraTables = function()
{
	var rows = $S('table.zebra tr');
	var even = false;
	
	for(var i=0; i < rows.length; i++) {
		var row = rows[i];
		if (even) { row.setStyle('background-color', '#eee'); }
		even = !even;
	}
}

YF.ScrollLinks = {
    currentHash: false,
    start: function(){
        this.scroll = new fx.Scroll({duration: 800, onComplete: function(){YF.ScrollLinks.end();}});
        this.allinks = $$('a');
        for (i=0; i<this.allinks.length; i++){
            var lnk = this.allinks[i];
            if ((lnk.href && lnk.href.indexOf('#') != -1) && ( (lnk.pathname == location.pathname) || ('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search)) {
                lnk.onclick = function(){
                    YF.ScrollLinks.scroll.clearTimer();
                    this.initialHref = this.href;
                    this.initialHash = this.hash;
                    this.href = "javascript:void(0)";
                    setTimeout(function(){this.href = this.initialHref;}.bind(this), 200);
                    ScrollLinks.click(this);
                }
            }
        }
    },

    click: function(link){

        this.currentHash = link.initialHash.substr(1);
        if (this.currentHash) {
            for (j=0; j<this.allinks.length; j++){

                if (this.allinks[j].hash.substr(1) == this.currentHash){

                    if (!window.opera) this.scroll.scrollTo(this.allinks[j].hash.substr(1));
                    else this.scroll.scrollTo(this.allinks[j].hash.substr(1));
                    break;
                }
            }
        }
    },

    end: function(){
        window.location.href = "#"+this.currentHash;
        this.currentHash = false;
    }
}

window.addEvent('load', function(){
	YF.yellowfade();
	YF.ScrollLinks.start();
	YF.zebraTables();
});