$(document).ready( page_init );

/// Element IDs
var ids = {
    loading: "#loading",

    search_go: "#search_go",
    search_text: "#search_text",

    sub_text: "#top_subscribe",

    menus: "#nav_menus",

    page_cover: "#page_cover",
    popup: "#popup",
    popup_content: "#popup_content",

    last: ""
};


var menu = {

    sub_show: function(){
        $(this).find( "ul.s-l" ).show();
        $(this).children().eq(0).addClass( "over" );
    },
    sub_hide: function(){
        $(this).find( "ul.s-l" ).hide();
        $(this).children().eq(0).removeClass( "over" );
    }
};


/// initialize elements after page is fully loaded
function page_init(){
    // the search input field
    $( ids.search_text ).focus(
        function(){
            if( $(this).val() == "Enter Keywords..." ) $(this).val( "" );
        }
    ).blur(
        function(){
            if( $(this).val() == "" ) $(this).val( "Enter Keywords..." );
        }
    );
    // the search button
    $( ids.search_go ).hover(
        function(){
            $(this).addClass( "over" );
        },
        function(){
            $(this).removeClass( "over" );
        }
    );
    // subscribe input field
    $( ids.sub_text ).focus(
        function(){
            if( $(this).val() == "Join Now! Never miss another bargain" ) $(this).val( "" );
        }
    ).blur(
        function(){
            if( $(this).val() == "" ) $(this).val( "Join Now! Never miss another bargain" );
        }
    );

    // the submenus
    $( ids.menus + " li" ).hover( menu.sub_show, menu.sub_hide );
    // the loading image
    //loading();
};


/// product list
var prdt_list = {

    init: function(){
        $( "#prdt_list" + " .cart" ).css( "display", "block" );
    }
};


