var WhyTrendstop = Object();


	WhyTrendstop.Storage = {
	    CurrentItem: null,
	    PreviousItem: null,
	    CurrentGender: null,
	    MoveLeftBy: 784,
	    Speed: 1000,
	    Moving: false,
		BlockRun: 0,
		TotalItems: 6
	}
	
	WhyTrendstop.Settings = {
	    PrefixId: {
			FullContent: 'case_studies_popup',
			InnerContent: 'case_studies_wrapper',
	        ItemMover: 'why_ts_wrapper_content',
	        ItemToEffect: 'why_ts_item_',
	        PrevNav: 'why_larrow',
	        NextNav: 'why_rarrow'
	        	
	    },
	    CssClass: {}
	}

	WhyTrendstop.Show = function(iId)
	{
		advAJAX.post({
	        url: '/',
	        mode: 'ajax',
	        act: 'why_trendstop',
	        action: 'get',
	        _type: 'ajax',
	        _fetch: 'content',
	        id: iId,
	        onLoading: function(){
	            Popup.Loader()
	        },
	        onSuccess: function(Obj){
	        	// setting the current item
	        	WhyTrendstop.Storage.CurrentItem = iId;
            	Popup.AjaxShowContent(Obj.responseText, 'what_we_offer_popup');
            	
            	WhyTrendstop.RefreshNavigation();
            	if( iId > 1 )
            	{
            		WhyTrendstop.Slide()
            	}
	        }
	    })	    	
	}
	
	
	WhyTrendstop.Navigate = function(Option){
		if(WhyTrendstop.Storage.Moving) return;
		
		WhyTrendstop.MoveStart();
		
	    if (!Option) 
	        return;
	    
	    WhyTrendstop.Storage.PreviousItem = WhyTrendstop.Storage.CurrentItem;
	    
	    $(WhyTrendstop.Settings.PrefixId.ItemToEffect + WhyTrendstop.Storage.CurrentItem).style.display  = 'block';
	    
	    if( isNaN(Option) )
	    {
	    	WhyTrendstop.Storage.CurrentItem = (Option == 'next') ? WhyTrendstop.Storage.CurrentItem + 1 : WhyTrendstop.Storage.CurrentItem - 1;
	    }
	    else
	    {
	    	WhyTrendstop.Storage.CurrentItem = Option;
	    }
	    WhyTrendstop.RefreshNavigation();
	    WhyTrendstop.Slide();
	}	
	
	WhyTrendstop.RefreshNavigation = function()
	{
	    var ObjPrev = $(WhyTrendstop.Settings.PrefixId.PrevNav);
	    var ObjNext = $(WhyTrendstop.Settings.PrefixId.NextNav);

	    //Previous Functionality
	    if (WhyTrendstop.Storage.CurrentItem &&
	    	WhyTrendstop.Storage.CurrentItem > 1) 
	    {
	        ObjPrev.style.display = 'block';
	        
	    }
	    else {
	        ObjPrev.style.display = 'none';
	    }
	    
	    //Next Functionality
	    if (WhyTrendstop.Storage.CurrentItem >= 0 && 
	    	WhyTrendstop.Storage.CurrentItem < WhyTrendstop.Storage.TotalItems) 
	    {
	        ObjNext.style.display = 'block';
	    }
	    else {
	        ObjNext.style.display = 'none';
	    }
	    
	    
	}
	
	
	WhyTrendstop.Slide = function(){
	    var ObjMover = $(WhyTrendstop.Settings.PrefixId.ItemMover);
	    Calculate = WhyTrendstop.CalculateSlide();
	    if (WhyTrendstop.Storage.PreviousItem == null) {
	        ObjMover.style.left = Calculate + 'px';
	    }
	    else {
	    	WhyTrendstop.Storage.Moving = true;
	        new Effect.Move(ObjMover, {
	            x: Calculate,
	            y: 0,
	            duration: 0.8,
	            mode: 'relative',
				afterFinish: function() {
					WhyTrendstop.MoveStop();
				}
	        });
	        WhyTrendstop.AnimationEffect();
	    }
	}	
	
	WhyTrendstop.MoveStart = function(){
		WhyTrendstop.Storage.Moving = true;
	}

	
	WhyTrendstop.MoveStop = function(){
		WhyTrendstop.Storage.Moving = false;
	}
	
	WhyTrendstop.CalculateSlide = function(){
	    if (WhyTrendstop.Storage.PreviousItem == null) {
	        Calculate = WhyTrendstop.Storage.MoveLeftBy * (WhyTrendstop.Storage.CurrentItem-1);
	        Calculate = (Calculate > 0) ? -Calculate : Calculate;
	    }
	    else {
	    	Calculate = (WhyTrendstop.Storage.PreviousItem - WhyTrendstop.Storage.CurrentItem) * WhyTrendstop.Storage.MoveLeftBy;
	    }
	    return Calculate;
	}
	

	WhyTrendstop.AnimationEffect = function(){
		var ObjMover = $(WhyTrendstop.Settings.PrefixId.ItemToEffect + WhyTrendstop.Storage.CurrentItem);
		
		new Effect.Fade(ObjMover, {
	        duration: 3.5,
	        from: 0,
	        to: 1
	    });
	    
	}
	
	/*
	WhyTrendstop.Hide = function ()
	{
		var OverBodyContainer = $(Popup.Settings.PrefixId.OverBodyContent);
		var PopupContainer = $(Popup.Settings.PrefixId.PopupId);
		var PopupContent = $(Popup.Settings.PrefixId.ContentId);
		if(PopupContainer){

			PopupContainer.style.display = 'none';
			
			if (OverBodyContainer) {
				OverBodyContainer.removeClassName(Popup.Settings.CssClass.ShowOverBody);
				OverBodyContainer.style.display = 'none';
			}
			
			if(Popup.Storage.AjaxLoad == 1){
				Popup.Storage.AjaxLoad = null;
			}
			
			Popup.SelectInputEIFix(1);
			Popup.Storage.Active = null;
			Popup.Storage.ContentById = null;
		}else{
			return;
		}		
	}
	*/
	

	
