/* General Setting - Dynamic Height 
        - Every div with the class fillout, will fillout
*/
jQuery.noConflict();
var browser         = jQuery.browser;
var browserVersion  = jQuery.browser.version;
var previousColumn  = "";
var ColumnCounter   = 0;
var bToggle         = false;
var toggleHeight    = 55;
var bAjaxLoad       = false;
var PreviousItem    = "";
var allTogether     = 0;
var minHeight       = 0;
var bIsSet          = false;

jQuery(document).ready(function() {     
    Custom.init();

    jQuery("a[rel^='lightbox']").prettyPhoto();
           
    jQuery(window).resize(function(){
      resizeHandler();
    });
    /* Set pretty checkboxes */
    jQuery("input[type=checkbox]").each(
        function(){
            jQuery(this).addClass("styled");
        }
    );
    jQuery("input[type=radio]").each(
        function(){
            jQuery(this).addClass("styled");
        }
    );
    /*jQuery("select").each(
        function(){
            jQuery(this).addClass("styled");
        }
    ); */
    
    
    
    jQuery('.divFoldGreen .detailHead').each(function(){
      var _this = jQuery(this);
      _this.click(function(){
        resumeFold(_this);
      });
    });
    
    if(jQuery('ul#slidepictures li').length > 0){ 
        jQuery('ul#slidepictures').css('margin-left', '0px');
        jQuery('ul#slidepictures').jcarousel();
    }
    
    if(jQuery('ul#slidevideos li').length > 0){
        jQuery('ul#slidevideos').css('margin-left', '0px');
        jQuery('ul#slidevideos').jcarousel();
    }
    
    if(jQuery('ul#slideslideshows li').length > 0){ 
        jQuery('ul#slideslideshows').css('margin-left', '0px');
        jQuery('ul#slideslideshows').jcarousel();
    }
    
    if(jQuery('.vacancy-overview').length > 0 || jQuery('.company-overview').length > 0){
        GoogleMap.HideAllMarkers();

        jQuery('a.map_marker').each(function(){
            var markerId = jQuery(this).attr('id');
            var markerId = markerId.toString().replace("map_","");
            var markerId = markerId.toString().replace("employer_","");
            GoogleMap.ShowMarker(markerId);
        });   
    }
       
    jQuery(window).trigger('resize');
    
   jQuery('.fileObject').si_files({
      button: {
        src: '/pics/btn/btn-browse.png',
        width: 70,
        height: 20
      }
    });
    
    jQuery('a.GetBlogPost').click(function(){
      return GetBlogPost(jQuery(this));
    });
    
    
    if(jQuery('a.SwitchArchive').length > 0){
      SwitchArchiveInit('a.SwitchArchive');
      jQuery('a.SwitchArchive').click(function(){
        return SwitchArchive(jQuery(this));
      });
    }
});

function centerImage(){
  if(jQuery('.company-logo').length > 0){
        var top = ( jQuery('.company-logo').height() - jQuery(".company-logo img").height() ) / 2; 
        jQuery(".company-logo img").css('margin-top', top);    
    }
}

function ToggleDiv(CheckboxElement, DivName){
    if(jQuery(DivName).css('display') == 'none') {
       jQuery(DivName).css('display','block');

    } else {
       jQuery(DivName).css('display','none');

    }
}

function ClearFile(Element){
  var ClickedElement = jQuery(Element);
  var PrevFileElement = ClickedElement.prev().find(':file');
  var ElementName = PrevFileElement.attr('name');
  var ElementClass = PrevFileElement.attr('class');
  ClickedElement.prev().remove();
  ClickedElement.parent().prepend('<input class="' + ElementClass + '" type="file" name="' + ElementName + '" style="position: relative; width: auto; opacity: 0; cursor: pointer; left: 0px; top: 0px;" />');
  jQuery('.fileObject').si_files({
      button: {
        src: '/pics/btn/btn-browse.png',
        width: 70,
        height: 20
      }
    });
}