/// javascript for the viewing product page
var prdt = {
    imgs: [],
    tmbs: [],
    wh: { w: 400, h: 300 },
    wh_up: { w:640, h:480 },
    tmpl: {},

    img_slc: function( a ){
        var i = a.id.replace( "prdt_img_tmb_", "" );
        var img = new Image();
        var big_id = "#prdt_detail" + " .imgs .big";
        var a_id = "#prdt_detail" + " .imgs a";
        $( big_id ).html( '<img class="ld" src="/template/default/imgs/i_prdt_img_loading.gif" alt="loading" />' );
        img.onload = function(){
            var w = this.width;
            var h = this.height;
            if( w > prdt.wh.w ){
                w = prdt.wh.w;
                h = Math.round( this.height / ( this.width / prdt.wh.w ) );
            }
            if( h > prdt.wh.h ){
                h = prdt.wh.h;
                w = Math.round( this.width / ( this.height / prdt.wh.h ) );
            }
            this.width = w;
            this.height = h;

            var p = ( prdt.wh.h - this.height ) / 2;
            $( big_id ).empty().append( this );
            $(this).css( "padding-top", p ).addClass( "clk" ).click( prdt.popup );
        }
        img.src = prdt.imgs[i];
        img.id = "prdt_img_big_" + i;
        //$( "#prdt_detail" + " .imgs .left" ).html( '<img src="' +prdt.imgs[i]+ '" />' );
        $( a_id ).removeClass( 'cur' );
        $(a).addClass( 'cur' );
    },

    popup: function( img ){
        var i = this.id.replace( "prdt_img_big_", "" );
        var tb = new jQuery( prdt.tmpl.popup );
        tb.find( ".info" ).empty().append( $( "#prdt_infos" ).html() );
        tb.find( ".info" ).find( ".prdt-ps" ).remove();
        tb.find( ".hd" ).empty().append( '<div class="page-hd">' +$( ".page-hd" ).html()+ '</div>' );
        var tmbs = tb.find( ".tmbs div" ).empty();
        for( var j = 0; j < prdt.imgs.length; j++ ){
            tmbs.append( '<a id="prdt_popup_tmb_' +j+ '"onclick="prdt.popup_slc(this)"><img src="' +prdt.tmbs[j]+ '" /></a>' );
        }
        tmbs.children( "a" ).hover( m_over, m_out );
        popup.set( tb );
        popup.show();
        prdt.popup_slc( i );
    },
    popup_slc: function( a ){
        if( typeof a != "object" ){
            var i = a;
            a = $( "#prdt_popup_tmb_" + a );
        }else{
            var i = a.id.replace( "prdt_popup_tmb_", "" );
            a = $(a);
        }
        var img = new Image();
        var big = a.parent().parent().prev();
        big.empty().html( '<img class="ld" src="/template/default/imgs/i_prdt_img_loading.gif" alt="loading" />' );
        img.onload = function(){
            big.empty().append( this );
        }
        img.src = prdt.imgs[i];
        a.parent().children().removeClass( 'cur' );
        a.addClass( 'cur' );
    },

    ask: function( id ){
        loading( 1, "Posting Question..." );
        req.submit( "/misc/prdt_qnas/", get_inputs( "#prdt_question" ), prdt.ask_callback, "#prdt_question" );
    },
    ask_callback: function( msg ){
        msg = req.callback( msg, "#prdt_question" );
        alert( ( typeof msg.msg == typeof "" ? msg.msg : obj_to_arr( msg.msg ).join( "\r\n" ) ) );
        if( msg.response ){
            var o = $( "#prdt_question textarea" );
            $( "#prdt_qnas" ).append( '<div class="qna"><div class="q">' +nl2br( o.val() )+ '</div></div>' );
            o.val( '' );
        }
        loading( 0 );
    },

    init: function(){
        this.imgs = [];
        var a = $( "#prdt_detail" + " .tmbs a" );
        a.hover( m_over, m_out ).each(
            function(i){
                prdt.imgs[i] = this.href;
                prdt.tmbs[i] = $(this).children().get(0).src;
                this.id = "prdt_img_tmb_" + i;
            }
        ).click( function(){ prdt.img_slc(this);return false; } );
        prdt.img_slc( a.get(0) );
        prdt.tmpl.popup = get_inner( "#prdt_img_tmpl", 1 );
        push.init();
    }
};

/// cart related
var cart = {

    cart_empty: "",


    add: function( id, qty ){
        qty = qty || 1;
        if( id ){
            //loading( 1, "Adding " + qty + " product to your shopping cart..." );
            loading( 1, "Updating your shopping cart..." );
            $.post( "/cart/add/", {id:id, qty:qty}, cart.callback );
        }
    },
    del: function( id ){
        if( id ){
            loading( 1, "Updating your shopping cart..." );
            $.post( "/cart/del/", {id:id}, cart.callback );
        }
    },
    callback: function( msg ){
        msg = my_eval( msg );
        if( msg.response ){
            cart.show( msg.data );
        }else{
            alert( msg.msg );
        }
        loading( 0 );
    },
    add_form: function(){
        o = $( "#add_cart_form" );
        cart.add( o.find( 'input[name="id"]' ).val(), o.find( 'input[name="qty"]' ).val() );
    },
    show: function( data ){
        data = data || {};
        var o = $( "#cart_items" );
        var e = true;
        o.find( ".item" ).remove();
        for( var p in data ){
            e = false;
            d = data[p];
            o.append( '<div class="item"><div class="i-i"><a href="' +d['url']+ '"><img src="' +( d['pic'] ? d['pic'] : '/template/default/imgs/i_prdt_no_img.png' )+ '" height="50" /></a></div>' +
                      '<div class="i-t"><strong><a href="' +d['url']+ '">' +d['name']+ '</a></strong> x ' +d['qty']+
                      '<div class="i-p">' +money( d['qty'] * d['price'] )+
                      ' <img onclick="cart.del(\'' +d['id']+ '\')" src="/template/default/imgs/i_del.gif" alt="remove" />' +
                      '</div></div></div>' );
        }
        if( e ){
            o.find( ".empty" ).show();
            $( "#cart_checkout" ).hide();
        }else{
            o.find( ".empty" ).hide();
            $( "#cart_checkout" ).show();
        }
    }
};


