
$(document).ready(function() {
	$("#datepicker").datepicker();

	var IE6 = (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 6);
	if(IE6) {
		/// PNGs
		$("img[src$='.png']").each(function() {
			var src = $(this).attr('src');
			$(this).attr("src", "http://www.dynamit.us/img/spacer.gif").attr("style", "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "');");
		});
	}


	/** Setup dropdowns **/
	var to;
	$('a.openup').mouseover(function() {
		clearTimeout(to);
		$('ul.opened').hide();

		var id = $(this).attr('id');
		$('#subnav-' + id).show();
	}).mouseout(function() {
		var id = $(this).attr('id');
		to = setTimeout(function() {
			closeme($('#subnav-' + id));
		}, 2000);
	});

	$('ul.opened').mouseover(function() {
		clearTimeout(to);
	}).mouseout(function() {
		var id = $(this).attr('id');
		to = setTimeout(function() {
			closeme($('#' + id));
		}, 1000);
	});

	function closeme(o) {
		o.hide();
	}


	/** link list hovers **/
	$('ul.subnav>li').hover(function() {	//mouseover
		$(this).addClass('on');
	}, function() {				//mouseout
		$(this).removeClass('on');
	});

	/** video player navigation **/

    $("#scroll-panel #left").bind("click", function(e){
	  moveLeft();
    });

    $("#scroll-panel #right").bind("click", function(e){
      moveRight();
    });

});


var leftPos = 0;
var pos = 0;

function moveRight() {
	var newLeft = leftPos - 87;
	leftPos = newLeft;
	$("#thumbs-move").animate({ 
		marginLeft: newLeft + "px"
	}, 750);

	pos++;

	toggleArrows();
}

function moveLeft() {
	var newLeft = leftPos + 87;
	leftPos = newLeft;
	$("#thumbs-move").animate({ 
		marginLeft: newLeft + "px"
	}, 750);

	pos--;

	toggleArrows();
}

function toggleArrows() {
	if(pos + 4 > numPictures) {
		$("#scroll-panel #right").css("visibility", "hidden");
		$("#scroll-panel #left").css("visibility", "visible");
	} else {
		$("#scroll-panel #right").css("visibility", "visible");
	}

	if(pos > 0) {
		$("#scroll-panel #left").css("visibility", "visible");
	} else {
		$("#scroll-panel #left").css("visibility", "hidden");
	}
}


function playMovie(url) {
	dynamItLoad('/plugin/media/media.php?url=files/home_page/videos/'+url, 'flash-player', '427', '317', ' ');
}

function number_format( number, decimals, dec_point, thousands_sep ) {

 
    var n = number, prec = decimals;
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep == "undefined") ? ',' : thousands_sep;
    var dec = (typeof dec_point == "undefined") ? '.' : dec_point;
 
    var s = (prec > 0) ? n.toFixed(prec) : Math.round(n).toFixed(prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
 
    var abs = Math.abs(n).toFixed(prec);
    var _, i;
 
    if (abs >= 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;
 
        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
 
        s = _.join(dec);
    } else {
        s = s.replace('.', dec);
    }
 
    return s;
}
