/**
 * appRain CMF
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Inc. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 * 
 * Official Website 
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */
var appslide =
{   
    _obj       :null,
    _ttime     :100, 
    _data      :Array(),
    _l_img     :base + '/componentroot/appslide/', 
    _l_obj     :'.app-press-menu',
    show_img   :function(item)
                {
                    jQuery(item).fadeIn('slow');
                },
    chimg      :function(_obj)
                {
                    var g = true;
                    jQuery('.press-img-pan').children('img').each(function(index,item){
                        if(jQuery(item).attr('src').search(jQuery(_obj).attr('rel'))>0 && g){
                            g = false;
                            appslide.show_img(item);
                        }
                        else {
                            jQuery(item).css('display','none');
                        }
                    });
                },
    clrsec     :function()
                {
                    jQuery('.app-press-menu').children('a').each(function(index, item){
                        jQuery(item).removeClass('selected');  
                    })
                },
    loading    :function(ptr)
                {
					var arr = siteInfo.skinUrl.split('/');
				    var filename = (arr[arr.length-1] == 'blackrain') ? 'load-b.gif' : 'load-w.gif';
                    if(ptr)jQuery(appslide._l_obj).css('background','url(' + appslide._l_img + filename + ') left top no-repeat');
                    else jQuery(appslide._l_obj).css('background','none');
                },
    view       :function()
                {
                    appslide._obj = this;

                    if( typeof appslide._data[jQuery(appslide._obj).attr('longdesc')] == 'undefined')
                    {
                        appslide.loading(true);
						jQuery.ajax({
							url: siteInfo.baseUrl + "/appslide/index/" + jQuery(this).attr('longdesc'),
							context: document.body,
							success: function(responseTxt){
								appslide._data[jQuery(appslide._obj).attr('longdesc')] =responseTxt ;
                                appslide.chimg(appslide._obj);
                                appslide.clrsec();
                                jQuery(appslide._obj).css('selected');
                                jQuery('.app-press-text').html(appslide._data[jQuery(appslide._obj).attr('longdesc')]);
                                Cufon.replace('h1');
                                appslide.loading(false);
							}
						});
                    }
                    else
                    {
                        appslide.chimg(appslide._obj);
                        appslide.clrsec();
                        jQuery(appslide._obj).addClass('selected');
                        jQuery('.app-press-text').html(appslide._data[jQuery(appslide._obj).attr('longdesc')]);
                        Cufon.replace('h1');
                    }
					
                },
    loadimage  :function(image)
                {
  			       jQuery('.press-img-pan').append('<img src="' + siteInfo.baseUrl + '/uploads/filemanager/' + image + '" style="display:none" />');
                },
    init       :function()
                {
					jQuery('.app-press-menu').children('a').each(function(index,item){
						appslide.loadimage(jQuery(item).attr('rel'));
						jQuery(item).click(appslide.view);
					}); 
                }
}

jQuery(document).ready(appslide.init);