$(function(){
  Cufon.replace('h1.white_big_header', { fontFamily: 'a_Assuan' });
  $("img.vis").hover(
      function () {
        $("img.hidden").hide();
        $("img.vis").show();
        var ident = $(this).attr('ident');
        if($("#"+ident).is(':hidden'))
        {
          $(this).prev().show();
          $(this).hide();
        }
      },
      function () {
        return true;
      }
  );

  $("img.hidden, #menu").hover(
      function () {
        return true;
      },
      function () {
        $("img.hidden").hide();
        $("img.vis").show();
      }
    );

  $("a.color1").hover(
      function () {
        $(this).parent().parent().parent().addClass('active_case');
        $(this).parent().prev().addClass('active_case_head');
      },
      function () {
        $(this).parent().parent().parent().removeClass('active_case');
        $(this).parent().prev().removeClass('active_case_head');
      }
    );
	

/*
  $(".carousel").jCarouselLite({
      btnNext: ".next",
      btnPrev: ".prev",
      speed: 1000,
      circular: false

  });

  $(".carousel_news").jCarouselLite({
      btnNext: ".next_news",
      btnPrev: ".prev_news",
      speed: 1000,
      visible:4,
      circular: false

  });
*/
  $("a.portfolio,img.opacity").live('click',
    function(e){
      $("#portfolio_preview img").removeClass('opacity');
      $("#portfolio_preview img").addClass('opacity1');
      $("#portfolio_preview a").removeClass('portfolio');
      $("#portfolio_preview a").addClass('portfolio_passive');
      $("div.prev_first, div.next_first").remove();
      $("div.prev, div.next").show();
      return false;
  });

  $("a.portfolio_passive").live('click',
    function(e){
      return false;
  });

  $("#portfolio_preview img").hover(
      function () {
        if(!$(this).hasClass('opacity'))
        {
          $(this).removeClass('opacity1');
        }
      },
      function () {
        if(!$(this).hasClass('opacity'))
        {
          $(this).addClass('opacity1');
        }
      }
  );

  $("div.next_news").hover(
      function () {
        $(this).trigger('click');
      }
    );

  $("div.prev_news").hover(
      function () {
        $(this).trigger('click');
      }
    );

  //select all the a tag with name equal to modal
  $('a[name=modal]').click(function(e) {
    //Cancel the link behavior
    e.preventDefault();

    //Get the A tag
    var filename = $(this).attr('filename');
    $("#loop_img").append('<img src="/uploads/assets/' + filename + '" id="big_img" />');
    var id = $(this).attr('href');

    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});

    //transition effect
    $('#mask').fadeIn(1000);
    $('#mask').fadeTo("slow",0.8);

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center
    $(id).css('top',  winH/2-$(id).height()/2);
    $(id).css('left', winW/2-$(id).width()/2);

    //transition effect
    $(id).fadeIn(2000);

  });

  //if close button is clicked
  $('.window .close').click(function (e) {
    //Cancel the link behavior
    e.preventDefault();
    $("#big_img").remove();
    $('#mask').hide();
    $('.window').hide();
  });

  //if mask is clicked
  $('#mask').click(function () {
    $("#big_img").remove();
    $(this).hide();
    $('.window').hide();
  });

  $("img.portfolio_thumb_img").hover(
      function () {
        $("div.left_modal, div.right_modal").hide();
        $(this).prev().animate({opacity: "show"}, "slow");
      },
      function () {
        return true;
      }
    );

  $("div.left_modal, div.right_modal").hover(
      function () {
        return true;
      },
      function () {
        $(this).hide();
      }
    );

  $('textarea.blabla').live('click',function () {
    $(this).removeClass('blabla');
    $(this).empty();
  });
  
  $('#frontend_text table tr td:odd').addClass('td_horizontal_padding');
  $('#frontend_text table tr td:first').addClass('td_first_padding');
  
  $('h1.white_big_header').live('click',function () {
    if(!$(this).hasClass('current_service'))
    {
      $('h1.white_big_header').removeClass('current_service');
      $("div.service_article").slideUp();
      $(this).addClass('current_service');
      $(this).next().next().slideDown();
    }
  });
  
  $('h1.current_service').live('click',function () {
    if($(this).next().next().is(':hidden'))
    {
      $(this).next().next().slideDown();  
    }
    else
    {
      $(this).removeClass('current_service');
      $(this).next().next().slideUp();  
    }
    
  })


 })



