function preload(arrayOfImages) {
  $(arrayOfImages).each(function(){
    $('<img/>')[0].src = this;
  });
}

// to load hover images



$(document).ready(function(){
  $('#slides').slides({
    preload: true,
    generateNextPrev: true
  });

  $('.accordion').accordion({
    autoHeight  : false,
    collapsible : true,
    active      : false // start compressed
  });
  //to make the first tab in accordion active
  $('#tab1').click();

// the client scroller in the home page
  $('#client').cycle({
    fx: 'scrollDown'
  });

  // customer cuote in the homepage footer
  $('#footer_center').cycle({
    fx:     'fade',
    speed:   300,
    timeout: 10000,
    pause:   1,
    cleartypeNoBg: true
  });

  // to call preload function in order to load images
  preload([
    $('#base_path').attr("name")+"images/home_hover.png",
    $('#base_path').attr("name")+"images/work_hover.png",
    $('#base_path').attr("name")+"images/skills_hover.png",
    $('#base_path').attr("name")+"images/your_team_hover.png",
    $('#base_path').attr("name")+"images/way_hover.png",
    $('#base_path').attr("name")+"images/to_top_hover.png",
    $('#base_path').attr("name")+"images/left_nav_on.png"
    ]);

/*
 *  to change the menu images on hover
 **/
  $('.menu_bt1 a').hover(function(){
    $('.menu_bt1 a img').attr("src", $('#base_path').attr("name")+"images/home_hover.png");
  },function(){
    $('.menu_bt1 a img').attr("src", $('#base_path').attr("name")+"images/home.png");
  });

  $('.menu_bt2 a').hover(function(){
    $('.menu_bt2 a img').attr("src", $('#base_path').attr("name")+"images/work_hover.png");
  },function(){
    $('.menu_bt2 a img').attr("src", $('#base_path').attr("name")+"images/work.png");
  });

  $('.menu_bt3 a').hover(function(){
    $('.menu_bt3 a img').attr("src", $('#base_path').attr("name")+"images/skills_hover.png");
  },function(){
    $('.menu_bt3 a img').attr("src", $('#base_path').attr("name")+"images/skills.png");
  });

  $('.menu_bt4 a').hover(function(){
    $('.menu_bt4 a img').attr("src", $('#base_path').attr("name")+"images/way_hover.png");
  },function(){
    $('.menu_bt4 a img').attr("src", $('#base_path').attr("name")+"images/way.png");
  });

  $('.menu_bt5 a').hover(function(){
    $('.menu_bt5 a img').attr("src", $('#base_path').attr("name")+"images/your_team_hover.png");
  },function(){
    $('.menu_bt5 a img').attr("src", $('#base_path').attr("name")+"images/your_team.png");
  });
// End button hover


  // to scroll to the top of the page
  $("#to_top").click(function(){
    $('html, body').animate({
      scrollTop: 0
    }, 'slow');
  });

  // the top slideshow
  $('#slider1')
  .anythingSlider({
    width          : 850,
    height         : 195,
    startStopped   : true,
    toggleControls : true,
    theme          : 'metallic'
        
  })

  // the right button sildeshow (in the window)
  $('#slider3').anythingSlider({
    width               : 280,   // if resizeContent is false, this is the default width if panel size is not defined
    height              : 277,   // if resizeContent is false, this is the default height if panel size is not defined
    resizeContents      : true, // If true, solitary images/objects in the panel will expand to fit the viewport
    startStopped        : true  // If autoPlay is on, this can force it to start stopped
          
  });

  // when slide image 1 in the main slide show clicked
     
  $('#slide1, #slider_bt1').click(function(){
    navigate(2);
  });

  // when slide image 2 in the main slide show clicked
  $('#slide2, #slider_bt2').click(function(){
    navigate(3);
  });

  // when slide image 3 in the main slide show clicked
  $('#slide3,#slider_bt3').click(function(){
    navigate(4);
  });

  // when slide image 4 in the main slide show clicked
  $('#slide4, #slider_bt4').click(function(){
    navigate(5);
  });


  $('.send_button').click(function(){
    var error_class_name=".error_message"
    var user_message=$('.home_drop_message textarea#edit-message').attr('value');
    var emailAddress=$('.home_drop_title input#edit-email').val();
     validate_drop_line(user_message,emailAddress,error_class_name);
return false;
  });

  $('.involved_send_button').click(function(){
    var error_class_name=".taqat_error_message";
    var user_message=$('#involved_message').attr('value');
    var emailAddress=$('#involved_email').val();
    validate_drop_line(user_message,emailAddress,error_class_name);
    return false;
  });
  
   $('.involved_send_button2').click(function(){
 var error_class_name=".taqat_error_message2";
    var user_message=$('#involved_message').attr('value');
    var emailAddress=$('#involved_email').val();
   validate_drop_line(user_message,emailAddress,error_class_name)
    return false;
  });

function validate_drop_line(user_message,emailAddress,error_class_name)
{
    var message="";
  var check=true;
  var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    if(!pattern.test(emailAddress))
    {
      message="*Enter a valid e-mail.<br />" ;
      check= false;
    }
    if(user_message=='Message')
    {

      message +=" *Enter your message.";
      check= false;
    }
    if(!check)
      $(error_class_name).html(message);
    if(check)
    {

      if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      }
      else
      {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function()
      {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
          $(error_class_name).html("Message successfully sent.");
        }
      }
      xmlhttp.open("GET",$('#base').attr("name")+"templates/submit_form.php?email="+emailAddress+"&message="+user_message,true);
      xmlhttp.send("");
    }

}
 

  // to make links in outsourcing/partner-not-provider goes to specific tab in outsourcing/hire-us through post id
  var param1 = getUrlVars()["id"];
  if(param1=="hireTeam"){
    DisplayClick("imgHireTeam");
  }
  else  if(param1=="hireDeveloper"){
    DisplayClick("imgHireDeveloper");
  }
  else  if(param1=="getQuote"){
    DisplayClick("imgGetQuote");
  }
  else  if(param1=="USAOffice"){
    DisplayClick("imgUSAOffice");
  }
// end of links

});

// to get the parameter posted in URL used in outsourcing/partner-not-provider goes to specific tab
function getUrlVars() {
  var vars = {};
  var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
    vars[key] = value;
  });
  return vars;
}

function navigate($i){
  // to quik navigate between slides in the main slideshow
  $('#slider1').anythingSlider($i);

  // to quik navigate between slides in the right button slideshow
  // to check if the window slider is exist in this page
  if($('#slider3').length!=0)
    $('#slider3').anythingSlider($i);   
}

function changeForward(){
  if($('#window_slides').length!=0){         
    $('#slider3').data('AnythingSlider').goForward();
      //for IE only
    if($.browser.msie)
      $(".slides_container").stop(true,true).animate({
        backgroundPositionX: "-=280px"
      }, 600);
     //for all browsers
    else
      $(".slides_container").stop(true,true).animate({
        backgroundPosition: "-=280px 0 "
      } ,600);
  }
}

function changeBack(){
  if($('#window_slides').length!=0){
    $('#slider3').data('AnythingSlider').goBack();
    // to animate the right button slideshow bg
    //for IE only
    if($.browser.msie)
      $(".slides_container").stop(true,true).animate({
        backgroundPositionX: "+=280px"
      }, 600);
    //for all browsers
    else
      $(".slides_container").stop(true,true).animate({
        backgroundPosition: "+=280px 0 "
      }, 600);
  }
}

