$j(window).load(function() {
	
	// init nivo slider
	initNivo();
	
	// init carousel
	$j('#carousel_imageArea').carousel('#carousel_arrowLeft', '#carousel_arrowRight');
	
	// last menu item fix for ie
	$j("nav#mainMenu a:last-child").css( {"border-bottom": "0"} );

});

function initNivo() {

	$j('#slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500, //Slide transition speed
		pauseTime:6000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:true, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:true, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){}, //Triggers after all slides have been shown
		lastSlide: function(){}, //Triggers when last slide is shown
		afterLoad: function(){} //Triggers when slider has loaded
	});

}

function checkform() {
	
	var required = new Array(
		"nimi",
		"puhelin",
		"spamcheck"
	);
	var errors = 0;
	
	required.each(function(elem) {
		
		if($j("#" + elem).val() == "") {
			$j("#" + elem).addClass("error");
			errors++;
		}
		else if(elem == "spamcheck" && $j("#" + elem).val() != "viisi") {
			$j("#" + elem).addClass("error");
			errors++;
		}
		else {
			$j("#" + elem).removeClass("error");
			errors = errors > 0 ? errors-- : 0;
		}

	});

	if(errors > 0) {
		$j("#fillall").show();
	}
	else {
		$j("#fillall").hide();
		$j("#formOfferRequest").submit();
	}
}


function googleAnalytics() {
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-20722497-1']);
	_gaq.push(['_trackPageview']);
	
	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();	
}

