// Function to Expand FAQ Divs - AT 4-19-2011
$(document).ready(function()
{
  //hide the all of the element with class faq_body
  $(".faq_body").hide();
  //toggle the componenet with class faq_body
  $(".faq_header").click(function()
  {
    $(this).next(".faq_body").slideToggle(300);
  });
});


// Function to Expand Comment Div - AT 5-09-2011
$(document).ready(function()
{
  //hide the all of the element with class faq_body
  $(".comment_form").hide();
  //toggle the componenet with class faq_body
  $(".comment_right").click(function()
  {
    $(this).next(".comment_form").slideToggle(300);
  });
});

function validate() {
    $("form").length && $("form").submit(function(a) {
        $(".Required").each(function() {
            $(this).is(":hidden") == 0 && ($(this).val() == "" || $(this).val() == null || $(this).attr("selectedIndex") == "" ? (a.preventDefault(), $(this).addClass("valError")) : $(this).removeClass("valError"))
        })
    })
}

// COMMENTS FUNCTION
function BxLinks(ndx) {
  var tmp = ''
  for (var i=0; i<3; i++) {
    tmp = 'div'+(i+1);
    document.getElementById(tmp).style.display = 'none';
  }
  tmp = 'div'+ndx;
  var w = document.getElementById(tmp);
  if (w.style.display == "none") { w.style.display = "block"; }
  return false;
}
function InitBxLinks() {
  document.getElementById('div1').style.display = 'block';
}

// SHOW/HIDE DIV FOR COLUMNS FILTER
function colLinks(ndx) {
  var tmp = ''
  for (var i=0; i<7; i++) {
    tmp = 'dmc_Column'+(i+1);
    document.getElementById(tmp).style.display = 'none';
  }
  tmp = 'dmc_Column'+ndx;
  var w = document.getElementById(tmp);
  if (w.style.display == "none") { w.style.display = "block"; }
  return false;
}

$(window).load(function(){
    $('.crop').each(function(index) {
        var ratio = ($(this).width()) / ($(this).height());
        var trueratio = ($(this).parent().parent().width()) / ($(this).parent().parent().height());
        if (ratio < trueratio) {
            var width = $(this).parent().parent().width();
            $(this).width(width);
            var parent_height = $(this).parent().parent().height();
            var image_height = $(this).height();
            var top_margin = (parent_height - image_height) / 2;
            //and change the margin-top css attribute of the image
            $(this).css('margin-top', top_margin);
        } else if (ratio > trueratio) {
            var height = $(this).parent().parent().height();
            $(this).height(height);
            var parent_width = $(this).parent().parent().width();
            var image_width = $(this).width();
            var left_margin = (parent_width - image_width) / 2;
            //and change the margin-top css attribute of the image
            $(this).css('margin-left', left_margin);
        } else {
            var height = $(this).parent().parent().height();
            var width = $(this).parent().parent().width();
            $(this).width(width);
            $(this).height(height);
        }
    });
});
