var headerShow;
var menu_slider = new Array();
var req;
var now_url;
var currentHash = '';
var history_interval;
var is_trackmap = false;
window.addEvent('load', function(){
$('main_body').setStyle('background','url(\'/images/mainback2_'+window.getSize().x+'.jpg\') no-repeat center bottom #0b3695');
    $('slide_show').innerHTML = '';
    $('slide_show').setStyle('display','block');
    headerShow = new Slideshow('slide_show', slideshowData, {width:890, height:312, caption:false, loader:''});
    headerShow.first();
    headerShow.pause(0);
    
	
    $$('td.menu').each(function(item,index){ 
	if(item.getElement('.a_submenu')) {
	    item.getElement('.submenu').setStyle('display','none');
	    item.addEvent('mouseover',function(e){
		e.stop();
		item.getElement('.submenu').setStyle('display','block');
	    });

	    item.addEvent('mouseout',function(e){
		e.stop();
		item.getElement('.submenu').setStyle('display','none');
	    });

	    item.getElement('.submenu').addEvent('mouseout',function(e){
		e.stop();
		item.getElement('.submenu').setStyle('display','none');
	    });

	}
    });

req = new Request.HTML({url:'/', 
	onSuccess: function(html) {
	    $('main_content').set('text', '');
	    $('main_content').adopt(html);
	    document.title = $('sitetitle').innerText;
	    trackToGA();
	    try {initialize();}
	    catch(e){}
	}
    });
    

    try {initialize();}
    catch(e){}

    sync_url();
    history_interval = setInterval(sync_url,1000);


});

function sync_url()
{
    if(currentHash != String(document.location.hash).substring(1))
    {
        var anchor = new Hash ({href: 'http://krasiya.info/' + document.location.hash.substring(1)});
        load_data(anchor);
    }

}

function edit_content(page_id, act, item, topic)
{
    return true;
    if(item == undefined) item = '';
    if(topic == undefined) topic = '';
    act = act + '&post_url=' + item + '&topic=' + topic;
    Shadowbox.open({
    content: '/edit.php?p=' + page_id + '&act=' + act,
    player:     "iframe",
	title:      "Редактирование",
        height:     560,
	width:      560
    });
    return false;
}

function trackToGA() {
    pageTracker._trackPageview(now_url);
}

function load_data(anchor)
{
    $('main_content').innerHTML = '<center><h1>' + loading_text + '...</h1></center>';    
    now_url = anchor.href;
    if(anchor.title != undefined) document.location = 'http://krasiya.info#' + anchor.href.substring(20);
    currentHash = document.location.hash.substring(1);
    req.send({url:anchor.href +'?aj=1'});
    return false;
}

function init_trackmap() 
{
//$('lift1_a').title = $('lift1').innerText;
//$('lift2_a').title = $('lift2').innerText;
//$('lift3_a').title = $('lift3').innerText;
//$('lift4_a').title = $('lift4').innerText;

//var Tips3 = new Tips($$('.tips'), {
//    className: 'tool',
//    initialize:function(){
//	this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
//    },
//    onShow: function(toolTip) {
//	this.fx.start(1);
//    },
//    onHide: function(toolTip) {
//	this.fx.start(0);
//    }
//});

}
			