$(document).ready(function(){
	
	$('#slideshow').jqFancyTransitions({ width: 640, height: 226, effect:'', strips: 10, links : false, delay: 4000, position: 'top', direction: 'left', navigation:false });
	$('.lightbox').lightBox({fixedNavigation:true});

	$("a.bookmark").click(function(e){
		e.preventDefault();
		var url = this.href;
		var title = this.title;

		if (window.sidebar) { 
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { 
			window.external.AddFavorite( url, title);
		} else if(window.opera) { 
			return false; 
		} else { 
			 alert('Sorry, your browser does not support the requested action,'
			 + ' please add this page manually to your bookmarks.');
		}
	});

	// headline scroll content
	var headline_count;
	var headline_interval;
	var old_headline = 0;
	var current_headline = 0;
	headline_count = $("div.headline").size();
	$("div.headline:eq("+current_headline+")").css('top','0px');
	headline_interval = setInterval(headline_rotate,7000); //time in milliseconds
	
	function headline_rotate() {
		current_headline = (old_headline + 1) % headline_count; 
		$("div.headline:eq(" + old_headline + ")").animate({top: -170},"slow", function() {
		$(this).css('top','170px');
		});
		$("div.headline:eq(" + current_headline + ")").show().animate({top: 0},"slow");  
		old_headline = current_headline;
	}

	// add item to basket
	$('.button-add').click(function(e){
		e.preventDefault();
		var id = $(this).attr('id').replace('prodId-','');
		var q = $('#quantity-'+id);
		var qv = q.val();
		var min = $('#min-'+id).attr('title');

		if (qv != '') {
			if ( parseInt(qv) == 0 || parseInt(qv) < parseInt(min) ) {
				q.addClass('error');
				if ( parseInt(qv) == 0 ) {
					alert('your quantity must be more than 0!');
				} else {
					alert('minimum order must be more than '+min);
				}
				return false;
			} else {
				$.post('/resources/vb/post-basket-item.asp',{
				id:id,
				quantity:qv
				},function(response){
					if (response != '') {
						q.val('');
						q.removeClass('error');
						$('#basket').fadeOut(20);
						$('#basket').animate({opacity: 1.0}, 300)
						$('#basket').load('/resources/vb/post-get-basket.asp',{basket:response});
						$('#basket').fadeIn(150);
					}
				});
			}
		} else {
			q.addClass('error');
		}
	});

	function getbasket(basket) {
		$('#basket').empty();
		$('#basket').load('/resources/vb/post-get-basket.asp',{basket:basket});
		//clearConsole();
	}
	getbasket('');

});