// sort by
var sortby = {

    show: function( e, on ){
        var o = $(e).find( ".slcts" );
        if( on ){
            var i = 0;
            var as = o.children().get();
            for( i; i < as.length; i++ ){
                //if( as[i].innerHTML.toLowerCase().indexOf( "<strong>" ) == 0 ){
                if( as[i].className == "cur" ){
                    break;
                }
            }
            o.css( "margin-top", (-21) - (15*i) );
            o.show();
        }else{
            o.hide();
        }
    }
};


// checkout
var cko_cart = {
    fid: "#cko_cart_form",
    tid: "#cko_cart_lst",
    mid: "#cko_cart_msg",
    url: "/checkout/cart/update",
    prdts: {},

    msg: function( msg ){
        var o = $(this.mid);
        msg ? o.html( msg.join( "<br />" ) ).show() : o.hide();
    },

    qty: function( add, i ){
        if( !cko_cart.updating ){
            var a = $(this);
            cko_cart.prdts[i].qty *= 1;
            var n = ( add ? ( cko_cart.prdts[i].qty < cko_cart.prdts[i].max ? 1 : 0 ) : ( cko_cart.prdts[i].qty > 0 ? -1 : 0 ) );
            if( n ){
                cko_cart.prdts[i].qty += n;
            }
            cko_cart.build();
        }
    },

    build: function( data ){
        this.prdts = data || this.prdts;
        var t = $( this.tid );
        t.children().children( "tr:gt(0)" ).remove();
        var total = 0;
        var html = "";
        for( var i in this.prdts ){
            html = "";
            var p = this.prdts[i];
            var subtotal = p['price'] * p['qty'];
            total += subtotal;
            var img = p['pic'] ? p['pic'] : "/template/default/imgs/i_prdt_no_img.png";
            var l = ( p['max'] != '999' ) ? '<br /><span class="g">Crasy Daily Deals Limited ' +p['max']+ ' items per customer</span>' : "";
            html += '<tr>' +
                    '<td class="img v-m"><a href="' +p['url']+ '"><img src="' +img+ '" /></a></td>' +
                    '<td class="prdt v-m"><a href="' +p['url']+ '">' +p['name']+ '</a>' +l+ '</td>' +
                    '<td class="price v-m">' +money( p['price'] )+ '</td>' +
                    '<td class="qty v-m">' +
                    '<a class="minus" onclick="cko_cart.qty(0,\'' +i+ '\')">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>&nbsp;' +
                    '<span>' +p['qty']+ '<input type="hidden" name="qty[' +i+ ']" value="' +p['qty']+ '" /></span>' +
                    '&nbsp;<a class="plus" onclick="cko_cart.qty(1,\'' +i+ '\')">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td>' +
                    '<td class="subtotal v-m">' +money( subtotal )+ '</td>' +
                    '</tr>';
            t.append( html );
        }
        html = '<tr class="total">' +
               '<td colspan="2">&nbsp;</td>' +
               '<td class="t" colspan="2">Total Amount</td>' +
               '<td class="t">' +money( total )+ '</td>' +
               '</tr>';
        t.append( html );
    },

    init: function(){
        if( cart_items ){
            cko_cart.prdts = cart_items;
            cko_cart.build();
        }else{
            //alert( "Your shopping cart is empty." );
        }
    }
};


