/* 
 * @file Shop Info
 */

var ShopInfoDialogId = 'shop_info_dialog';
var ShopInfoUrl = 'ajax/shop/info.php';
var ShopInfoData = null;

function LoadInfoDialog(){

    $('body').append('<div id="'+ShopInfoDialogId+'"></div>');

    dialog = $('#'+ShopInfoDialogId);
    //dialog.hide();
    dialog.addClass('pop_up');


    container = $('<div id="pop_up_container"></div>');
    content   = $('<div id="pop_up_content"></div>');
    content.append('<div id="pop_up_content_top"></div>');
    content.append('<div id="pop_up_content_bottom"></div>');
    content.append('<div id="close_it_box"></div>');
    container.append(content);

    dialog.append(container);

    $('#close_it_box').click(HideInfoDialog);

    //Load data
    $.post(ShopInfoUrl,null,DataLoaded,"json");

    dialog.hide();

    $('a.help_link').click(function(){

        ShowInfoDialog($(this).attr('href'));

        return false;
    })

}

function DataLoaded(data){

    ShopInfoData = new Array();

    box_container = $('#pop_up_content_bottom');

    for(i in data){
        title = data[i]['Title'];
        text  = data[i]['Text'];

        box = $('<div></div>');
        box.addClass('pop_boxes');
        box.addClass('ppb_inactive');
        box.html('<a href=""><h3>'+title+'</h3></a>');
        box.attr('id','popbox_'+i);
        box_container.append(box);

        ShopInfoData[i]=text;
    }

    //Define Action for boxes
    $('div.pop_boxes a').click(function(){

        $('[id^=popbox_]').each(function(){
            if( $(this).hasClass('ppb_active') ){
                $(this).removeClass('ppb_active');
                $(this).addClass('ppb_inactive');
            }
        });

        if( $(this).parent().hasClass('ppb_inactive') ){
            $(this).parent().removeClass('ppb_inactive');
        }

        if( !$(this).parent().hasClass('ppb_active') ){
            $(this).parent().addClass('ppb_active');
        }
            

        id = $(this).parent().attr('id').replace('popbox_','');
        $('#pop_up_content_top').html(ShopInfoData[id]);
     
        return false;
    });
}

function ShowInfoDialog(param){
    $('#pop_up_content_top').html(ShopInfoData[param]);

    $('[id^=popbox_]').each(function(){
            if( $(this).hasClass('ppb_active') ){
                $(this).removeClass('ppb_active');
                $(this).addClass('ppb_inactive');
            }
        });

    cont = $('#popbox_'+param);

    if( cont.hasClass('ppb_inactive') )
        cont.removeClass('ppb_inactive');

    if( !cont.hasClass('ppb_active') )
        cont.addClass('ppb_active');
    
    $('html, body').animate({scrollTop:0}, 'slow', function(){
        $('#'+ShopInfoDialogId).fadeIn();
    });
    
}

function HideInfoDialog(){
    dialog = $('#'+ShopInfoDialogId);
    dialog.fadeOut();
}