/* 
  Author: Silverfish AG, Marcel Stadelmann
  Date: 01. September 2011
*/

debugArr = [];
debugObj = {};

$(function() {

    // detect ie
    isIE  = ($.browser.msie) ? true : false;
    isIE6 = ($.browser.msie && parseInt(jQuery.browser.version) == 6) ? true : false;
    isIE7 = ($.browser.msie && parseInt(jQuery.browser.version) == 7) ? true : false;
    isIE8 = ($.browser.msie && parseInt(jQuery.browser.version) == 8) ? true : false;
  
  // clear browser incompatibilities
  if (isIE6 || isIE7) {
    $("input[type=text]").addClass("text");
    $("input[type=submit]").addClass("submit");
    $("#copyright").prepend("<br />");
    $("#main-nav li:not(:last-child) a, #languages li:not(:last-child) a").append('&nbsp;&nbsp;<span>|</span>&nbsp;&nbsp;');
    $("#sub-nav ul ul li a, #sub-nav ul ul ul li a").prepend('-&nbsp;');
  }
  
  if (isIE6 || isIE7) {
    $(".workspaces .csc-textpic-imagewrap a img").hover(function(){
      $(this).css("border", "1px solid #1463a8");
    }, function(){
      $(this).css("border", "1px solid #f2f2f2");  
    });
  }
  
  // remove default values in input fields
  defaultVal = '';
  $("input.searchbtn, #awb").focus(function(){
    defaultVal = $(this).val();
    $(this).val('');
  });
  
  // add default values again
  $("input.searchbtn, #awb").blur(function(){
    if ($(this).val() == '') {
        $(this).val(defaultVal);
    }
  });
  
  // track and trace (homepage form)
  $(".btn-trackntrace").click(function(e) {
    e.preventDefault();
    var awb = $("#awb").val();
    $.fancybox.showActivity();
    $.ajax({
      type   : "GET",
      cache  : false,
      url     : "http://www.dnata.ch/web/tracktrace.php?awb=" + awb,
      success: function(response) {
            $.fancybox({'padding'           : 15,
                        'content'           : response,
                        'hideOnOverlayClick': false,
                        'onClosed'          : function() {
                                                $("input[name=awb]").val("Airwaybill-Number");
                                              }
                       });
      }
    });
    return false;
  });
  
  // select every 3rd item in workspaces overview and remove right margin
  $(".workspaces .csc-textpic:nth-child(3n+2)").css("margin-right", 0);
  
  // lightbox for workspace thumbnails
  $("a.lightbox").attr("rel", "lightbox-group");
  $("a[rel=lightbox-group]").fancybox({'padding': 10});
  
  $(".tiplink a").fancybox({'width'     : 700,
              'height'    : 350,
                'autoScale'     : true,
                'transitionIn'  : 'none',
              'transitionOut'  : 'none',
              'type'      : 'iframe',
              'padding'    : 5,
                            'hideOnOverlayClick': false});  

  $('.job-messages').cycle({
    fx: 'fade',
    timeout:  5000,
    speed: 1500,
    cleartypeNoBg:true
  });
  
});