/* Dynamic Height - See top for settings!*/
function callVacancy(element){
    if(!bAjaxLoad){
            bAjaxLoad = true;
            var _this = element;
            if(jQuery(_this).length > 0){
                var url = jQuery(_this).attr("href");
            } else {
                var url = _this;
            }
            
            jQuery("#mapsButton").removeClass("active");
            jQuery("#vacancyButton").removeClass("disabled");
            jQuery("#vacancyButton").addClass("active");
            jQuery("img.legenda").hide();
            var ContentWindow = jQuery("#contentWindow");
            ContentWindow.css({"display":"block", "z-index":"100"});            
            ContentWindow.html('<img src="http://www.vividlinks.eu/pics/loader.gif" style="margin-left: 163px; margin-top: 131px;" />');
            if(jQuery("#contentWindow").css('display') == "block"){
                if(PreviousItem != ""){
                    jQuery(PreviousItem).removeClass("active");
                }
            }
        
            jQuery("#contentWindow").load(url + "?callback=1", function(){
                    Cufon.replace('h1');    
                    Cufon.replace('h4');
                    jQuery(_this).addClass("active");
                    PreviousItem = jQuery(_this);
                    bAjaxLoad = false;
                    resizeHandler();
            });

            return false;
        } else {
            return false;
        }
}

function callEmployer(element){
    if(!bAjaxLoad){
        bAjaxLoad = true;
        var _this = element;
        if(jQuery(_this).length > 0){
            var url = jQuery(_this).attr("href");
        } else {
            var url = _this;
        }
        jQuery("#mapsButton").removeClass("active");
        jQuery("#vacancyButton").removeClass("disabled");
        jQuery("#vacancyButton").addClass("active");
        jQuery("img.legenda").hide();
        jQuery("#contentWindow").css("display","block");
        jQuery("#contentWindow").css("z-index","100");
        jQuery("#contentWindow").html('<img src="http://www.vividlinks.eu/pics/loader.gif" style="margin-left: 163px; margin-top: 131px;" />');
        
        jQuery("#contentWindow").load(url + "?callback=1", function(response){   
          Cufon.replace('h1');    
          Cufon.replace('h4');
          Cufon.replace('.detailHead');
          Cufon.replace('#content .tagcloud');       
          jQuery('.divFold .detailHead').each(function(){
            var _this = jQuery(this);
            _this.click(function(){
              companyFold(_this);
            });
          });
          
          jQuery('.companyDescription').find('.detailHead').click();
          jQuery("#contentWindow #ajaxCall div").removeClass("scroll-container");
          jQuery("#contentWindow #ajaxCall #scroller").addClass("scroll-container");

          bAjaxLoad = false;
          jQuery(window).trigger('resize');
        });   
        return false;
    } else {
        return false;
    }
}

function showMaps(){
    jQuery("#vacancyButton").removeClass("active");
    jQuery("#contentWindow").hide();
    jQuery("#contentWindow").css('z-index', '-100');
    jQuery("img.legenda").show();
    jQuery("#mapsButton").addClass("active");
    return false;
}

function showVacancy(){
    if(jQuery("#vacancyButton").hasClass("disabled")){
        return false;    
    }
    jQuery("#mapsButton").removeClass("active");
    jQuery("#contentWindow").show();
    jQuery("#contentWindow").css('z-index','10');
    jQuery("img.legenda").hide();
    jQuery("#vacancyButton").addClass("active");
    return false;
}
      
