var csload = function (el,event){
    if(el.get('rel')=='main') {
        $$('#menu a').each(function(el){
            el.removeClass('active');
        });
        el.addClass('active');
        var thePage=$(el).get('href');
        if(thePage.indexOf("?")<=0) {
            thePage=thePage+"?"
        }
        thePage=thePage.split('url=');
        thePage=thePage[1].split('&');
        thePage=thePage[0];
        pageTracker._trackPageview('?thePage='+thePage);
        var anim = new Fx.Morph($('main'), {duration:500, transition: Fx.Transitions.Back.easeIn});
        anim.start({
            marginLeft: '0'
        }).chain(function() {
            var anim = new Fx.Morph($('main'), {duration:500, transition: Fx.Transitions.Back.easeOut});
            anim.start({
                marginLeft: '720px'
            }).chain(function() {
                $$('.page').each(function(el) {
                    el.removeClass('show');
                    el.addClass('hide');
                });
                $('page'+thePage).removeClass('hide');
                $('page'+thePage).addClass('show');
                $('main').setStyle('marginLeft','-720px');
                var anim = new Fx.Morph($('main'), {duration:500, transition: Fx.Transitions.Back.easeOut});
                anim.start({
                    marginLeft: '0'
                });
            });
        });
    }
    if(el.get('rel')=='specificationtab') {
        $$('.specificationtabmenu a').each(function(el){
            el.removeClass('active');
        });
        el.addClass('active');
        var theTab=$(el).get('href');
        if(theTab.indexOf("?")<=0) {
            theTab=thePage+"?"
        }
        theTab=theTab.split('specificationtab=');
        theTab=theTab[1].split('&');
        theTab=theTab[0];
        $$('.specificationtab').each(function(el){
            el.addClass('hide');
            el.removeClass('show');
        });
        $(theTab).removeClass('hide');      
        $(theTab).addClass('show');
    }
    if(el.get('rel')=='locationtab') {
        $$('.locationtabmenu a').each(function(el){
            el.removeClass('active');
        });
        el.addClass('active');
        var theTab=$(el).get('href');
        if(theTab.indexOf("?")<=0) {
            theTab=thePage+"?"
        }
        theTab=theTab.split('locationtab=');
        theTab=theTab[1].split('&');
        theTab=theTab[0];
        $$('.locationtab').each(function(el){
            el.addClass('hide');
            el.removeClass('show');
        });
        $(theTab).removeClass('hide');      
        $(theTab).addClass('show');
    }
    if(el.get('rel')=='slide') {
        var theSlide=$(el).get('href');
        if(theSlide.indexOf("?")<=0) {
            theSlide=theSlide+"?"
        }
        theSlide=theSlide.split('slide=');
        theSlide=theSlide[1].split('&');
        theSlide=theSlide[0];
        $('theslide').set('src','images/'+theSlide+'.jpg');
    }
    if(el.get('rel')=='specslide') {
        var theSpecslide=$(el).get('href');
        if(theSpecslide.indexOf("?")<=0) {
            theSpecslide=theSpecslide+"?"
        }
        theSpecslide=theSpecslide.split('specslide=');
        theSpecslide=theSpecslide[1].split('&');
        theSpecslide=theSpecslide[0];
        $('thespecslide').set('src','images/'+theSpecslide+'.jpg');
    }
    if(el.get('rel')=='popup') {
        var thePopup=$(el).get('href');
        if(thePopup.indexOf("?")<=0) {
            thePopup=thePopup+"?"
        }
        thePopup=thePopup.split('popup=');
        thePopup=thePopup[1].split('&');
        thePopup=thePopup[0];
        $('block').setStyle('marginTop','100%');
        $('block').removeClass('hide');
        $('block').addClass('show');
        $('popup'+thePopup).setStyle('marginTop','-100%');
        $('popup'+thePopup).removeClass('hide');
        $('popup'+thePopup).addClass('show');
        var anim = new Fx.Morph($('block'), {duration:500, transition: Fx.Transitions.Back.easeOut});
        anim.start({
            marginTop: '0'
        });
        var anim = new Fx.Morph($('popup'+thePopup), {duration:500, transition: Fx.Transitions.Back.easeOut});
        anim.start({
            marginTop: '0'
        });
        $('popup'+thePopup).addEvent('click',function(event){
            $$('.popup').each(function(el){
                el.removeClass('show');
                el.removeClass('hide');
            });
            $$('.popup').each(function(el){
                el.addClass('hide');
            });
            $('block').removeClass('show');
            $('block').addClass('hide');         
        });
    }
    if(el.get('rel')=='popupclose') {
        $$('.popup').each(function(el){
            el.removeClass('show');
            el.removeClass('hide');
        });
        $$('.popup').each(function(el){
            el.addClass('hide');
        });
        $('block').removeClass('show');
        $('block').addClass('hide');
    }
}
window.addEvent('domready',function(){
    $('window').setStyle('display','block');
    $('main').setStyle('marginLeft','-720px');
    $('body').setStyle('opacity','0');
    $('body').setStyle('height','0');
    var anim = new Fx.Morph($('body'), {duration:500, transition: Fx.Transitions.Back.easeOut});
    anim.start({
        height: '408px'
    }).chain(function() {
        var anim = new Fx.Morph($('body'), {duration:1500});
        anim.start({
            opacity: '1'
        }).chain(function() {
            var anim = new Fx.Morph($('main'), {duration:500, transition: Fx.Transitions.Back.easeOut});
            anim.start.delay(1000,anim,{
                marginLeft: 0
            });
        });
    });
    $$('#menu a','#body a','#popup a').each(function(el){
        if(el.target.length<=0) {
            el.addEvent('click',function(event){
                csload(el,event);
                el.blur();
                return false;
            });
        }
    });
    $$('area').each(function(el){
        el.addEvent('click',function(event){
            csload(el,event);
            el.blur();
            return false;
        });
    });
});