// address page in checkout process
var cko_addr = {
    addrs: {},
    fid: "#cko_addr_form",

    slc: function( i ){
        if( cko_addr.addrs[i] ){
            var a = cko_addr.addrs[i];
            set_inputs(
                cko_addr.fid,
                [ "first_name", "last_name", "company", "phone", "address", "suburb", "city", "postcode" ],
                [ a.first_name, a.last_name, a.company, a.phone, a.address, a.suburb, a.city, a.postcode ]
            );
        }
    },

    pkup: function(){
        $( cko_addr.fid + " tr" ).each( function( i ){
            if( i > 5 && i < 11 ){
                $( "#cko_addr_pickup" ).attr( "checked" ) ? $( this ).css( 'display', 'none' ) : $( this ).css( 'display', '' );
            }
        } );
    },

    to_save: function( e ){
        var o = $( cko_addr.fid + " input[name='addr_name']" );
        o.attr( 'disabled', !e.checked );
    },

    init: function(){
        if( saved_addrs ){
            cko_addr.addrs = saved_addrs;
        }else{

        }
        cko_addr.pkup();
    }
};


var cko_invc = {
    h: function(){
        $( "#pmnt_cc" ).attr( "checked" ) ? $( "#cc_card_tb" ).show() : $( "#cc_card_tb" ).hide();
    },
    init: function(){
        $( "[name='payment_method']" ).click( cko_invc.h );
    }
};

// functions for home page
var home = {
    bnrs: [],
    bnrs_cur: 0,
    t: 0,
    to: 7000,

    bnrs_init: function(){
        var o = $( "#banner_ctl" );
        for( var i = 0; i < this.bnrs.length; i++ ){
            o.append( '<a id="banner_a' +i+ '" class="rc4" onclick="home.bnrs_go(' +i+ ')">' +(i+1)+ '</a>' );
        }
        $( "#banner_a0" ).addClass( "cur" );
        $( "#banner_a" + ( i - 1 ) ).addClass( "l" );
        this.t = setTimeout( "home.bnrs_go(1)", this.to );
    },
    bnrs_go: function( i ){
        i = i ? i % this.bnrs.length : 0;
        var c = this.bnrs_cur;
        if( this.bnrs[i] && i != c ){
            clearTimeout( this.t );
            $(this.bnrs[c]).fadeOut(1000);
            $(this.bnrs[i]).slideDown(1000);
            $( "#banner_a" + c ).removeClass( "cur" );
            $( "#banner_a" + i ).addClass( "cur" );
            this.bnrs_cur = i;
            this.t = setTimeout( "home.bnrs_go(" +(i+1)+ ")", this.to );
        }
    },

    init: function(){
        if( banners ){
            home.bnrs = banners;
            home.bnrs_init();
        }
        $( ".prdt-list" + " .cart" ).css( "display", "block" );
    }

};