function resizeHandler(){
    var headerContainerHeight       = jQuery("#header_container").innerHeight();
    var navigationContainerHeight   = jQuery("#navigation_container").innerHeight();
    var vSpacerHeight               = jQuery(".v_spacer_100").innerHeight();
    var allTogether                 = (parseInt(vSpacerHeight) + parseInt(headerContainerHeight)) + parseInt(navigationContainerHeight);
    if(jQuery("#searchForm").length > 0){
        minHeight                   = parseInt(jQuery("#searchForm")[0].scrollHeight);
    } else {
        minHeight                   = parseInt(jQuery(".column.width_150 .text").innerHeight()) - 40; 
    }
    
    var bodyHeight          = jQuery("body").innerHeight();
    var columnHeight        = (parseInt(bodyHeight) - allTogether) - 77;
    var jqueryElementScroll = jQuery(".fillout .scroll-container"); 
    var jqueryElementText   = jQuery(".fillout .text");
    var columnHeightScroll  = columnHeight;
             
    if(browserVersion != "6.0"){         
        
        if(columnHeight < minHeight){
            jqueryElementScroll.css('min-height', '0');
            jqueryElementScroll.css('height', (minHeight + 10) + 'px');
            if(jqueryElementScroll.hasClass("medium")){
                if(jQuery('.company-overview').length > 0){
                  jQuery(".scroll-container.medium").css('height', '680px');   
                } 
                else if(jQuery('.vacancy-overview').length > 0) {
                  jQuery(".scroll-container.medium").css('height', '1029px');
                } else {
                  jQuery(".scroll-container.medium").css('height', (minHeight - 30) + 'px');  
                }
            }
            
            if(jqueryElementScroll.hasClass("medium-large")){
                jQuery(".scroll-container.medium-large").css('height', (minHeight - 30) + 'px');
            }
            if(jqueryElementScroll.hasClass("medium-large-large")){
              if(jQuery('.company-overview').length > 0){
                if(browserVersion != "7.0"){
                  jQuery(".scroll-container.medium-large-large").css('height', '640px');
                } else {
                  jQuery(".scroll-container.medium-large-large").css('height', '630px');  
                }  
              } else {  
                jQuery(".scroll-container.medium-large-large").css('height', (minHeight - 60) + 'px');
              }
            }
            jqueryElementText.css('min-height', '0');
            
            if(jQuery('.company-overview').length > 0){
              jqueryElementText.css('height',  '690px'); 
            } 
            else if(jQuery('.vacancy-overview').length > 0){
              jqueryElementText.css('height', '1048px');  
            } else {
              jqueryElementText.css('height', minHeight + 'px');
            }
            
            if(jQuery('#contentWindow').length > 0 && !jQuery('#contentWindow').hasClass('fixedHeight')){
                 
                if(minHeight > 500){                
                    jQuery('#map_search').css('height', '500px');
                } else {
                    jQuery('#map_search').css('height', (minHeight - 95) + 'px');    
                }
                if(jQuery("#contentWindow").hasClass('employer')) {
                  jQuery('#contentWindow').css('height', '686px');
                } else {
                  jQuery('#contentWindow').css('height', '1045px');
                }
                if(browserVersion != "7.0"){
                   if(jQuery("#contentWindow").hasClass('employer')) {
                    jQuery('#contentWindow .scroll-container').css('height', '687px');
                  } else {
                    jQuery('#contentWindow .scroll-container').css('height', '1000px');
                  }
                } else {
                  if(jQuery("#contentWindow").hasClass('employer')) {
                    jQuery('#contentWindow .scroll-container').css('height', '677px');
                  } else {
                    jQuery('#contentWindow .scroll-container').css('height', '990px');  
                  }
                }  
            }
        } else {
            jqueryElementScroll.css('min-height', '0');
            jqueryElementScroll.css('height', (columnHeightScroll - 5) + 'px');
            if(jqueryElementScroll.hasClass("medium")){
              if(jQuery('.company-overview').length > 0){
                  jQuery(".scroll-container.medium").css('height', '680px');   
                } 
                else if(jQuery('.vacancy-overview').length > 0) {
                  jQuery(".scroll-container.medium").css('height', '1029px');
                } else {
                  jQuery(".scroll-container.medium").css('height', (minHeight - 35) + 'px');  
                }  
            }
            if(jqueryElementScroll.hasClass("medium-large")){
                jQuery(".scroll-container.medium-large").css('height', (columnHeightScroll - 40) + 'px');
            }
            if(jqueryElementScroll.hasClass("medium-large-large")){
              if(jQuery('.company-overview').length > 0){
                if(browserVersion != "7.0"){
                  jQuery(".scroll-container.medium-large-large").css('height', '640px');
                } else {
                  jQuery(".scroll-container.medium-large-large").css('height', '630px');  
                }  
              } else {  
                jQuery(".scroll-container.medium-large-large").css('height', (columnHeight - 70) + 'px');
              }
            }
            
            if(jQuery('#contentWindow').length > 0 && !!jQuery('#contentWindow').hasClass('fixedHeight')){
                if(columnHeight - 55 > 500){
                  
                    jQuery('#map_search').css('height', '500px');    
                } else {
                    jQuery('#map_search').css('height', (columnHeight - 55) + 'px');
                }
                
                if(jQuery("#contentWindow").hasClass('employer')) {
                  jQuery('#contentWindow').css('height', '686px');
                  jQuery('#contentWindow .scroll-container').css('height', '686px');
                } else {
                  jQuery('#contentWindow').css('height', minHeight + 'px');
                  jQuery('#contentWindow .scroll-container').css('height', (minHeight - 25) + 'px');
                }
            }
            if(jQuery('.company-overview').length > 0){
              jqueryElementText.css('height',  '690px'); 
            } 
            else if(jQuery('.vacancy-overview').length > 0){
              jqueryElementText.css('height', '1048px');  
            } else {
              jqueryElementText.css('min-height', '0');
            jqueryElementText.css('height', (columnHeight - 15) + 'px');
            }
        }
        if(jqueryElementScroll.hasClass("fixedHeight")){
            jQuery(".scroll-container.fixedHeight").css('height', '278px');
        }
        
        jQuery('.scroll-container').jScrollPane({scrollbarWidth: 10});
        if(jQuery("#map_search").length > 0){
            GoogleMap.FitMapToMarkers();
        }
        return
    } else {
        jQuery('.scroll-container').jScrollPane({scrollbarWidth: 10});
        return
    }  
 
}

