function frmchng(val)	{

	for(i=0;i<document.getElementById('project').length;i++)	{
		if(document.getElementById('project').options[i].value==val)	{
			document.getElementById('project').selectedIndex=i;
		}
	}

}

function clearField (thisfield, placeholder) {
	if (thisfield.value == placeholder) {
		thisfield.value = '';
	}
}

function labelField(tfield,placeholder) {
	if (tfield.value == '') {
		tfield.value = placeholder;
	}
}

$(document).ready(function(){

	$("#contentInnerWrap").find("div.move_box").each(function() {
		var moveBoxContent = $(this).find("div.move_box_content");
		var thumbLinks = moveBoxContent.find("a");
		var fullImgs = $(this).parent().siblings("div.cTeaser_type_special_img_box").children("a");
		
		thumbLinks.bind("click",function() {
			var selectedImg = fullImgs.eq(thumbLinks.index($(this)));
			fullImgs.hide();
			selectedImg.show();
		});

		var bottomNav = $(this).find("div.move_box_bottom_nav").find("a.bullet");
	    var boxCount = moveBoxContent.size();
	    var boxWidth = moveBoxContent.width();
	    var maskWidth = $(this).find('div.move_box_mask').width();
	    var containerWidth = boxCount*maskWidth;
	    var moveBoxContainer = $(this).find("div.move_box_content_container");
	    moveBoxContainer.css("width",containerWidth+"px");
	    var m = containerWidth / boxCount;
    	var mcalc = boxCount - 1;
    	var mv = false;
    	var buttonPrev =  $(this).find("a.prev");
    	var buttonNext =  $(this).find("a.next");

    	buttonPrev.click(function() {
	        var cm = parseInt(moveBoxContainer.css('margin-left'));
	        if (isNaN(cm)) cm = 0;
	        
	        var canMove = false;
			for (var i = 0; i < boxCount; i++){
				if (cm == 0 - m * i){
					canMove = true;
				}
			}
			if(!canMove) return false;

	        bottomNav.removeClass("active");
	        if (cm < 0) {
	            moveBoxContainer.animate({
	                marginLeft: cm + m
	            },
	            'normal');

                var bottomNavIndex = cm/m * -1 -1;
	            bottomNav.eq(bottomNavIndex).addClass("active");
	        } else {
	            moveBoxContainer.animate({
	                marginLeft: 0 - m * mcalc
	            },
	            'slow');

	            var bottomNavIndex = boxCount -1;
	            bottomNav.eq(bottomNavIndex).addClass("active");
	        }
    	});

    	buttonNext.click(function() {
	        var cm = parseInt(moveBoxContainer.css('margin-left'));
	        if (isNaN(cm)) cm = 0;
	        
			var canMove = false;
			for (var i = 0; i < boxCount; i++){
				if (cm == 0 - m * i){
					canMove = true;
				}
			}
			if(!canMove) return false;

		 	bottomNav.removeClass("active");
		    if (cm > 0 - m * mcalc) {
	            moveBoxContainer.animate({
	                marginLeft: cm - m
	            },
	            'normal');

				 var bottomNavIndex = cm/m * -1 + 1;
	             bottomNav.eq(bottomNavIndex).addClass("active");
	        } else {
	            moveBoxContainer.animate({
	                marginLeft: 0
	            },
	            'slow');
	            bottomNav.eq(0).addClass("active");
		    }
    	});

    	bottomNav.bind("click",function() {
    		var link = $(this);
    	    bottomNav.removeClass("active");
    	    link.addClass("active");
    	    moveBoxContainer.animate({
	        		marginLeft:  -m * link.index()
	            },
    	        'normal');
		});
	});
});
