jQuery(document).ready(function() {
	jQuery('#next').click(function() {
		counter++;
		if(counter > pNavLength){
			counter = 7;
			jQuery("#portfolioNav ul").animate({"left": "0px"}, "fast");
		} else {
			jQuery("#portfolioNav ul").animate({"left": "-=125px"}, "fast");
		}
	});
	jQuery('#prev').click(function() {
		counter--;
		if(counter == 6){
			counter = pNavLength;
			var posR = (pNavLength-7) * 125;
			jQuery("#portfolioNav ul").animate({"left": "-="+posR+"px"}, "fast");							
		} else {
			jQuery("#portfolioNav ul").animate({"left": "+=125px"}, "fast");
		}
	});
	
	jQuery('input[title], textarea[title]').each(function() {
		if(jQuery(this).val() === '') {
			jQuery(this).val(jQuery(this).attr('title'));	
		}
		
		jQuery(this).focus(function() {
			if(jQuery(this).val() == jQuery(this).attr('title')) {
				jQuery(this).val('').addClass('focused');	
			}
		});
		jQuery(this).blur(function() {
			if(jQuery(this).val() === '') {
				jQuery(this).val(jQuery(this).attr('title')).removeClass('focused');	
			}
		});
	});
	
	jQuery('ul#imgrotate').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '258px'
	});
	jQuery('ul.banners').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '80px'
	});
	if(module == 'products') jQuery('.field').numeric();
	
	jQuery('#contactform').submit(function() {
	  	// get all the required fields
	   	var $inputs = jQuery('#contactform .text, #contactform .ctext, #contactform .text');
		var values = {};
		var missingFields = false;
		var val276 = '';
		var val277 = '';
		
		$inputs.each(function() {
			// check if required field and filled inn
			if(jQuery(this).hasClass('required')){
				if(jQuery(this).val() == jQuery(this).attr('title')){
					alert(completeForm);
					missingFields = true;
					return false;			
				} else {
					// check for email
					if(jQuery(this).attr("id") == 'field_3'){
						var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
						if (!filter.test(jQuery(this).val())){
							alert(completeForm);
							missingFields = true;
							return false;		
						}
					}
				}
			}
		});
		
		if(missingFields == false){
			// check if field 276 and 277 on the form and one of them is filled in
 			if(jQuery('#field_276').length > 0) val276 = jQuery("#field_276").val();
			if(jQuery('#field_277').length > 0) val277 = jQuery("#field_277").val();
			if(val276 != '' && val277 != ''){
				if(val276 == '0' && val277 == '0'){
					alert(selectStudio);
					return false;			
				} else if(val276 != '0' && val277 != '0') {
					alert(selectStudioOnce);
					return false;	
				} else {
					$inputs.each(function() {
						if(jQuery(this).val() == jQuery(this).attr('title')){
							jQuery(this).val('');
						}
					});
				}
			} else {
				// if submit -> empty not filled in fields
				$inputs.each(function() {
					if(jQuery(this).val() == jQuery(this).attr('title')){
						jQuery(this).val('');
					}
				});
			}
		} else {
			return false;	
		}
	});
});

if(module == 'contactform'){
	function addFormField(nrs) {
		var nr_children = document.getElementById("nr_children").value;
		if(nr_children < nrs){ 
			for(var id=nr_children;id<nrs;id++){
				jQuery("#divTxt").append("<div id='row" + id + "' class='childdiv'><label for='txt" + id + "' >"+ lblChild + " " + (parseInt(id)+1) + "</label><table cellpadding='0' cellspacing='0'><tr><td>"+lblChildName+"&nbsp;</td><td>:&nbsp;<input type='text' name='txt[]' id='txt" + id + "' class='ctext' ></td></tr><tr><td>"+lblChildGBDate+"&nbsp;</td><td>:&nbsp;<input type='text' name='gbdat[]' id='gbdat" + id + "' class='ctext date'></td></tr></table></div>");
				var tmp = document.getElementById('divTxt').innerHTML;
			}
		} else {
			for(var id=nr_children-1;id>=nrs;id--) removeFormField("#row" + id);
		}
		jQuery(".date").unmask();
		jQuery(".date").mask("99/99/9999");
		nr_children = (nrs);
		document.getElementById("nr_children").value = nr_children;
	}
	function removeFormField(id) {
		jQuery(id).remove();
	}
	jQuery(function($){
		jQuery(".date").unmask();
		jQuery(".date").mask("99/99/9999");
		jQuery("select, input.ctext, textarea").uniform();
	});
	
	
}
