/* Author: 
      Dom Ioanna
*/
   

   
   jQuery(document).ready(function() {

    });
// Resolve conflict issues w/ other libraries
jQuery.noConflict();



// Window load effects
jQuery(window).load(function() { 

  if ( jQuery('#intro').click() )

// Intro
  var timer;
  
// effects
  function goOnFadeIn(event) { jQuery(".intro_go_on").fadeIn("slow"); }
  function peacockFadeIn(event) { jQuery("#peacock").fadeIn("slow"); }
  function showOffFadeIn(event) { jQuery(".intro_show_off").show("slide", { direction: "up" }, 1000); }
  function logoFadeIn(event) { jQuery("#intro_logo").fadeIn("slow"); }
  function logoEDFadeIn(event) { jQuery("#intro_ed").fadeIn("slow"); }
  function backgroundFade(event) {  
    jQuery('#spider-wrapper').css({backgroundPosition: '0px -700px'});
    jQuery("#intro").fadeOut("slow");
    jQuery('.slide-out-div').fadeIn("slow");
    jQuery('.slide-out-div-home').fadeIn("slow");
    jQuery("#nav-pad-home").animate( { height: '80px' }, { queue: false, duration: 1000 });
    jQuery(".block_1").delay(300).show("slide",  { direction: "up" }, 1000);
    jQuery(".block_2").delay(600).show("slide",  { direction: "up" }, 1000);
    jQuery(".block_3").delay(900).show("slide",  { direction: "up" }, 1000);
    jQuery(".block_4").delay(1200).show("slide", { direction: "up" }, 1000);
    jQuery(".block_5").delay(1500).show("slide", { direction: "up" }, 1000);
    jQuery(".block_6").delay(1800).show("slide", { direction: "up" }, 1000);
    jQuery(".block_7").delay(2100).show("slide", { direction: "up" }, 1000);
    jQuery('#spider-wrapper').delay(200).animate({backgroundPosition: '0px 0px'}, 5000); 
  }
  
// events
  function goOnFadeInTimer(event) { clearTimeout(timer); timer = setTimeout(eval("goOnFadeIn"),"1000"); }
  function peacockFadeInTimer(event) { timer = setTimeout(eval("peacockFadeIn"),"3500"); }
  function showOffFadeInTimer(event) { timer = setTimeout(eval("showOffFadeIn"),"5000"); }
  function logoFadeInTimer(event) { timer = setTimeout(eval("logoFadeIn"),"7000"); timer = setTimeout(eval("logoEDFadeIn"),"9000"); }
  function backgroundFadeTimer(event) { timer = setTimeout(eval("backgroundFade"),"11000"); }
  
// instantiations
  goOnFadeInTimer();
  peacockFadeInTimer();
  showOffFadeInTimer();
  logoFadeInTimer();
  backgroundFadeTimer();
  
// After intro, or if clicked, the blocks load in
  jQuery('#intro').click(function() {
    jQuery('#spider-wrapper').css({backgroundPosition: '0px -700px'});
    jQuery(this).stop(true, true).fadeOut();
    jQuery("#nav-pad-home").animate( { height: '80px' }, { queue: false, duration: 1000 });
    jQuery('.slide-out-div-home').fadeIn("slow");
    jQuery(".block_1").hide().addClass('block_1_click').removeClass('block_1').delay(300).show("slide", { direction: "up" }, 1000);
    jQuery(".block_2").hide().addClass('block_2_click').removeClass('block_2').delay(600).show("slide", { direction: "up" }, 1000);
    jQuery(".block_3").hide().addClass('block_3_click').removeClass('block_3').delay(900).show("slide", { direction: "up" }, 1000);
    jQuery(".block_4").hide().addClass('block_4_click').removeClass('block_4').delay(1200).show("slide", { direction: "up" }, 1000);
    jQuery(".block_5").hide().addClass('block_5_click').removeClass('block_5').delay(1500).show("slide", { direction: "up" }, 1000);
    jQuery(".block_6").hide().addClass('block_6_click').removeClass('block_6').delay(1800).show("slide", { direction: "up" }, 1000);
    jQuery(".block_7").hide().addClass('block_7_click').removeClass('block_7').delay(2100).show("slide", { direction: "up" }, 1000);
    jQuery('#spider-wrapper').delay(200).animate({backgroundPosition: '0px 0px'}, 5000); 
  }, function() {});

});

