var Page = {
	
	refresh_inputs: function() {
		$('.form .form_row input,.form .form_row textarea').each(function(i,element) {
			$(element).focus(function() {
				$('.form_row').each(function(j,row) {
					$(row).removeClass('focus');
				});
				$(element).parent().parent().addClass('focus');
			});
			$(element).blur(function() {
				$(element).parent().parent().removeClass('focus');
			});
		});
	}
	
};

$.extend(String.prototype,{
    strpos: function(ch) {
        for (var i=0; i < this.length; i++) {
            if (this.substring(i,i+1) == ch) 
            return i;
        };
        return -1;
    },
    
    encode: function() {
        return encodeURIComponent(this);
    }
});

$.url = {
    anchor: function() {
        var url = window.location.toString();
		var pos = url.strpos("#");
		if(pos > 0)
		    url = url.substring(pos+1,url.length);
		else
		    return "";
		return url;
    },
    
    before_anchor: function() {
        var url = window.location.toString();
		var pos = url.strpos("#");
		if(pos > 0)
		    url = url.substring(0,pos);
		return url;
    }
};


$.doc = {
    img_counter: 0,
    loaded_f: new Array(),
    
    new_img_loaded: function() {
        this.img_counter++;
        if(this.img_counter == $("img").length)
            this.trigger_loaded();
    },
    
    loaded: function(f) {
        this.loaded_f.push(f);
    },
        
    trigger_loaded: function() {
        for (var i=0; i < this.loaded_f.length; i++) {
            this.loaded_f[i]();
        };
    }
};


$(window).bind('load', function() {
    $("img").each(function(i,element) {
        if($(element).hasClass("fade"))
            $(element).css({opacity:0.01});
        var img = new Image();
        $(img).load(function () {
            if($(element).hasClass("fade"))
                $(element).animate({opacity:1});
            $.doc.new_img_loaded();
            
        }).attr('src', $(element).attr("src"));
    });
});

$(document).ready(function() {
	$('a[rel*=facebox]').facebox() 
});
