/*
 * This script used to Atom-tuka in main.
 */

(function() {
    var atom = {};
    atom.config = {};
    atom.vars = {};

    //config settings.
    atom.config.shopName = 'shop';
    atom.config.cvName = 'cover';
    atom.config.cv = $( '<div />' )
        .attr( 'id', atom.config.cvName )
        .appendTo( $( 'body' ) )
        .css({
            'display': 'none',
            'background-color': '#cdcbc6',
            'width': '100%',
            'position': 'absolute',
            'left': 0,
            'top': 0,
            'z-index': 100,
            'opacity': 0.8
        })
        .click(function() {
            atom.dePpShop();
        });
    atom.config.cvShow = function() {
        atom.config.cv.css( 'height', ( $('html').height() > $(document).height() ? $('html').height() : $(document).height() ) + 'px' );
        atom.config.cv.fadeIn();
    }
    atom.config.cvHide = function() {
        atom.config.cv.fadeOut();
    }

    //popup member-shop details.
    atom.ppShop = function( id ) {
        this.vars.id = id;
        var selector = '#' + this.config.shopName + this.vars.id;
        $(selector)
            .css({
                'top': ( $('body').attr('scrollTop') > $('html').attr('scrollTop') ? $('body').attr('scrollTop') : $('html').attr('scrollTop') ) + ( ( $('html').attr('clientHeight') - $(selector).height() ) / 2 ) + 'px',
                'left': '50%',
                'margin-left': -( $(selector).width()/2 ) + 'px'
            }).fadeIn();
        this.config.cvShow();
    }

    atom.dePpShop = function( id ) {
        if( id ) {
            this.vars.id = id;
        }
        var selector = '#' + this.config.shopName + this.vars.id;
        $(selector).fadeOut();
        this.config.cvHide();
    }

    atom.mmEvent = function( tar, form ) {
        if( tar.href ) {
            $( '#' + form + ' form' ).attr( 'action', tar.href ).get(0).submit();
            return false;
        }
    }

    window.atom = atom;
 })();


$(function() {
    $( 'input.placeholder[type=text]' ).focus(function() {
        if( !this.value_def ) {
            this.value_def = this.value;
        }
        if( this.value === this.value_def ) {
            this.value = '';
        }
    }).blur(function() {
        if( !this.value && this.value_def ) {
            this.value = this.value_def;
        }
    });
});

