var basicClass = function() {
	var self = this;	
	var lockButton = false;

	//menu customerlogin slider
	this.menuCustomerLogin = function() {
		
		$('#menu-customerlogin .title').click(function() {
			$('#menu-customerlogin ul').slideToggle(300);
		});
		
	};
	
	//menu main scroll with page
	this.menuMainScroll = function() {
	
		var $scrollingDiv = $('#menu-main');
		var startToScroll = 245;
		var menuMarginTop = 30; //$scrollingDiv.outerHeight(true) - $scrollingDiv.outerHeight(); //get margin-top
		var menuMarginBottom = 30;
		var menuHeight = $scrollingDiv.height();
		var footerHeight = $('#footer').height();
		var documentHeight = $(document).height();
 
		$(window).scroll(function(){	

			scrollTop = $(window).scrollTop();
			maxScroll = documentHeight - scrollTop - footerHeight - menuHeight - menuMarginTop - menuMarginBottom;
			//console.log( scrollTop + ' ' + maxScroll + ' ' + ( documentHeight - menuHeight - menuMarginTop - menuMarginBottom - footerHeight) );
			
			if( scrollTop >= startToScroll && maxScroll >= 0 )
			{
				$scrollingDiv
					.stop()
					.animate({"marginTop": ( scrollTop - startToScroll + menuMarginTop ) + "px"}, "slow" );
					
				//show goto top button
				//console.log( lockButton );
				
				if(lockButton == false) $('#side-right .goto-top').fadeIn(400);
			}
			else if( maxScroll <= 0 )
			{
				$scrollingDiv
					.stop()
					.animate({"marginTop": ( documentHeight - menuHeight - menuMarginBottom - footerHeight - startToScroll ) + "px"}, "slow" );
					
			}
			else
			{
				$scrollingDiv
					.stop()
					.animate({"marginTop": ( menuMarginTop ) + "px"}, "slow" );
				
				//hide goto top button	
				$('#side-right .goto-top').fadeOut(400);
				lockButton = false;
			}
		});

		//scroll to top button
		$('#side-right .goto-top').hide();
		
		$('#side-right .goto-top').click( function() {
			$.scrollTo( '#header', 500 );
			$( this ).fadeOut(400);
			lockButton = true;
			return false;
			//console.log(lockButton);
		});
	
	};
	
	//article list scroll
	this.articleListScroll = function() {
	
		$('#content .mod_articleList a[href*=#]').bind('click', function(event) {
			
			var target = $(this).attr('href').split("#");; // Get scroll target
			$.scrollTo( '#' + target[1] , 500 );
			
			return false;
			
		});	
			
	};
	
	//box bg animation
	this.boxBgAnimation = function() {
		
		$('#content .box').hover(
			function() {
				$(this).stop().animate( { backgroundPosition: '0px -250px'}, 300 );
			},
			function() {
				$(this).stop().animate( { backgroundPosition: '0px 0px' }, 300 );
			}
		);
		
	};
	
	//Layout Select fields
	this.selectBox = function() {
		
		$('#content select.select').selectBox();
		
	};
	
	//Generate Nivo Slider Gallery
	this.nivoSlider = function() {
	
		$('#content .nivoSlider').nivoSlider({
			controlNavThumbs:true,
			controlNavThumbsFromRel:true,
			pauseTime:3000
		});
	
	}
		
};


var basic = new basicClass();

$(function(){

	basic.menuCustomerLogin();
	basic.menuMainScroll();
	basic.articleListScroll();
	basic.boxBgAnimation();
	basic.selectBox();
	basic.nivoSlider();

});
