var counter = 1;
var margin = 0;
var selectedButton = 0;

var Slider = {
	init: function() {
		$("#viewport").css({width:"1020px", overflow:"hidden", marginLeft:"2px"});
		$("#widecontainer").css({width:"4080px"});
		if(($.browser.msie) && ($.browser.version <= 6.0)){
	    	$(".feat_block").css({width:"945px", marginLeft:"25px"});
	  	}
	
		$("a.feat1").toggleClass("feat1_selected");
		selectedButton = 1;
		
		$("a.next").click(function(){
			if(counter < 4){
				Slider.moveRight();
				counter++;
			} else if (counter >= 4) {
				Slider.goToView1();
				counter = 1;
			}
			Slider.changeButton();
		});
		$("a.feat1").click(function(){
			if(counter != 1){
				Slider.goToView1();
				counter = 1;
				Slider.changeButton();
			}
		});
		$("a.learn_more_about_sams_process").click(function(){
			if(counter != 2){
				Slider.goToView2();
				counter = 2;
				Slider.changeButton();
			}
		});
		$("a.learn_more_about_sams_process").attr("href", "javascript:;");
		$("a.feat2").click(function(){
			if(counter != 2){
				Slider.goToView2();
				counter = 2;
				Slider.changeButton();
			}
		});
		$("a.what_to_expect_from_syscal").click(function(){
			if(counter != 3){
				Slider.goToView3();
				counter = 3;
				Slider.changeButton();
			}
		});
		$("a.what_to_expect_from_syscal").attr("href", "javascript:;");
		$("a.feat3").click(function(){
			if(counter != 3){
				Slider.goToView3();
				counter = 3;
				Slider.changeButton();
			}
		});
		$("a.contact_syscal_and_learn_more").click(function(){
			if(counter != 4){
				Slider.goToView4();
				counter = 4;
				Slider.changeButton();
			}
		});
		$("a.contact_syscal_and_learn_more").attr("href", "javascript:;");
		$("a.feat4").click(function(){
			if(counter != 4){
				Slider.goToView4();
				counter = 4;
				Slider.changeButton();
			}
		});
		$("ul.slider_nav li a").each(function(){
			$(this).attr("href", "javascript:;");
		});
	},
	moveRight: function() {
		margin = margin - 970;
		$("#widecontainer").animate({
			marginLeft: margin + "px"
		}, 500);
	},
	goToView1: function() {
		margin = 0;
		$("#widecontainer").animate({
			marginLeft: margin + "px"
		}, 500);
	},
	goToView2: function() {
		margin = -970;
		$("#widecontainer").animate({
			marginLeft: margin + "px"
		}, 500);
	},
	goToView3: function() {
		margin = -1940;
		$("#widecontainer").animate({
			marginLeft: margin + "px"
		}, 500);
	},
	goToView4: function() {
		margin = -2910;
		$("#widecontainer").animate({
			marginLeft: margin + "px"
		}, 500);
	},
	changeButton: function() {
		//deselect currently selected button first
		Slider.deselectButton();
		
		if(counter == 1) {
			$("a.feat1").toggleClass("feat1_selected");
			selectedButton = 1;
		} else if(counter == 2) {
			$("a.feat2").toggleClass("feat2_selected");
			selectedButton = 2;
		} else if(counter == 3) {
			$("a.feat3").toggleClass("feat3_selected");
			selectedButton = 3;
		} else if(counter == 4) {
			$("a.feat4").toggleClass("feat4_selected");
			selectedButton = 4;
		}
	},
	deselectButton: function() {
		if(selectedButton == 1) {
			$("a.feat1").toggleClass("feat1_selected");
		} else if(selectedButton == 2) {
			$("a.feat2").toggleClass("feat2_selected");
		} else if(selectedButton == 3) {
			$("a.feat3").toggleClass("feat3_selected");
		} else if(selectedButton == 4) {
			$("a.feat4").toggleClass("feat4_selected");
		}
	}
}

$(document).ready(function(){
	Slider.init();
});