File: D:/HostingSpaces/SBogers10/spire.komma-mediadesign.nl/wwwroot/js/VertGridSlider.js
/**
* Created by Komma-mediadesign.
* User: Mike
* Date: 3/13/13
* Time: 3:11 PM
*/
function VerticalGridSlider(slider){
var t = this;
/*
* @property gridSize;
* The slider slides on a grid
*/
t.gridSize = 246;
/*
* @property viewport
* width of the viewport
*/
t.viewport = 738;
/*
* @property slider
*/
t.slider = slider;
/*
* @property numItems
*/
t.numItems = 0;
/*
* @property itemsInView
*/
t.itemsInView = 0;
/*
* @property hiddenLeft
*/
t.hiddenLeft = 0;
/*
* @property hiddenRight
*/
t.hiddenRight = 0;
/*
* @property index
*/
t.index = 0;
t.btnNext = '#relatedNext';
t.btnPrev = '#relatedPrev';
this.init = function()
{
// set num items
t.numItems = ($('li',t.slider).size());
// set slider size
var w = t.gridSize * t.numItems;
$(t.slider).css({ width : w+'px' });
// set Items in view
t.itemsInView = Math.floor(t.viewport / t.gridSize);
// set Items in view
t.hiddenRight = t.numItems - t.itemsInView;
// set on click functions
$(t.slider+' li').each(function(index)
{
$(this).click(function(e){
e.preventDefault();
var a = $('a',this);
$('body').append('<div id="jsLoad"></div>');
$('#jsLoad').load('/mvc/controllers/c_gridSlider.php?index='+index+'&hiddenLeft='+ t.hiddenLeft+'&hiddenRight='+ t.hiddenRight+'&offsetTop='+$(document).scrollTop(), function(){
window.location.href = $(a).attr('href');
});
});
});
// set on click buttons
$(t.btnNext).click(function(e){
t.slide(1);
});
$(t.btnPrev).click(function(e){
t.slide(-1);
});
};
this.setGridSize = function(size)
{
t.gridSize = parseInt(size);
};
this.setViewport = function(size)
{
t.gridSize = parseInt(size);
};
this.setButtons = function(left,right)
{
t.btnNext = parseInt(right);
t.btnPrev = parseInt(left);
};
this.slide = function(dir)
{
var left = null;
var steps = 3;
/*
* If over half of the viewport
*/
if(dir == 1)
{
if((t.hiddenLeft + 3) != t.numItems)
{
t.hiddenLeft += steps;
left = t.hiddenLeft * t.gridSize * -1;
$(t.slider).stop().animate({ left : left+'px' },500);
}
}
if(dir == -1)
{
if(t.hiddenLeft != 0)
{
t.hiddenLeft -= steps;
left = t.hiddenLeft * t.gridSize * -1;
$(t.slider).stop().animate({ left : left+'px' },500);
}
}
if(t.hiddenLeft <= 0)
{
$('#relatedProducts .arrowLeft').stop().animate({ opacity: 0 },200);
$(t.btnPrev).css({ display: 'none'});
}
else
{
$('#relatedProducts .arrowLeft').stop().animate({ opacity: 1 },200);
$(t.btnPrev).css({ display: 'block'});
}
if((t.hiddenLeft + 3) >= t.numItems)
{
$('#relatedProducts .arrowRight').stop().animate({ opacity: 0 },200);
$(t.btnNext).css({ display: 'none'});
}
else
{
$('#relatedProducts .arrowRight').stop().animate({ opacity: 1 },200);
$(t.btnNext).css({ display: 'block'});
}
};
}