// JavaScript Document
var html,first,myid;
var liwidth = 0;
var ulwidth = 0;
var lioffset = 40;
function array_pop (inputArr) {
    var key = '', lastKey = '';
     if (inputArr.hasOwnProperty('length')) {
        if (!inputArr.length){
            return null;        }
        return inputArr.pop();
    } else {
        for (key in inputArr) {            if (inputArr.hasOwnProperty(key)) {
                lastKey = key;
            }
        }
        if (lastKey) {            var tmp = inputArr[lastKey];
            delete(inputArr[lastKey]);
            return tmp;
        } else {
            return null;        }
    }
}
function number_format(number, decimals, dec_point, thousands_sep) {
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }    return s.join(dec);
}
function array_shift (inputArr) {
	var props = false,
        shift = undefined, pr = '', allDigits = /^\d$/, int_ct=-1,
        _checkToUpIndices = function (arr, ct, key) {
            // Deal with situation, e.g., if encounter index 4 and try to set it to 0, but 0 exists later in loop (need to
            // increment all subsequent (skipping current key, since we need its value below) until find unused)            
			if (arr[ct] !== undefined) {
                var tmp = ct;
                ct += 1;
                if (ct === key) {
                    ct += 1;                }
                ct = _checkToUpIndices(arr, ct, key);
                arr[ct] = arr[tmp];
                delete arr[tmp];
            }            return ct;
        };
    if (inputArr.length === 0) {        return null;
    }
    if (inputArr.length > 0) {
        return inputArr.shift();
    } 
}

$(document).ready(function(){
	$("form").validationEngine();
	var apath = location.pathname;
	if (apath!='' && apath!='#') {
		$("a[href="+apath+"]").parent("li").addClass("active");
	}
	$("ul.drop-down").each(function(){
		liwidth = $(this).parent().width();
		ulwidth = $(this).width();
		if (liwidth > ulwidth) {
			$(this).css("width",liwidth+lioffset+"px");
		}
	});
	$(".top-level-li").each(function(){
		myid = $(this).attr("id");
		if (myid!='/' && myid!='#' && myid!='') {
			if ($("#"+myid+" li.active").length) {
				$(this).addClass("active");
			}
		}
	});
	/*
	$(".top-level-a b").each(function(){
		html = $(this).html().split(' ');
		first = array_shift(html);
		$(this).parent().html(first+'<br /> <b>'+html.join(' ')+'</b>');
	});
	
	$("ul.tmfooter li").each(function(){
		html = $(this).children("a").html().split(' ');
		first = array_shift(html);
		$(this).children("a").html(first+' <strong>'+html.join(' ')+'</strong>');
	});
	*/
	
	if ($('.slider').length){
		$('.slider').nivoSlider({
			effect:'fade',
			slices:1,
			animSpeed:500,
			pauseTime:5000,
			startSlide:0, //Set starting Slide (0 index)
			directionNav:false, //Next & Prev
			directionNavHide:false, //Only show on hover  
			controlNav:true, //1,2,3...
			controlNavThumbs:false, //Use thumbnails for Control Nav
			controlNavThumbsSearch: '.jpg', //Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			keyboardNav:false, //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
		});
	}
	
	if ($("a[rel^=prettyPhoto]").length) {
		$("a[rel^=prettyPhoto]").prettyPhoto();
	}
});
