/*******************************************************************************

	CSS on Sails Framework
	Title: Mobile Monitor Technologies
	Author: XHTMLized (http://www.xhtmlized.com/)
	Date: January 2012

*******************************************************************************/

$(document).ready(function() {
	function filterPath(string) {
		return string
		.replace(/^\//,'')
		.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
		.replace(/\/$/,'');
	}
	var locationPath = filterPath(location.pathname);
	var scrollElem = scrollableElement('html', 'body');
	
	$('a[href*=#]').bind('click', function(e) {
        e.preventDefault(); //prevent the "normal" behaviour which would be a "hard" jump

        var target = $(this).attr("href"); //Get the target

        // perform animated scrolling by getting top-position of target-element and set it as scroll target
        $('html, body').stop().animate({ scrollTop: $(target).offset().top }, 2000, function() {
             location.hash = target;  //attach the hash (#jumptarget) to the pageurl
        });

        return false;
   });	
	// use the first element that is "scrollable"
	function scrollableElement(els) {
		for (var i = 0, argLength = arguments.length; i <argLength; i++) {
			var el = arguments[i],
			$scrollElement = $(el);
			if ($scrollElement.scrollTop()> 0) {
				return el;
			} else {
				$scrollElement.scrollTop(1);
				var isScrollable = $scrollElement.scrollTop()> 0;
				$scrollElement.scrollTop(0);
				if (isScrollable) {
					return el;
				}
			}
		}
		return [];
	}
	
	$("#name").placeHolder({
		"text": "Full Name"
	});
	$("#phone").placeHolder({
		"text": "Phone Number"
	});
	$("#email").placeHolder({
		"text": "Email Address"
	});
	
	$('.slideshow').cycle({
		fx: 'scrollLeft', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 6000,
		cleartypeNoBg: true,
		cleartype: true,
		speed: 500
	});
	
	
	$(window).bind("load", function() {
		$("#gallery").slideViewerPro({
			thumbs: 7,
			autoslide: true,
			asTimer: 3500,
			typo: false,
			galBorderWidth: 0,
			thumbsBorderOpacity: 0.5,
			buttonsTextColor: "#858585",
			buttonsWidth: 40,
			thumbsActiveBorderOpacity: 0.8,
			thumbsActiveBorderColor: "#858585",
			thumbsRightMargin:5,
			thumbsPercentReduction: 7,
			shuffle: false
		});
	});
	
	$("h2, h3, p, li, ul, ol").ieffembedfix();
});