function searchCallbackCompanies(){
    var str = jQuery("#searchForm").serialize();
    if(jQuery("#contentWindow").css('display') == "none"){
      jQuery("#contentWindow").css('z-index','-100');
      jQuery("#contentWindow").css('display','block');
    }
    jQuery('.inside-column198:eq(1) .scroll-container').html('<img style="margin-left: 71px;" src="http://www.vividlinks.eu/pics/loader.gif" />');
    jQuery('.inside-column198:eq(1)').load(jQuery("#searchForm").attr("action"), str,function(){  
      jQuery("#contentWindow").css('z-index','10');

        jQuery(window).trigger('resize'); 
        Cufon.replace('h1');
        jQuery("#vacancyButton").addClass("disabled");
        showMaps();
        GoogleMap.HideAllMarkers();

        jQuery('a.map_marker').each(function(){
            var markerId = jQuery(this).attr('id');
            var markerId = markerId.toString().replace("employer_","");
            GoogleMap.ShowMarker(markerId);
        });
    });    
    return false;
}

function searchCallbackVacancies(){
    var str = jQuery("#searchForm").serialize();
    jQuery('.inside-column198:eq(1) .scroll-container').html('<img style="margin-left: 71px;" src="http://www.vividlinks.eu/pics/loader.gif" />');
    jQuery('.inside-column198:eq(1)').load(jQuery("#searchForm").attr("action") + ' .inside-column198:eq(1)', str,function(){         
        jQuery(window).trigger('resize'); 
        Cufon.replace('h1');
        jQuery("#vacancyButton").addClass("disabled");
        showMaps();
        GoogleMap.HideAllMarkers();

        jQuery('a.map_marker').each(function(){
            var markerId = jQuery(this).attr('id');
            var markerId = markerId.toString().replace("map_","");
            GoogleMap.ShowMarker(markerId);
        });
        
    });  
    return false;
}

function resetSearch(vacancySearch){
    if(vacancySearch){
        divElement = " .inside-column198:eq(1)";
    } else {
        divElement = "";
    }
    jQuery("#searchForm input:text").attr('value','');
    jQuery("#searchForm input:checkbox").attr('checked','checked');
    jQuery("#searchForm input").removeAttr('selected');

    jQuery('.inside-column198:eq(1) .scroll-container').html('<img style="margin-left: 71px;" src="http://www.vividlinks.eu/pics/loader.gif" />');
    
    
    GoogleMap.ShowAllMarkers();
    jQuery('.inside-column198:eq(1)').load(jQuery("#searchForm").attr("action") + divElement,'reset=1&stripped=1',function(){        
        jQuery(window).trigger('resize'); 
        Cufon.replace('h1');
        jQuery("#vacancyButton").addClass("disabled");
        showMaps();
        GoogleMap.HideAllMarkers();

        jQuery('a.map_marker').each(function(){
            var markerId = jQuery(this).attr('id');
            var markerId = markerId.toString().replace("map_","");
            var markerId = markerId.toString().replace("employer_","");
            GoogleMap.ShowMarker(markerId);
        }); 
    });
    Custom.clear();   
    return false;
}

function windowHide(){
    if(jQuery("#contentWindow").css('right') == "0px"){
        jQuery("#contentWindow").animate({
            right: "-300px"
        },1500);
        return false;
    }
    return false;    
}

