﻿function toggleDivs(whatDiv, whatTitleOpen, whatTitleClosed) {
  var curStatus = jQuery("#" + whatDiv + " .moreContent").css('display') == 'none';

    if (whatDiv.match("accordeonSpot"))
       hideAccordeonSpot();

    if (curStatus == true) {
      
       jQuery("#" + whatDiv + " .more").attr("title", whatTitleClosed);


      if (jQuery("#" + whatDiv + " .more").html == "+") {
        jQuery("#" + whatDiv + " .more").html("-");
        }

        jQuery("#" + whatDiv + " .more").addClass('less');
        jQuery("#" + whatDiv + " .more").removeClass('more');
        jQuery("#" + whatDiv + " .moreContent").slideDown("fast");
        jQuery("#" + whatDiv + " .moreContent").slideDown("fast");
        if (jQuery("#" + whatDiv + " .moreContent").style != null)
          jQuery("#" + whatDiv + " .moreContent").style.height = '';
    }
    else {

      if (whatDiv.match("accordeonSpot"))
        jQuery("#" + whatDiv + " .more").attr("title", whatTitleOpen);
      else
        jQuery("#" + whatDiv + " .less").attr("title", whatTitleOpen);
      jQuery("#" + whatDiv + " .less").addClass('more');
      if (jQuery("#" + whatDiv + " .less").html == "-") {
        jQuery("#" + whatDiv + " .less").html("+");
        }

        jQuery("#" + whatDiv + " .less").removeClass('less');
        jQuery("#" + whatDiv + " .moreContent").slideUp("fast");
    }
}



function hideAccordeonSpot() {
  jQuery(".accordeonSpot .less").addClass('more');
  jQuery(".accordeonSpot .less").removeClass('less');
  jQuery(".accordeonSpot .moreContent").slideUp("fast");
}

function makeLessToMore() {

  if (jQuery(".less").html == "-") {
    jQuery(".less").html("+");
    }
    jQuery(".less").addClass('more');
    jQuery(".less").removeClass('less');

}


function initAccordeon() {
    jQuery(".accordioncontent").accordion({ active: 'none', collapsible: true });
/*
    jQuery(".accordioncontent").accordion({ active: 'none', collapsible: true, change: function(event, ui) {

    //alert(jQuery(this).siblings(".accordioncontent").children(".ui-state-active").length);
    jQuery(this).siblings(".accordioncontent").children(".ui-state-active").addClass("ui-state-default");
        jQuery(this).siblings(".accordioncontent").children().removeClass('ui-state-active');
    //Query(this).siblings(".accordioncontent").children('.ui-accordion-content-active').addClass('ui-accordion-content-default');
    jQuery(this).siblings(".accordioncontent").children(".ui-accordion-content-active").slideUp("fast");
    //jQuery(this).siblings(".accordioncontent").children().removeClass('ui-accordion-content-active');
    

    } 
    });*/
    
    var acc = jQuery(".moreContent");
    jQuery(acc).css("display", "none");

    var id = getQuerystring("id", null);
    if (id != null) {
      toggleDivs("_" + id);
    }
    /*
    jQuery(acc).each(function() {
    var height = jQuery(this).height();
    jQuery(this).css("height", height);
    alert(height);
    }
    )
    */

}

function getQuerystring(key, default_) {
  if (default_ == null) default_ = "";
  key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if (qs == null)
    return default_;
  else
    return qs[1];
}