(function(){
	ua = navigator.userAgent.toLowerCase(),	  
	check = function(r){
		return r.test(ua);
	}
	isOpera = check(/opera/),			  
	isIE = check(/msie/),
	isIE7 = isIE && check(/msie 7/),
	isIE8 =	isIE && check(/msie 8/),
	isIE6 =	isIE && !isIE7 && !isIE8,
	isChrome = check(/chrome/),
	isWebKit =check(/webkit/),
	isSafari =!isChrome && check(/safari/),
	isSafari2 =	isSafari && check(/applewebkit\/4/),
	isSafari3 = isSafari && check(/version\/3/),
	isSafari4 = isSafari && check(/version\/4/),
	isGecko = !isWebKit && check(/gecko/),
	isGecko2 = isGecko && check(/rv:1\.8/),
	isGecko3 = isGecko && check(/rv:1\.9/),
	isWindows = check(/windows|win32/),	
	isMac = check(/macintosh|mac os x/),	
	isAir = check(/adobeair/),	
	isLinux = check(/linux/),
	
	
	jQuery.extend(jQuery.browser, {
		isOpera: isOpera,
		isIE:	isIE,
		isIE7: isIE7,
		isIE8: isIE8,
		isIE6: isIE6,
		isChrome: isChrome,
		isWebKit: isWebKit,
		isSafari: isSafari,
		isSafari2: isSafari2,
		isSafari3: isSafari3,
		isSafari4: isSafari4,
		isGecko: isGecko,
		isGecko2: isGecko2,
		isGecko3: isGecko3,
		isWindows: isWindows,
		isMac: isMac,
		isAir: isAir,
		isLinux: isLinux
	});
})();

function addStyle(patch){
	var style = document.createElement('link');
	style.setAttribute('rel','stylesheet');
	style.setAttribute('type','text/css');
	style.setAttribute('href',patch);
	document.getElementsByTagName('head')[0].appendChild(style)	;	
}

jQuery(document).ready(function($){				   
	if($.browser.isIE6){
		addStyle('css/ie6fix.css');		
		$('#logo').pngFix();
	}	
	if($.browser.isSafari){
		//addStyle('css/safarifix.css');		
	}
	$.fn.sifr({ path: 'flash/' , font: 'avenir', save: true });
	$('#menu ul li').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});	
	$('#menu ul li a, #header #logo a').focus(function(){this.blur();});
	
});
function initHome(){
	/*
	$('#left-fish, #right-fish').pngFix();
	$('#home-ct #intro .header .text h2').sifr({
		color: '#3f3f3f',size:20, height:23, width:135
	});
	$('#home-ct #intro .intro-body p').sifr({
		color:'#8c8c8c', size:19, tA: 'center', height:60, width:780
	});
	$('#blocks #highlights .header .text h2, #blocks #testimonials .header .text h2').sifr({
		color: '#3f3f3f',size:17, height:23, width:205
	});
	$('#blocks #newsletter .header .text h2').sifr({
		color: '#3f3f3f',size:17, height:23, width:160
	});	
	*/
}
function initProduct(){
	/*
	$('#product-ct > .title-wrap > .title h2').sifr({
		color: '#3f3f3f',size:20, height:23, width:500
	});	
	$('#product-newsletter .header .text h2').sifr({
		color: '#3f3f3f', size:20,height:23, width:155
	});
	*/
	$('#product-viewport #side-panel ul li a').click(function(){
		var productId = $(this).attr('id').replace('product-', '');
		var self = this;
		$.ajax({
			url: 'product-detail.php',
			type: 'get',
			data: 'productId=' + productId,
			dataType: 'html',
			success: function(html){
				$('#product-content .content-body').html(html);
				$('#product-viewport #side-panel ul li').removeClass('active');
				$(self).parent().addClass('active');
			}
		});
		return false;
	});
	$('#product-viewport #side-panel ul li a').focus(function(){this.blur();});
	initProudctInfo();
	
	
}
function initProudctInfo(){
	/*
	$('#product-content .content-body .product-list .title h2').sifr({
		color: '#3f3f3f', size:15, height:23, width:120
	});
	*/
}

