jQuery(document).ready(function(){
	tfuse_form(); //controls the contact form locatet in frameork/functons/sendmail.js
});


// Slideshow of the Home Page Section
$(function () {

    $insert_nav = $('.contentLeft');

    //Insert Nav into the DOM
    $('<ul id="board_nav"><li id="previous" title="previous">previous</li><li id="next" title="next">next</li></ul>').insertBefore($insert_nav);

    $elements = $('.contentLeft .home_page_image');
    $elementsSize = $($elements).length;

    // Setting the intervals for animation
    $n=0;
    $interval = 5000;
    $hideInterval = 100;
    $showInterval = 1000;
    $stop_loooping = false;

    loop_cicle();
 
    function loop_cicle(){

      if ($stop_loooping == true){

      }else{

        if(($n == $elementsSize) || ($n > $elementsSize)){
          $n = 0;
        };
  
        $($elements).fadeOut($hideInterval);
        $($elements[$n] ).fadeIn($showInterval);
        $n++;
  
        setTimeout(loop_cicle,$interval);

      }              
    }


    // Next button
    $('#next').live('click', function (){
        
    $stop_loooping = true;
    
    if(($n == $elementsSize) || ($n > $elementsSize)){
      $n = 0;
    }
    
    $($elements).hide();
    $($elements[$n]).show();
    
    $n++;

    $stop_loooping = false;

    });

    // Prev button
    $('#previous').live('click', function (){

      $stop_loooping = true;
      
      if($n == -1) {
        $n = $elementsSize -1;
      }
      
      if(($n == $elementsSize) || ($n > $elementsSize)){
        $n = 0;
      }
      
      $($elements).hide();
      $($elements[$n]).show();
      
      $n++;

      $stop_loooping = false;

    });

});



// Cut Submenu
$(function () {


  $('.menu a').click(function () {
    // Hide the overflow
    $('.contentTextSlide').css({"overflow" : "hidden"});
    $('#cut_submenu a').removeClass("active");
    $('#cut_submenu').fadeOut(500);
    $('#cut_subpages .servicesText').hide();
    $('#experience_subpages').show();
  });


  $('.menuservices a').click(function() {

    // Hide the overflow
    $('.contentTextSlide').css({"overflow" : "hidden"});

    //Show the submenu if the "The Cut and Style" is selected
    if($(this).attr("id") == 'page_16'){
      
      //If the submenu is shown hide it and show the default image
      if($('#cut_submenu').css("display") == 'block'){
        $('#cut_submenu').fadeOut(500);
        $('#experience_subpages').show();
        $('#cut_subpages .servicesText').hide();
      }else{
        $('#cut_submenu').fadeIn(500);
      }
      
    }else{
      $('#cut_submenu').fadeOut(500);
      $('#experience_subpages').show();
      $('#cut_subpages .servicesText').hide();
    }

  });
})

// Cut Subpages
$(function () {
  $('#cut_submenu a').click(function (){

    $('#cut_submenu a').removeClass("active");

    // Switch the overflow
    $('.contentTextSlide').css({"overflow" : "auto"});

    $(this).addClass("active");
    $('#experience_subpages').hide();

    var current_link_id = $(this).attr("id");
        section_id = current_link_id.replace("page_", "page_id_");   
        section_to_show_id = '#' + section_id;

    $('#cut_subpages .servicesText').hide();
    $(section_to_show_id).show();
    return false;
  });
   return false;
});