// On hover, the images on homepage increase in size, and decrease on mouseout
  jQuery('a.home-news-image img').mouseenter(function(e) {
    jQuery(this).animate({ height: '210', left: '-5', top: '-5', width: '300'}, 100);
  }).mouseleave(function(e) {
    jQuery(this).animate({ height: '200', left: '0', top: '0', width: '290'}, 100);
  });

  jQuery('a.home-block-image img').mouseenter(function(e) {
    jQuery(this).animate({ height: '140', left: '-5', top: '-5', width: '220'}, 100);
  }).mouseleave(function(e) {
    jQuery(this).animate({ height: '130', left: '0', top: '0', width: '210'}, 100);
});

// jTwitter
  jQuery(".tweet").tweet({
    username: "fabspiderltd",
    avatar_size: 0,
    count: 1,
    loading_text: "loading tweets..."
  });

// Page shadow
  jQuery('#page').shadow( {type:'sides', sides:'vt-2'});
  jQuery('.drop-shadow-img').shadow('raised');
  jQuery('.home-block-image img').shadow('raised');
  jQuery('.home-news-image img').shadow('raised');
  jQuery('.news-post img').shadow('raised');
  jQuery('.jqmWindow').shadow('raised');
  
// Gives illusion of nav dropping down
  jQuery("#nav-pad").animate( { height: '80px' }, { queue: false, duration: 500 });
  jQuery('.slide-out-div').fadeIn("slow");

// Curves corners
  jQuery('.read-more').corner("5px");
  jQuery('input').corner("5px");
  jQuery('textarea').corner("5px");
  jQuery('select').corner("5px");
  jQuery('.selecterBtns a').corner("5px");
  jQuery('.hosting-package').corner("7px");
  jQuery('.hosting-read-more').corner("bottom 7px");
  jQuery('.hosting-package h3').corner("top 7px");

// Adds a div.box-inner to all div.box
  jQuery('.box').wrapInner('<div class="box-inner" />');

// Portfolio Filter initiation
jQuery(function(){
	jQuery('.selecter').mobilyselect({
		collection: 'all',
		animation: 'fade',
		duration: 300,
		listClass: 'selecterContent',
		btnsClass: 'selecterBtns',
		btnActiveClass: 'active',
		elements: 'li',
		onChange: function(){},
		onComplete: function(){}
	});
});



// Social box on Get In Touch page, hover on link slides link to right
jQuery(document).ready(function() {
  jQuery('#social-box ul li a').hover(function() { //mouse in
    jQuery(this).animate({ paddingLeft: '20px' }, 400);
  }, function() { //mouse out
    jQuery(this).animate({ paddingLeft: '10px' }, 400);
  });
});


// Contact form live submit
jQuery(document).ready(function(){

  jQuery('#contactform').submit(function(){
    var action = jQuery(this).attr('action');

    // Message box
    jQuery("#message").slideUp(750,function() {
      jQuery('#message').hide();
    
    // Loads loader.gif image after submit
      jQuery('#submit')
        .after('<img src="http://www.fabspider.com/wp-content/themes/fabspider/images/loader.gif" class="loader" />')
        .attr('disabled','disabled');

    // Creates live $_POST attributes for PHP
      jQuery.post(action, { 
        recipient: jQuery('#recipient').val(),
        name: jQuery('#name').val(),
        email: jQuery('#email').val(),
        phone: jQuery('#phone').val(),
        subject: jQuery('#subject').val(),
        comments: jQuery('#comments').val(),
        verify: jQuery('#verify').val()
      },
      function(data){
        document.getElementById('message').innerHTML = data;
        jQuery('#message').slideDown('slow');
        jQuery('#contactform img.loader').fadeOut('slow',function(){jQuery(this).remove()});
        jQuery('#submit').removeAttr('disabled'); 
        if(data.match('success') != null) jQuery('#contactform').slideUp('slow');
      });
    });
  
    return false; 
  });
});