// functions for the addressbook
var addr = {
    data: {},
    working: 0,

    save: function(){
        loading( 1, "Saving Address..." );
        addr.working = 1;
        req.submit( "/account/addressbook/save/", get_inputs( "#addr_inp" ), addr.save_callback, "#addr_inp" );
    },
    save_callback: function( msg ){
        msg = req.callback( msg, "#addr_inp", 1 );
        addr.working = 0;
        if( !msg.response ){
            set_err_inputs( "#addr_inp", msg.msg );
            alert( ( typeof msg.msg == typeof "" ? msg.msg : obj_to_arr( msg.msg ).join( "\r\n" ) ) );
        }else{
            addr.data = msg.data.addresses;
            addr.slct( msg.data.id );
        }
        loading( 0 );
    },

    build: function( data ){
        this.data = data || this.data;
        var s = "";
        for( var i in this.data ){
            if( this.data[i].main == "1" ){
                s = i;
                break;
            }
        }
        this.slct( s );
    },
    build_lst: function( cur ){
        var o = $( "#addr_lst" ).empty();
        // new address
        var c = !cur ? ' now' : "";
        o.append( '<a class="new' +c+ '" onclick="addr.slct()"><strong>Add New Address</strong></a>' );
        for( var i in this.data ){
            var n = this.data[i].addr_name;
            c = ( this.data[i].main == "1" ? "main" : "" );
            c += ( cur == i ? ' now' : "" );
            o.append( '<a class="' +c+ '" onclick="addr.slct(\''+i+'\')">' +n+ "</a>" );
        }
    },

    slct: function( i ){
        if( addr.working ){
            return;
        }
        unset_err_inputs( "#addr_inp" );
        var p = addr.data[i] || {id:""};
        set_inputs( "#addr_inp",
                    ['id', 'addr_name', 'first_name', 'last_name', 'company', 'phone', 'fax', 'mobile', 'address', 'suburb', 'city', 'postcode'],
                    [p.id, p.addr_name, p.first_name, p.last_name, p.company, p.phone, p.fax, p.mobile, p.address, p.suburb, p.city, p.postcode]
                  );
        var s = $( "#addr_main" ).get();
        s[0].checked = ( p.main == "1" );
        if( !p.city ){
            s = $( "#addr_inp select" ).get();
            s[0].selectedIndex = 0;
        }
        addr.build_lst( i );
        addr.lock( i );
    },

    lock: function( lock ){
        var o = $( "#addr_inp" );
        o.find( "input,select,textarea" ).attr( "disabled", ( lock ? true : false ) );
        if( lock ){
            o.find( "[name='do_edit']" ).show().attr( "disabled", false );
        }else{
            o.find( "[name='do_edit']" ).hide();
            o.find( "[name='addr_name']" ).focus();
        }
    },

    init: function(){
        if( acct_addrs ){
            addr.data = acct_addrs;
        }else{
        }
        addr.build();
    }

};


