/***************************************************************************
*          Copyright (c) 2011 Dan@my.ro for OnlineShop SRL                 *
/***************************************************************************/
$J=jQuery.noConflict();
function Namespace(str)
    {
    var namespaces=str.split('.')||[str];
    var root=window;
    var F=function(){};
    $J.each(namespaces,function(i,ns){
        if(typeof(root[ns])==='undefined')
            {
            root=root[ns]=F;
            root=root.prototype=F;
            }
        else
            {
            root = root[ns];
            }        
    });
}
/* --------------------------------- SLIDER ------------------------------------- */
Namespace("Egreat.Slider");
Egreat.Slider={
    params:{
        'cid'   :0,
        'timer' :null
    },
    init:function(params)
        {
        $J.extend(this.params,params||{});
        $J('#slideuri').find('.featured .prev').click(function(){$Slider.previous();});
        $J('#slideuri').find('.featured .next').click(function(){$Slider.next();});
        $Slider.auto();
        },
    next:function()
        {
        var cid=$Slider.params.cid+1;//next ID
        if(cid==5){cid=0;}
        $Slider.focusOn(cid);
        },
    previous:function()
        {
        var cid=$Slider.params.cid-1;//previous ID 
        if(cid==-1){cid=4;}
        $Slider.focusOn(cid);
        },
    focusOn:function(el_id)
        {
        $J('#slideuri').find('div.featured').eq($Slider.params.cid).hide();
        $J('#slides-menu').find('li .focus').removeClass('focus');
        $Slider.params.cid=el_id;
        $J('#slideuri').find('div.featured').eq($Slider.params.cid).show('slow');
        $J('#slides-menu').find('li a').eq($Slider.params.cid).addClass('focus');
        },
    auto:function()
        {
        if($Slider.params.timer!=null)
            {
            clearTimeout($Slider.params.timer);
            $Slider.next();           
            }        
        $Slider.params.timer=setTimeout(function(){$Slider.auto()},6000);
        }
};
//the end
$Slider=Egreat.Slider;
/* --------------------------------- SLIDER ------------------------------------- */
/* ----------------------------- Product Page ----------------------------------- */
Namespace("Egreat.Product.Slider");
Egreat.Product.Slider={
    details:{
        'slides':[]
    },
    init:function(params)
        {
        $J.extend(this.details,params||{});
        $J('#slides').slides({
            preload: true,
            preloadImage: 'images/slider/product-slider/loading.gif',
            play: 5000,
            pause: 2500,
            hoverPause: true,
            animationStart: function(current){
                $J('.caption').animate({
                bottom:-35
                },100);
					
                },
                animationComplete: function(current){
                    $J('.caption').animate({
                    bottom:0
                    },200);					
                }
            }); 
        }
};
//Tabs
Namespace("Egreat.Product.Tabs");
Egreat.Product.Tabs={
    details:{
        'id':1,
        'currentTab':'descriere'
    },
    init:function(params)
        {
        $J.extend(this.details,params||{});
        //currently selected tab
        if(location.href.indexOf("#") != -1)
            {
            var tab=location.href.substr(location.href.indexOf("#")).substring(1);
            $Product.Tabs.focusTab(tab);
            }
        else
            {
            $Product.Tabs.focusTab('descriere');//default    
            }
        $J('#meniu-produse ul > li').each(function(index)
            {
            $J(this).click(function(el){ $Product.Tabs.focusTab(el.target.id.replace('prod_l_','')); });
            });
        },
    focusTab:function(tab)
        {
        parent.location.hash = '';
        var url=location.href.replace('#','');
        location.href=url+'#'+tab;
        $J('#prod_l_'+tab).addClass('focus');
        if(this.currentTab!='')
            {
            $J('#prod_l_'+this.currentTab).removeClass('focus');
            $J('#prod-c-'+this.currentTab).hide(); 
            }
        $J('#prod-c-'+tab).show();
        this.currentTab=tab;
        }
};
$Product=Egreat.Product;
/* ----------------------------- Product Page ----------------------------------- */