function toggleWidget(element, portal) {    
   var jqueryElement = jQuery(element).parent().parent();
   var backgroundUrl = jqueryElement.find('.widget_w .widget_content').css('background-image');
             
   if(jqueryElement.find('.widget_w .widget_content').css('height') == toggleHeight + "px"){
        if(backgroundUrl != "none"){
            jqueryElement.find('.widget_w .widget_content').css('background','#ffffff none');
            jqueryElement.find('.widget_sw').css('background','url(pics/bottom.png) top left no-repeat');
        }
        jqueryElement.find('.widget_w .widget_content').animate({height: jqueryElement.find('.widget_w .widget_content')[0].scrollHeight + "px"},function(){
            if(backgroundUrl != "none"){
                jQuery(this).css('background','#ffffff url(pics/home-bg.gif) bottom left repeat-x'); 
                jqueryElement.find('.widget_sw').css('background','url(pics/bottom-green.png) top left no-repeat');
            }
        });
        jQuery(element).removeClass("toggle-widget-active");
        jQuery(element).addClass("toggle-widget");
   } else {
        var height = jqueryElement.find('.widget_w .widget_content').innerHeight();
        if(height > toggleHeight){
            if(backgroundUrl != "none"){
                jqueryElement.find('.widget_sw').css('background','url(pics/bottom.png) top left no-repeat');
                jqueryElement.find('.widget_w .widget_content').css('background','#ffffff none');
            }
            jqueryElement.find('.widget_w .widget_content').animate({height: toggleHeight + "px"},function(){
                if(backgroundUrl != "none"){
                    jQuery(this).css('background','#ffffff url(pics/home-bg.gif) 0px 5px repeat-x');
                    jqueryElement.find('.widget_sw').css('background','url(pics/bottom-green.png) top left no-repeat');
                }
                
            });
            jQuery(element).removeClass("toggle-widget");
            jQuery(element).addClass("toggle-widget-active");
        }
   }
   setTimeout(function(){bToggle = true; onUpdate(portal);}, 500);
 }
 
function onUpdate(portal, widget) {
    var totalItems      = 0;
    var PlaceCounter    = 0;
    var previousColumn  = -1;
    var itemFolded      = 0;
    
    if(!bToggle){
        jQuery(".widget").each(function(){
            if (totalItems % 2 == 0){
                if(jQuery(this).find('.widget_content').css('height') == toggleHeight + 'px'){
                    jQuery(this).find('.widget_content').css('background','#ffffff url(pics/home-bg.gif) 0px 5px repeat-x');
                    jQuery(this).find('.widget_sw').css('background','url(pics/bottom-green.png) top left no-repeat');
                } else {
                    jQuery(this).find('.widget_content').css('background','#ffffff url(pics/home-bg.gif) bottom left repeat-x');
                    jQuery(this).find('.widget_sw').css('background','url(pics/bottom-green.png) top left no-repeat');    
                }
            } else {
                jQuery(this).find('.widget_content').css('background','#ffffff none');
                jQuery(this).find('.widget_sw').css('background','url(pics/bottom.png) top left no-repeat'); 
            }
            totalItems++;
        });
    } 

    var aSplittedValues = portal.serializeAdd().split(",");
    aSplittedValues.pop();
    for( var i = 0; i < aSplittedValues.length; i++){
        
        var aFinalValues = aSplittedValues[i].split("-");
        if(aFinalValues[0].slice(-1) == previousColumn){
            PlaceCounter++;
        } else {
            PlaceCounter = 0;
        }
        if(jQuery("#" + aFinalValues[1]).find('.widget_content').css("height") == "55px"){
            itemFolded = 1;
        } else {
            itemFolded = 0;    
        }
        setCookie(aFinalValues[1], aFinalValues[0].slice(-1) + "-" + PlaceCounter + "-" + aFinalValues[1].slice(-1) + "-" + itemFolded, 365)
        
        previousColumn = aFinalValues[0].slice(-1);
    }
    bToggle = false;   
}

 function clearTxt(element)
{
    if (element.value == "..."){
        element.value = "";
    }
}
function checkTxt(element)
{
    if (element.value == ""){
        element.value = "...";
    }
}

function toggleSearch(){
    if(jQuery('#advancedSearch').css('height') == "0px"){
        jQuery('#advancedSearch').animate({height: "112px"}, "slow");
        return false;
    } else {
        jQuery('#advancedSearch').animate({height: "0px"}, "slow");
        return false;    
    }
}

