//--|BASICVARS----------

var ocontainer;
var ocontent;
var spaceToScroll;

var intOverallDelta = 0;



//--|FUNCTIONS----------

function updateDragger(){
	if ( 
		$('#finder .scrollbar').length 
		|| $('#compare .scrollbar').length 
		|| $('#faq .scrollbar').length 
	){
		// update scrollbar size
		contentSize = jQuery.iUtil.getSize(ocontent.get(0));
		indicatorHeight = containerInner.h * containerSize.hb / contentSize.hb;

		if( indicatorHeight > containerInner.h ){
			indicatorHeight = containerInner.h;
		}

		// update dragger position
		$('div.indicator').css('height', indicatorHeight  + 'px');
	
		// recalculate scrolling space
		spaceToScroll = contentSize.hb - containerInner.h;
		if (spaceToScroll < 0) {
			spaceToScroll = 0;
		}
	
		// update position
		$('.scrollbar').SliderSetValues([ [20, 0], [200, 200]	]);
	}
}



function updateDraggerLightbox(id){
	// update scrollbar size
	contentSize_lb = jQuery.iUtil.getSize(ocontent_lb.get(0));

	/*indicatorHeight_lb = containerInner_lb.h * containerSize_lb.hb / contentSize_lb.hb	

	if (indicatorHeight_lb > containerInner_lb.h) {
		indicatorHeight_lb = containerInner_lb.h;
	}

	// update dragger position
	$('div.indicator').css('height', indicatorHeight_lb  + 'px')*/
	
	// recalculate scrolling space
	spaceToScroll_lb = contentSize_lb.hb - containerInner_lb.h;

	if (spaceToScroll_lb < 0) {
		spaceToScroll_lb = 0;
		$('#' + id + ' .scrollbar').css('display', 'none');
		$('#' + id + ' .scrollbar_arrow_up').css('display', 'none');
		$('#' + id + ' .scrollbar_arrow_down').css('display', 'none');
	}
	
	// update position
	$('.scrollbar').SliderSetValues([	[20, 0], [200, 200]	])
}



//--|HOOKS----------

$(document).ready(function(){
		// mousewheel support
		$("body").mousewheel(function(objEvent, intDelta){
			if( intDelta > 0 ){
				intOverallDelta++;
				
				$('.scrollbar').SliderSetValues([	[20, -9],	[200,200]	]);
			} else if( intDelta < 0 ){
				intOverallDelta--;
				
				$('.scrollbar').SliderSetValues([	[20, +9], [200, 200] ])
			}
		});

		/*if( $('#device_details #comment .scrollbar').length ){
			ocontainer_lb = $('#comment .scroll_container');
			ocontent_lb = $('#comment .scroll_content');
      oindicator_lb = $('#comment .indicator');

      containerSize_lb = jQuery.iUtil.getSize(ocontainer_lb.get(0));
      containerPosition_lb = jQuery.iUtil.getPosition(ocontainer_lb.get(0));
      containerInner_lb = jQuery.iUtil.getClient(ocontainer_lb.get(0));
      containerSize_lb = jQuery.iUtil.getSize(ocontent_lb.get(0));


      $('#comment div.scrollbar_arrow_up').click(function(){
				$('#comment .scrollbar').SliderSetValues([ [20, -9], [200, 200] ]);
        return false;
      });

	    $('#comment div.scrollbar_arrow_down').click(function(){
        $('#comment .scrollbar').SliderSetValues([ [20, +9], [200, 200] ]);
        return false;
      });

      $('#comment .scrollbar').Slider({
        accept : '.indicator',
        onSlide : function(cordx, cordy, x , y){
          $('#comment .scroll_content').css('top', - spaceToScroll_lb * cordy / 100 + 'px');
        }
      });

      updateDraggerLightbox('comment');
		} else if( $('#device_details #mba_features .scrollbar').length ){
			ocontainer_lb = $('#mba_features .scroll_container');
			ocontent_lb = $('#mba_features .scroll_content');
      oindicator_lb = $('#mba_features .indicator');

      containerSize_lb = jQuery.iUtil.getSize(ocontainer_lb.get(0));
      containerPosition_lb = jQuery.iUtil.getPosition(ocontainer_lb.get(0));
      containerInner_lb = jQuery.iUtil.getClient(ocontainer_lb.get(0));
      containerSize_lb = jQuery.iUtil.getSize(ocontent_lb.get(0));


      $('#mba_features div.scrollbar_arrow_up').click(function(){
				$('#mba_features .scrollbar').SliderSetValues([ [20, -9], [200, 200] ]);
        return false;
      });

	    $('#mba_features div.scrollbar_arrow_down').click(function(){
        $('#mba_features .scrollbar').SliderSetValues([ [20, +9], [200, 200] ]);
        return false;
      });

      $('#mba_features .scrollbar').Slider({
        accept : '.indicator',
        onSlide : function(cordx, cordy, x , y){
          $('#mba_features .scroll_content').css('top', - spaceToScroll_lb * cordy / 100 + 'px');
        }
      });

      updateDraggerLightbox('mba_features');
		} else {*/
			ocontainer	= $('.scroll_container');
			ocontent	= $('.scroll_content');
			oindicator	= $('.indicator');
		
			containerSize		= jQuery.iUtil.getSize(ocontainer.get(0));
			containerPosition	= jQuery.iUtil.getPosition(ocontainer.get(0));
			containerInner		= jQuery.iUtil.getClient(ocontainer.get(0));
			contentSize		= jQuery.iUtil.getSize(ocontent.get(0));
		
			// initialize slider
			/*$('div.scollbar')
				.css('top', containerPosition.y + 'px')
				.css('left', containerPosition.x + containerSize.wb + 'px')
				.css('height', containerSize.hb + 'px');
			*/
			$('div.scrollbar_arrow_up').click(function(){
				$('.scrollbar').SliderSetValues([	[20, -9],	[200, 200] ]);
				return false;
			});

			$('div.scrollbar_arrow_down').click(function(){
				$('.scrollbar').SliderSetValues([	[20, +9],	[200, 200] ]);
				return false;
			});

			$('#faq .scrollbar').Slider({
				accept : '.indicator',
				onSlide : function(cordx, cordy, x , y){
					$('#faq_content .scroll_content').css('top', - spaceToScroll * cordy / 100 + 'px');
				}
			});
		
			$('#compare .scrollbar').Slider({
	      accept : '.indicator',
	      onSlide : function(cordx, cordy, x , y){
          $('#compare_container .scroll_content').css('top', - spaceToScroll * cordy / 100 + 'px');
        }
      });

			$('#finder .scrollbar').Slider({
				accept : '.indicator',
				onSlide : function(cordx, cordy, x , y){
					$('#container .scroll_content').css('top', - spaceToScroll * cordy / 100 + 'px');
				}
			});
		
			updateDragger();
		//}
	}
);