var eml = "vasb\100rgnczrqln\056pbz".replace(/[a-zA-Z]/g, function(c){
    return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);
    }),
    emls = '<a href="mailto:%s">%s</a>',
    site_menu = [
        ['@etapmedya', 'http://twitter.com/etapmedya', true],
        ['müşterilerimiz', 'clients'],
        ['teknoloji', 'technology'],
        ['reklam', 'agency-services'],
        ['strateji', 'strategy-services'],
        ['web', 'web-services'],
        ['hakkımızda', 'aboutus']
    ];

function publis_site(initial_page){
	if(arguments.length == 0){
		initial_page = "aboutus";
	};
	var html = '<ul>',
        format = '<li><a%(target)shref="%(url)s">%(text)s</a></li>',
        clickables = [];
    $.each(site_menu, function(i, o){
        if(o[1].substr(0,4) == 'http'){
            html+= dji18njs.interpolate(format, {
                target: o[2] ? ' target="_blank" ': ' ',
                url: o[1],
                text: o[0]
            }, true);
        } else {
            var a_id = dji18njs.interpolate("page-%s", [o[1]])
            clickables.push(a_id);
            html+= dji18njs.interpolate(format, {
                target: dji18njs.interpolate(' id="%s" ', [a_id]),
                url: dji18njs.interpolate('#m=%s', [o[1]]),
                text: o[0]
            }, true);
        }
    });
    html+= '</ul>';
    $("nav").html(html).find("li:first-child").addClass('first-child');
    $.each(clickables, function(i, o){
        var $a = $("header nav a#"+o).click(function(){
            window.location.href=this.href;
            publis_site();
        });
    });
    var url_match = window.location.href.match("(?:http|file)?(?:s?)://[^/]*([^#]*)(#m=(?:.*))?$");    
    
	if(url_match !== null && url_match[2] != undefined){
        if(url_match[2].length>0){
			initial_page = url_match[2].replace('#m=',"");
		};
    }
	var load_file = dji18njs.interpolate("page-%s.html", [initial_page]);
	$("#middle").load(load_file, function(response, status, xhr){
        $("#page-"+initial_page).addClass('current');
    });

}

/* main */
$(document).ready(function() {
    $("#eml").html(dji18njs.interpolate(emls, [eml, eml]));
    publis_site();
});

