function comeStep() {
        step = 0;
        $('#main1').everyTime(10, function(){
            step++;
            if (step > 20) {
                $('#main1').stopTime();
            } else {
                allwdth = 0;
                for (i=0; i<3; i++) {
                    wdthn[i] = wdthn[i] + wstep[i];
                    ii = i + 1;
                    $('#p'+ii).width(Math.ceil(wdthn[i]));
                    $('#pp'+ii).width(Math.ceil(wdthn[i]));
                    $('#pa'+ii).width(Math.ceil(wdthn[i]));
                    $('#ppa'+ii).width(Math.ceil(wdthn[i]));
                    allwdth = allwdth + Math.ceil(wdthn[i]);
                    bposn[i] = bposn[i] + bstep[i];
                    $('#p'+ii).css('backgroundPosition', bposn[i]+'px 0');
                    $('#pa'+ii).css('backgroundPosition', bposn[i]+'px 0');
                }
                y = 900 - allwdth;
                $('#p4').width(y);
//                bposn[wdtht] = bposn[wdtht] + bstep[wdtht];
//                $('#p'+(wdtht+1)).css('backgroundPosition', bposn[wdtht]+'px 0');
//                $('#pa'+(wdtht+1)).css('backgroundPosition', bposn[wdtht]+'px 0');
                bposn[3] = bposn[3] + bstep[3];
                $('#p4').css('backgroundPosition', bposn[3]+'px 0');
                $('#pa4').css('backgroundPosition', bposn[3]+'px 0');
                $('#pp4').width(y);
                $('#pa4').width(y);
                $('#ppa4').width(y);
            }
        });    
}

function comeTo() {
        for (i=0; i<4; i++) {
            if (i==wdtht) {
                start = 390;
            } else {
                $('#ppa'+(i+1)).css('backgroundImage', 'url(/img/label'+(i+1)+'s.png)');
                start = 170;
            }
            wstep[i] = (start - wdthn[i]) / steps;
            bstep[i] = (bposf[i] - bposn[i]) / steps;
        }
        bstep[wdtht] = (-10 - bposn[wdtht]) / steps;
        comeStep();
}

function comeOut() {
        for (i=0; i<4; i++) {
            $('#ppa'+(i+1)).css('backgroundImage', 'url(/img/label'+(i+1)+'.png)');
            wstep[i] = (225 - wdthn[i]) / steps;
            bstep[i] = (bposf[i] - bposn[i]) / steps;
        }
//        bstep[wdtht] = (bposf[wdtht] - bposn[wdtht]) / steps;
        comeStep();
}

$(function(){
    wdthn = new Array(225, 225, 225, 225);
    bposn = new Array(-25, -200, -200, -50);
    bposf = new Array(-25, -200, -200, -50);
    wdtht = 0;
    wstep = new Array(1, 1, 1, 1);
    bstep = new Array(1, 1, 1, 1);
    fstep = 1;
    steps = 20;
    step = 0;
    $('a#pp1').mouseover(function() {
        wdtht = 0;
        comeTo();
    });
    $('a#pp1').mouseout(function() {
        $('#main1').stopTime();
        comeOut();
    });
    $('a#pp2').mouseover(function() {
        wdtht = 1;
        comeTo();
    });
    $('a#pp2').mouseout(function() {
        $('#main1').stopTime();
        comeOut();
    });
    $('a#pp3').mouseover(function() {
        wdtht = 2;
        comeTo();
    });
    $('a#pp3').mouseout(function() {
        $('#main1').stopTime();
        comeOut();
    });
    $('a#pp4').mouseover(function() {
        wdtht = 3;
        comeTo();
    });
    $('a#pp4').mouseout(function() {
        $('#main1').stopTime();
        comeOut();
    });
    $('a#ppa1').mouseover(function() {
        wdtht = 0;
        comeTo();
    });
    $('a#ppa1').mouseout(function() {
        $('#main1').stopTime();
        comeOut();
    });
    $('a#ppa2').mouseover(function() {
        wdtht = 1;
        comeTo();
    });
    $('a#ppa2').mouseout(function() {
        $('#main1').stopTime();
        comeOut();
    });
    $('a#ppa3').mouseover(function() {
        wdtht = 2;
        comeTo();
    });
    $('a#ppa3').mouseout(function() {
        $('#main1').stopTime();
        comeOut();
    });
    $('a#ppa4').mouseover(function() {
        wdtht = 3;
        comeTo();
    });
    $('a#ppa4').mouseout(function() {
        $('#main1').stopTime();
        comeOut();
    });
    
    $('#opentext_morelink1 a').click(function() {
    	$('#opentext_morelink1').hide();
    	$('#opentext_more').slideDown();
    	$('#opentext_morelink2').show();
    	return(false);
    });
    $('#opentext_morelink2 a').click(function() {
    	$('#opentext_morelink2').hide();
    	$('#opentext_more').slideUp();
    	$('#opentext_morelink1').show();
    	return(false);
    });
});