// account messages
var msgs = {
    tmpl: {},
    msgs: {},
    working: 0,
    v: { lst: 0, add: 1, view: 2 },
    ids: { l: "#acct_msg_list", v: "#acct_msg_view", a: "#acct_msg_add", rs: "#acct_msg_replies", r: "#acct_msg_reply" },

    show: function( v, p ){
        $( this.ids.a ).hide();
        $( this.ids.v ).hide();
        $( this.ids.l ).hide();
        $( ".msg-acts a" ).hide();
        unset_err_inputs( this.ids.a );
        unset_err_inputs( this.ids.r );
        var scr = $(document).scrollTop();
        switch( v ){
            case this.v.add:
                $( ".msg-acts .list" ).show();
                $( this.ids.a ).show();
                scr > 250 && $(document).scrollTop( "100" );
                break;

            case this.v.view:
                $( ".msg-acts .list" ).show();
                $( ".msg-acts .reply" ).show();
                $( this.ids.v ).show();
                this.build_view( p );
                scr > 200 && $(document).scrollTop( "100" );
                break;

            default:
                $( ".msg-acts .ref" ).show();
                $( ".msg-acts .add" ).show();
                $( this.ids.l ).show();
                scr > 100 && $(document).scrollTop( "100" );
                this.build();
        }
    },

    add: function(){
        if( !msgs.working ){
            loading( 1, "Sending Message..." );
            msgs.working = 1;
            req.submit( "/account/messages/post/", get_inputs( msgs.ids.a ), msgs.add_callback );
        }
    },
    add_callback: function( msg ){
        msg = req.callback( msg, 0, 1 );
        msgs.working = 0;
        if( msg.response == 1 ){
            msgs.build( msg.data );
            msgs.show( msgs.v.lst );
            $(msgs.ids.a + " input[name!='do_add']," + msgs.ids.a + " textarea").val( "" );
        }else{
            set_err_inputs( msgs.ids.a, msg.msg );
            alert( ( typeof msg.msg == typeof "" ? msg.msg : obj_to_arr( msg.msg ).join( "\r\n" ) ) );
        }
    },
    reply: function(){
        if( !msgs.working ){
            loading( 1, "Adding New Reply to Message..." );
            msgs.working = 1;
            req.submit( "/account/messages/post/", get_inputs( msgs.ids.r ), msgs.reply_callback );
        }
    },
    reply_callback: function( msg ){
        msg = req.callback( msg, 0, 1 );
        msgs.working = 0;
        if( msg.response == 1 ){
            $(msgs.ids.r + " input[name!='do_reply']," + msgs.ids.r + " textarea").val( "" );
            msgs.build( msg.data );
            msgs.show( msgs.v.lst );
        }else{
            set_err_inputs( msgs.ids.r, msg.msg );
            alert( ( typeof msg.msg == typeof "" ? msg.msg : obj_to_arr( msg.msg ).join( "\r\n" ) ) );
        }
    },


    view: function( i ){
        if( !msgs.working ){
            loading( 1, "Loading Message..." );
            msgs.working = 1;
            req.submit( "/account/messages/view/" +i, {}, msgs.view_callback );
            $( this.ids.r + " input[name='id']" ).val( i );
        }
    },
    view_callback: function( msg ){
        msg = req.callback( msg, 0, 1 );
        msgs.working = 0;
        if( msg.response != 1 ){
            msgs.show( msgs.v.lst );
            alert( ( typeof msg.msg == typeof "" ? msg.msg : obj_to_arr( msg.msg ).join( "\r\n" ) ) );
        }else{
            msg = msg.data;
            msgs.msgs[msg.id].is_new=0;
            msgs.show( msgs.v.view, msg.message );
        }
    },

    list: function(){
        loading( 1, "Refreshing Message List..." );
        msgs.working = 1;
        req.submit( "/account/messages/list/", {}, msgs.list_callback );
    },
    list_callback: function( msg ){
        msg = req.callback( msg, 0, 1 );
        msgs.working = 0;
        if( msg.response == 1 ){
            msgs.build( msg.data );
        }
    },

    build: function( data ){
        if( data ){
            this.msgs = data.messages || this.msgs;
        }
        var o = $( this.ids.l );
        o.find( "tr" ).each( function( i ){ if( i > 0 ){ $(this).remove(); } } );
        var h = "";
        for( var i in this.msgs ){
            var m = this.msgs[i];
            var img = '<img src="/template/default/imgs/';
            if( test( m.is_new ) ){
                img += 'i_mail_new.gif" alt="New message" />';
            }else{
                img += 'i_mail.gif" alt="Old message" />';
            }
            h = '<tr class="m" onclick="msgs.view(\'' +i+ '\')">' +
                '<td class="i">' +img+ '</td>' +
                '<td class="c">' +to_time( m.created )+ '</td>' +
                '<td class="l">' +to_time( m.last_reply )+ '</td>' +
                '<td class="s">' +m.subject+ '</td>' +
                '<td class="f a-c">' +m.replies+ '</td>' +
                '</tr>';
            o.append( new jQuery( h ).hover( m_over, m_out ) );
        }
        if( !h ){
            o.append( '<tr><td colspan="4" class="no">' +
                      'You have no message at the moment.<br />' +
                      'Please <a onclick="msgs.show(msgs.v.add)">Send Us a Message</a> if you need any help or just want to say something.' +
                      '</td></tr>'
            );
        }
    },
    build_view: function( m ){
        var o = $( this.ids.rs ).empty();
        var h = "";
        for( var i in m ){
            var r = m[i];
            if( !test( r.admin_id ) ){
                h = '<div class="y">' +
                    '<div class="s">You posted on ' +to_time( r.created )+ '</div>' +
                    '<div class="c">' +nl2br( r.content ) + '</div>' +
                    '</div>';
            }else{
                h = '<div class="a">' +
                    '<div class="s">' +r.admin_name+ ' replied on ' +to_time( r.created )+ '</div>' +
                    '<div class="c">' +nl2br( r.content ) + '</div>' +
                    '</div>';
            }
            o.append( new jQuery( h ) );
        }
    },

    init: function(){
        if( acct_msgs ){
            msgs.msgs = acct_msgs;
            //msgs.show( msgs.v.lst );
        //}else{
            //msgs.show( msgs.v.add );
        }
        if( msg_init ){
            msgs.view( msg_init );
        }else{
            msgs.show( msgs.v.lst );
        }
    }
};