function companyFold(DivElement){
  var ParentDiv   = DivElement.parent();
  var SpanElement = DivElement.find('span');

  ParentDiv.css('overflow', 'hidden');
  if(ParentDiv.css('height') != '10px'){
    ParentDiv.animate({'height':'10px'}, function(){
      jQuery('.scroll-container').jScrollPaneRemove(); 
      jQuery('.scroll-container').jScrollPane({scrollbarWidth: 10});
    });
    SpanElement.css('background','url(pics/bg_div_fold_arrowDown.gif) top left no-repeat');
  } else {
    ParentDiv.animate({'height': ParentDiv[0].scrollHeight + 'px'}, function(){
      jQuery('.scroll-container').jScrollPaneRemove();
      jQuery('.scroll-container').jScrollPane({scrollbarWidth: 10});
    });
    SpanElement.css('background','url(pics/bg_div_fold_arrowUp.gif) top left no-repeat');
  }
  
}

function resumeFold(DivElement){
  var ParentDiv   = DivElement.parent();
  var SpanElement = DivElement.find('span');
  var bAllreadyFolding    = false;
  
  ParentDiv.css('overflow', 'hidden');
  if(!bAllreadyFolding){
    bAllreadyFolding = true;
    if(ParentDiv.css('height') != '25px'){
      ParentDiv.animate({'height':'25px'});
      SpanElement.css('background','url(/pics/arrow-down.gif) top left no-repeat');
      jQuery('a.resumeStep').each(function(){
        if(jQuery(this).attr('rel') == jQuery('a',DivElement).attr('name')) {
          jQuery(this).removeClass('active');
        }
      }); 
    } else {
      ParentDiv.animate({'height': ParentDiv[0].scrollHeight + 'px'});
      SpanElement.css('background','url(/pics/arrow-up.gif) top left no-repeat');
      jQuery('a.resumeStep').each(function(){
        if(jQuery(this).attr('rel') == jQuery('a',DivElement).attr('name')) {
          jQuery(this).addClass('active');
        }
      });
    }
  }
  
  /*else {
    jQuery('.divFoldGreen').each(function(){
      if(jQuery(this).css('height') != '25px'){
        jQuery(this).animate({'height':'25px'},function(){
          jQuery(this).find('.foldArrow').css('background','url(/pics/arrow-down.gif) top left no-repeat');
          ParentDiv.animate({'height': ParentDiv[0].scrollHeight + 'px'});
          SpanElement.css('background','url(/pics/arrow-up.gif) top left no-repeat');
        });
        bAllreadyFolding = true;
      }
    });*/
}

function CheckResumeDiv(){
  Hash = window.location.hash;
  Hash = Hash.replace("#","");

  jQuery('a.foldDiv').each (function(){
    if(jQuery(this).attr('name') == Hash){
      resumeFold(jQuery(this).parent());  
    }
  });
}

function GetBlogPost(ClickedElement){
  if(!bAjaxLoad){
    var url = ClickedElement.attr('href');
    jQuery(".blog-column.big").html('<img src="http://www.vividlinks.eu/pics/loader.gif" />');
    jQuery(".blog-column.big").load(url + " #blog-info", function(){
                      jQuery('#blog-info').css('text-align','left');
                      jQuery('#ListOptions').css('display','block');
                      Cufon.replace('h1');
                      Cufon.replace('h5');
                      Cufon.replace('.tagcloud a');
                      Cufon.replace('a.edit');
                      ClickedElement.addClass("active");
                      bAjaxLoad = false;
                      resizeHandler();
              });
  } 
  return false;
   
}
var bAnimation = false;

function SwitchArchiveInit(ElementClass){
  jQuery(ElementClass).each(function(){
    if(jQuery(this).hasClass('closed')){
      jQuery(this).next('ul').css('display','none');
    }
  });
}

function SwitchArchive(ClickedElement){
  if(bAnimation){
    return false;
  }
  bAnimation = true;
   
  ClickedElement.next('ul').slideToggle("slow",function(){
    if(ClickedElement.hasClass('opened')){
      ClickedElement.removeClass('opened');
      ClickedElement.addClass('closed');
    } else {
      ClickedElement.removeClass('closed');
      ClickedElement.addClass('opened');
    }  
    bAnimation = false;
  });
   
  return false;  
}