// JavaScript Document
jQuery.noConflict();

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

jQuery(document).ready(function(){	
		
	jQuery('#tier_slider').jcarousel({
        auto: 4,
		visible: 1,
		scroll: 1,
		wrap: 'both',
        /*initCallback: mycarousel_initCallback,*/
		buttonNextHTML: null, 
		buttonPrevHTML: null
    });
	
	
	jQuery('#product_carousel_div').jcarousel({
        auto: 2,
		visible: 4,
		scroll: 1,
        initCallback: mycarousel_initCallback,
        wrap: 'both',
        /*itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},*/
		buttonNextHTML: '<div id="product_carousel_next"> </div>', 
		buttonPrevHTML: '<div id="product_carousel_prev"> </div>'
    });
	
	
	/*jQuery("#tier_slider").easySlider({
		auto: true,
		continuous: false,
		speed: 600,
		pause: 3400,
		controlsShow: false
	});
    jQuery("#product_carousel_div").jCarouselLite({
        btnNext: "#product_carousel_next",
        btnPrev: "#product_carousel_prev",
		visible: 4,
		circular: true,
		easing: "easeInOutQuad",
		speed: 1000,
		auto: 1000
    });*/

});


//have a form validated by class="required" by adding onsubmit="return checkRequired(this)" to the form tag
function checkRequired(form){
    var els=form.elements;
    errorFields=new Array("Please provide valid information for: \n");
    var failed=0;
    for(b=0;b<els.length;b++){
        if(els[b].className=="required" || els[b].className.indexOf('required') >= 0){
			if(els[b].value.length<2){
				if(els[b].title){
					errorFields.push(els[b].title)
				}else{
					errorFields.push(els[b].name)
				}
				failed=1
			}
			if(els[b].name.indexOf('Email') >= 0 && failed==0){
				if(!is_valid_email(els[b].value)){
					if(els[b].title){
						errorFields.push(els[b].title)
					}else{
						errorFields.push(els[b].name)
					}
				}
			}
		}
		failed=0
	}

	//display errors
    if(errorFields.length>1){
        var alertText="";
        for(a=0;a<errorFields.length;a++){
        	alertText+=errorFields[a]+"\n"
        }
        alert(alertText);
        return false;
    }else{
        return true;
    }
}

function is_valid_email(email){
	return/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email)
}