function initAbout(){
	/*
	$('#main-content p').sifr({
		color:'#8c8c8c', size:19, height:350, width:765, textAlign: 'left'
	});
	$('#product-ct .title h2').sifr({
		color: '#3f3f3f',size:20, height:23, width:500
	});		
	*/
}
function initContact(){
	/*
	$('#product-ct .title h2').sifr({
		color: '#3f3f3f',size:20, height:23, width:500
	});			
	*/
}
function initMinnFinnForms(){
	var KEYS_ALLOWED = {
		8: 'BACKSPACE',
		13: 'ENTER',
		37: 'LEFT_ARROW',
		39: 'RIGHT_ARROW',
		46: 'DELETE',
		48: 'ZERO',
		49: 'ONE',
		50: 'TWO',
		51: 'THREE',
		52: 'FOUR',
		53: 'FIVE',
		54: 'SIX',
		55: 'SEVEN',
		56: 'EIGHT',
		57: 'NINE'
	};
	
	$('#strength-form').each(function(){
		var self = this;
		$('#t_dose', this).val(10).attr('readOnly', true);	
		$('#tank_vol_l, #vol_for_tret_ml, #vol_for_tret_fl,#weight_for_neu_gal, #weight_for_neu_t, #weight_for_neu_gr', this).attr('readOnly', true);
		$('#tank_vol_g', this).keypress(function(e){
			if (KEYS_ALLOWED[e.keyCode]) {
				return (true);
			}
			else {
				return (false);
			}
		});
		$('#tank_vol_g', this).keyup(function(){
			var val = $(this).val();
			$('#tank_vol_l', self).val(new Number(val * 3.7854).toFixed(2));
			$('#vol_for_tret_ml', self).val(new Number(val * 0.4465).toFixed(2));
			$('#vol_for_tret_fl', self).val(new Number(val * 0.016).toFixed(2));
			$('#weight_for_neu_gal', self).val(new Number(val * 0.000625).toFixed(2));
			$('#weight_for_neu_t', self).val(new Number(val * 0.03).toFixed(2));
			$('#weight_for_neu_gr', self).val(new Number(val * 0.1697).toFixed(2));												
		});
	});	
	
	$('#max-form').each(function(){
		var self = this;
		$('#t_dose_r', this).val(10).attr('readOnly', true);
		$('#tank_vol_l_r, #vol_for_tret_ml_r, #vol_for_tret_fl_r,#weight_for_neu_gal_r, #weight_for_neu_t_r, #weight_for_neu_t_gr', this).attr('readOnly', true);
		$('#tank_vol_g_r', this).keypress(function(e){
			if (KEYS_ALLOWED[e.keyCode]) {
				return (true);
			}
			else {
				return (false);
			}
		});
		$('#tank_vol_g_r', this).keyup(function(){
			var val = $(this).val();
			$('#tank_vol_l_r', self).val(new Number(val * 3.7854).toFixed(2));
			$('#vol_for_tret_ml_r', self).val(new Number(val * 0.1250).toFixed(2));
			$('#vol_for_tret_fl_r', self).val(new Number(val * 0.0045).toFixed(2));
			$('#weight_for_neu_gal_r', self).val(new Number(val * 0.000625).toFixed(2));
			$('#weight_for_neu_t_r', self).val(new Number(val * 0.03).toFixed(2));	
			$('#weight_for_neu_t_gr', self).val(new Number(val * 0.1725).toFixed(2));												
														
		});
	});
}

function initDistributorForm(){
	$('#distributor-form form').validate({
		rules: {
			'company-name': {
				required: true
			},
			'email_distributor': {
				required: true,
				email: true
			},
			'contact-name': {
				required: true
			},
			'city': {
				required: true
			},
			'state': {
				required: true
			},
			'zip': {
				required: true
			},
			'telephone': {
				required: true
			}
		},
		errorPlacement: function(error, element) {
			$(element).addClass('error');
		}
		,submitHandler: function() {
			$('#distributor-form .fbar').addClass('loading');
			$('#distributor-form form').ajaxSubmit({
				dataType: 'json',
				type: 'post',
				success : function(result){
					$('#distributor-form .fbar').removeClass('loading');
					$('#user-name').html(result.username);
					$('#distributor-form').slideUp(400, function(){
							$('#contact-result').slideDown(400);																	
					});
				}
			});
		}
	});
	
	$('#contact-result #back').click(function(){
		$('#contact-result').slideUp(400, function(){
			$('#distributor-form').slideDown(400);									  
		});									  
		return false;								  
	});
}

function initDealerForm(){
	$('#distributor-form form').validate({
		rules: {
			'company-name': {
				required: true
			},
			'email_company': {
				required: true,
				email: true
			},
			'contact-name': {
				required: true
			},
			'city': {
				required: true
			},
			'state': {
				required: true
			},
			'zip': {
				required: true
			},
			'telephone': {
				required: true
			}
		},
		errorPlacement: function(error, element) {
			$(element).addClass('error');
		}
		,submitHandler: function() {
			$('#distributor-form .fbar').addClass('loading');
			$('#distributor-form form').ajaxSubmit({
				dataType: 'json',
				type: 'post',
				success : function(result){
					$('#distributor-form .fbar').removeClass('loading');
					$('#user-name').html(result.username);
					$('#distributor-form').slideUp(400, function(){
							$('#contact-result').slideDown(400);																	
					});
				}
			});
		}
	});
	
	$('#contact-result #back').click(function(){
		$('#contact-result').slideUp(400, function(){
			$('#distributor-form').slideDown(400);									  
		});									  
		return false;								  
	});	
	

}
function initDataCollection(){

	$('#data-collection-form').validate({
		rules: {
			'company-name': {
				required: true
			},
			'email_company': {
				required: true,
				email: true
			},
			'city': {
				required: true
			},
			'state': {
				required: true
			},
			'zip': {
				required: true
			},
			'telephone': {
				required: true
			},
			'product': {
				required: true
			},
			'date': {
				required: true
			},
			'dosage': {
				required: true
			},
			'nbrtreatment': {
				required: true
			},
			'effectiveness': {
				required: true
			},
			'species': {
				required: true
			},
			'nbrfish': {
				required: true,
				digits: true
			},
			'treatdate': {
				required: true
			},
			'temperature': {
				required: true,
				number: true
			},
			'ph': {
				required: true,
				number: true
			}			
		},
		errorPlacement: function(error, element) {
			$(element).addClass('error');
		}	
		,submitHandler: function() {
			$('#data-collection-form .fbar').addClass('loading');
			$('#data-collection-form form').ajaxSubmit({
				dataType: 'json',
				type: 'post',
				success : function(result){
					$('#data-collection-form .fbar').removeClass('loading');
					$('#user-name').html(result.username);
					$('#data-collection-form').slideUp(400, function(){
							$('#contact-result').slideDown(400);																	
					});
				}
			});
		}		
		
	});
	$('#contact-result #back').click(function(){
		$('#contact-result').slideUp(400, function(){
			$('#data-collection-form').slideDown(400);									  
		});									  
		return false;								  
	});	
	
	
	
	// $("#date").datepicker({showOn: 'button', buttonImage: 'images/almanaque.jpg', buttonImageOnly: true});
	// $("#treatdate").datepicker({showOn: 'button', buttonImage: 'images/almanaque.jpg', buttonImageOnly: true});
}