// Adds target="_blank" to 'Services' > 'Telecomms' on the Nav 
  jQuery('.menu-item-type-custom a').click(function(){
    this.target = "_blank";
  });
  
// 
jQuery("a[href='http://fabspider.com/about-us/']").attr('href', 'http://fabspider.com/meet-the-team/')




// jQuery Slide Out Tab
  jQuery(function(){
    jQuery('.slide-out-div').tabSlideOut({
      tabHandle: '.handle',                     //class of the element that will become your tab
      pathToTabImage: 'http://fabspider.com/wp-content/themes/fabspider/images/tab.png', //path to the image for the tab //Optionally can be set using css
      imageHeight: '122px',                     //height of tab image           //Optionally can be set using css
      imageWidth: '40px',                       //width of tab image            //Optionally can be set using css
      tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
      speed: 500,                               //speed of animation
      action: 'hover',                          //options: 'click' or 'hover', action to trigger animation
      topPos: '200px',                          //position from the top/ use if tabLocation is left or right
      leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
      fixedPosition: true                      //options: true makes it stick(fixed position) on scroll
    });
  });
  
  jQuery(function(){
    jQuery('.slide-out-div-home').tabSlideOut({
      tabHandle: '.handle',                     //class of the element that will become your tab
      pathToTabImage: 'http://fabspider.com/wp-content/themes/fabspider/images/tab.png', //path to the image for the tab //Optionally can be set using css
      imageHeight: '122px',                     //height of tab image           //Optionally can be set using css
      imageWidth: '40px',                       //width of tab image            //Optionally can be set using css
      tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
      speed: 500,                               //speed of animation
      action: 'hover',                          //options: 'click' or 'hover', action to trigger animation
      topPos: '200px',                          //position from the top/ use if tabLocation is left or right
      leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
      fixedPosition: true                      //options: true makes it stick(fixed position) on scroll
    });
  });

  
// jQuery Modal Lightbox
  jQuery().ready(function() {
    jQuery('#dialog').jqm();
    jQuery('#middlew').jqm({modal: true, trigger: 'a.middlew'});
    jQuery('#junior').jqm({modal: true, trigger: 'a.junior'});
  });

  jQuery('.selecterBtns a').mouseenter(function(e) {
    jQuery(this).animate({backgroundColor:'#ccc'}, 300);
  }).mouseleave(function(e) {
    jQuery(this).animate({backgroundColor:'#ededed'}, 300);
    jQuery('.active').animate({backgroundColor:'#ccc'}, 300);
  });
  
  jQuery('#portfolio-clients li').mouseenter(function(e) {
    jQuery(this).children(".caption").fadeIn(500);
  }).mouseleave(function(e) {
    jQuery(this).children(".caption").fadeOut(500);
  });



  jQuery('.slideshow').cycle({ 
      fx:    'fade', 
      speed:  500 
   });


   jQuery('.corp-link').click( function() {
     jQuery('html, body').animate({
       scrollTop: jQuery("#corporate").offset().top
     }, 2000);
  });
  
   jQuery('.print-link').click( function() {
     jQuery('html, body').animate({
       scrollTop: jQuery("#print").offset().top
     }, 2000);
  });
  
   jQuery('.marketing-link').click( function() {
     jQuery('html, body').animate({
       scrollTop: jQuery("#marketing").offset().top
     }, 2000);
  });
  


  jQuery(document).ready(function(){

  // hide #back-top first
    jQuery("#back-top").hide();

  // fade in #back-top
    jQuery(function () {
      jQuery(window).scroll(function () {
        if (jQuery(this).scrollTop() > 100) {
          jQuery('#back-top').fadeIn();
        } else {
          jQuery('#back-top').fadeOut();
        }
      });

      // scroll body to 0px on click
      jQuery('#back-top a').click(function () {
        jQuery('body,html').animate({
          scrollTop: 0
        }, 800);
        return false;
      });
    });
  });
