/*
 * montelmedia.com main.js file
 * Created 16 March 2009
 * Sitewide javascript functions
 *
 * Developed by Vector Media Group, http://www.vectormediagroup.com
 */

$("html").addClass("js");
$("<img>").attr("src", "/images/logo_hover.png");
$(document).ready(function() {
	navResize();
	$(".print").click(function() {
		window.print();
		return false;
	});
	$(".products .lightbox").each(function () {
		$(this).lightBox();
	});
	$(".gallery .lightbox").lightBox();
	if ($("form#freeform").length > 0) {
		$("form#freeform").validate();
	};
	if ($("form#subscription").length > 0) {
		$("form#subscription").validate({
			rules: {
				'cm-fo-yklyhi': {
					required: true
				}
			},
			errorPlacement: function(error, element) {
				if (element.attr('name') == "cm-fo-yklyhi") {
					error.appendTo(element.parent().parent().find("span"));
				}
				else {
					error.appendTo(element.parent(".field"));
				};
			},
			messages: {
				"cm-fo-yklyhi": "You must choose at least one area of interest"
			}
		});
		$("#cm64458").click(function() {
			var is_checked = this.checked;
			$("#interests_select input").each(function() {
				this.checked = is_checked;
			});
		});
	};
	if ($("form[name='reel_login']").length > 0) {
		$("form[name='reel_login']").validate();
	};
	if ($(".thumbnail a.lightbox img").length > 0) {
		$(".thumbnail a.lightbox").hover(function() {
				$(this).find(".plus_icon").css('display', 'inline');
			}, function() {
				$(this).find(".plus_icon").css('display', 'none');
			});
	};
	if (!($.browser.msie && parseInt($.browser.version) < 7)) {
		$(".products .description .external a").attr('target', '_blank');
	};
	$("#credits").prepend('<span><a href="#">x</a></span>');
	$("#credits span a").click(function() {
		$("#credit_link").click();
		return false;
	});
	$("#credit_link").click(function() {
		if ($("#credits_outer").css('display') == "none") {
			$("#credits_outer").fadeIn("medium");
		}
		else {
			$("#credits_outer").fadeOut("medium");			
		};
		return false;
	});
});


function navResize()
{
	var _nav = document.getElementById('navigation');
	var _sec = _nav.getElementsByTagName('div');
	var _section = [];
	for(var i=0;i<_sec.length;i++)
	{
		if(_sec[i].className.indexOf("section") != -1)
		_section.push(_sec[i]);
	}
	for(var j=0;j<_section.length;j++)
	{
		var _max = _section[j].offsetWidth;
		var _el = _section[j].getElementsByTagName('a');
		for(var m=0;m<_el.length;m++)
			_el[m].style.width = _max -31 + 'px';
	}
}