// cc payment
var cc = {

    cvc: function(){
        var v = $( "#cc_csc_slc" ).val();
        if( v == "visa" || v == "master" ){
            $( "#csc_img" ).attr( "src", "/template/default/imgs/i_csc_" +v+ ".gif" );
        }
    },

    init: function(){
        $( "#cc_form select" ).change( cc.cvc );
        $( "#cc_form" ).submit( function(){ $( "#cc_form input[type='submit']" ).attr( "disabled", true ); } );
    }
};


// tabs for customer service page
var cust = {
    tabs: {},

    init: function(){
        cust.tabs = new tabs( "#tabs" );
    }
};


// switch the someone just bought block
var sold = {
    id: "#some_one_bought",
    tid: 0,
    cur: 0,
    to: 7000,
    tog: function(){
        var o = $(sold.id + " ul").get();
        $(o[sold.cur++]).hide();
        sold.cur = ( sold.cur > o.length - 1) ? 0 : sold.cur;
        $(o[sold.cur]).fadeIn(1000);
        this.t = setTimeout( "sold.tog()", sold.to );
    },
    init: function(){
        this.t = setTimeout( "sold.tog()", sold.to );
    }
};


// push game
var push = {
    p: {},
    working: 0,

    push: function( id ){
        if( !push.working ){
            loading( 1, "Pushing the price..." );
            push.working = 1;
            req.submit( "/push/push", {id:id}, push.push_callback );
        }
    },
    push_callback: function( msg ){
        msg = req.callback( msg, 0, 1 );
        push.working = 0;
        loading();
        if( !msg.response ){
            alert( ( typeof msg.msg == typeof "" ? msg.msg : obj_to_arr( msg.msg ).join( "\r\n" ) ) );
        }else{
            push.build( msg.data.push );
        }
    },

    build: function( data ){
        this.p = data || this.p;
        p = this.p;
        $( "#push_lv" ).html( p.lv + ( test( p.end_time ) ? ( "<br />Expires: " + to_time( p.end_time ) ) : "" ) );
        $( "#push_price" ).html( money( p.price ) );
        $( "#push_pushes" ).html( p.pushes );
        $( "#push_next_price" ).html( money( p.next_price ) );
        $( "#push_next_price_change" ).html( p.next_price_change );
        $( "#push_next_pushes" ).html( p.next_pushes );
        $( "#push_left" ).html( p.push_left );
        $( "#prdt_price" ).html( p.price );
        $( "#prdt_saves" ).html( p.saves );
        // the width of push_lb and push_rb
        var w_l = p.pushes / p.next_pushes * 100;
        w_l = w_l > 1 ? w_l - 1 : 1;
        var w_r = 99 - w_l;
        var maxed = ( p.lv == p.max_lv );
        var lv = ( maxed ? "max" : p.lv );
        $( "#push_lb" ).attr( "class", "lb lv" + lv ).attr( "width", w_l + "%" );
        //$( "#push_rb" ).attr( "width", w_r + "%" );
        if( maxed ){
            $( "#push_lb" ).attr( "width", "98%" );
            $( "#push_rb" ).remove();
        }
        if( test( p.allow_push ) ){
            $( "#push_pushed" ).hide();
            $( "#push_btn" ).show();
        }else{
            $( "#push_pushed" ).show();
            $( "#push_btn" ).hide();
        }
    },

    init: function(){
        if( prdt_push ){
            push.build( prdt_push );
        }
    }
};


// general js for account
var acct = {


    news_slc: function( e ){
        var o = $( "#news_slc" );
        test( e.value ) ? o.slideDown() : o.slideUp();
    },

    init: function(){
    }
};