function confirm_destroy(element, action) {
  if (confirm("Are you sure?")) {
    var f = document.createElement('form');
    f.style.display = 'none';
    element.parentNode.appendChild(f);
    f.method = 'POST';
    f.action = action;
    var m = document.createElement('input');
    m.setAttribute('type', 'hidden');
    m.setAttribute('name', '_method');
    m.setAttribute('value', 'delete');
    f.appendChild(m);
    f.submit();
  }
  return false;
}

$.fn.textfieldLabel = function() {
  this.each(function() {
    $(this).hide();
    var lt = $(this).html(); // label text
    var f = $('#' + $(this).attr('for')); // field element

    f.val(lt);
    f.addClass('with-label');

    f.focus(function () {
      if ($(this).val() == lt) {
        $(this).val('');
        $(this).removeClass('with-label');
      }
    });

    f.blur(function () {
      if ($(this).val() == '') {
        $(this).val(lt);
        $(this).addClass('with-label');
      }
    });
  })
}

$(function() {
  $('body').addClass('js');

  // Labels in text fields
  $('#search-holder label').textfieldLabel();

  // Spotlight scroller (jQuery Cycle) dots
  if ($('#spotlight .item-list ul.jq li').size() > 1) {
    $('#spotlight .item-list ul.jq').after('<div id="nav-wrapper"><div id="nav">').cycle({
      fx:         'scrollLeft',
      speed:       800,
      timeout:     7000,
      pager:      '#nav',
      pagerEvent: 'mouseup',
      pauseOnPagerHover: true,
      pause:      true
    });
  }
  if ($('#spotlight2 .item-list2 ul.jq li').size() > 1) {
    $('#spotlight2 .item-list2 ul.jq').after('<div id="nav-wrapper2"><div id="nav2">').cycle({
      fx:         'scrollLeft',
      speed:       800,
      timeout:     7000,
      pager:      '#nav2',
      pagerEvent: 'mouseup',
      pauseOnPagerHover: true,
      pause:      true
    });
  }
  if ($('#spotlight3 .item-list3 ul.jq li').size() > 1) {
    $('#spotlight3 .item-list3 ul.jq').after('<div id="nav-wrapper3"><div id="nav3">').cycle({
      fx:         'scrollLeft',
      speed:       800,
      timeout:     7000,
      pager:      '#nav3',
      pagerEvent: 'mouseup',
      pauseOnPagerHover: true,
      pause:      true
    });
  }
  if ($('#spotlight4 .item-list4 ul.jq li').size() > 1) {
    $('#spotlight4 .item-list4 ul.jq').after('<div id="nav-wrapper4"><div id="nav4">').cycle({
      fx:         'scrollLeft',
      speed:       800,
      timeout:     7000,
      pager:      '#nav4',
      pagerEvent: 'mouseup',
      pauseOnPagerHover: true,
      pause:      true
    });
  }

  // Home page rollover boxes
  $(".prop-title").hide();

  $("#active-video").hover(
    function () {
      $(".video-hover").fadeOut(1000);
    },
    function () {
      
    }
  );

  $("#video").hover(
    function () {
      $(".narrow-video-hover").fadeOut(1000);
    },
    function () {
      
    }
  );

  $("#prop-one").hover(
    function () {
      $("#video-connect").css('background-position','100px 1px');
      $("#info-text").hide();
      $("#one-team-text").show();
      $("#ccs-text").hide();
      $("#cloud-text").hide();
      $("#talent-text").hide();
      $(".video-hover").show();
      // $('iframe').attr('src', 'http://player.vimeo.com/video/34780475?title=0&amp;byline=0&amp;portrait=0');
      $('#intro').attr('src', '/images/home/one-team.jpg').attr('name','/one-team.html');
      $("#prop-one").addClass('visited-box');
      $("#prop-two").removeClass('visited-box');
      $("#prop-three").removeClass('visited-box');
      $("#prop-four").removeClass('visited-box');
      $("#intro-button").css('display','block').css('margin-left', '20px');
    },
    function () {
      console.log('out one-team');
      // $("#video-connect").css('background-position','0px 50px');
    }
  );
  $("#prop-two").hover(
    function () {
      $("#video-connect").css('background-position','357px -34px');
      $("#info-text").hide();
      $("#one-team-text").hide();
      $("#ccs-text").show();
      $("#cloud-text").hide();
      $("#talent-text").hide();
      $(".video-hover").show();
      // $('iframe').attr('src', 'http://player.vimeo.com/video/34780287?title=0&amp;byline=0&amp;portrait=0');
      $('#intro').attr('src', '/images/home/ccs.jpg').attr('name','/cake-collaboration-services.html');
      $("#prop-one").removeClass('visited-box');
      $("#prop-two").addClass('visited-box');
      $("#prop-three").removeClass('visited-box');
      $("#prop-four").removeClass('visited-box');
      $("#intro-button").css('display','block').css('margin-left', '270px');
    },
    function () {
      console.log('out ccs-text');
      // $("#prop-two").addClass('visited-box');
      // $("#video-connect").css('background-position','0px 50px');
    }
  );
  $("#prop-three").hover(
    function () {
      $("#video-connect").css('background-position','534px -69px');
      $("#info-text").hide();
      $("#one-team-text").hide();
      $("#ccs-text").hide();
      $("#cloud-text").show();
      $("#talent-text").hide();
      $(".video-hover").show();
      // $('iframe').attr('src', 'http://player.vimeo.com/video/34780402?title=0&amp;byline=0&amp;portrait=0');
      $('#intro').attr('src', '/images/home/cloud-services.jpg').attr('name','/cloud-development-services.html');
      $("#prop-one").removeClass('visited-box');
      $("#prop-two").removeClass('visited-box');
      $("#prop-three").addClass('visited-box');
      $("#prop-four").removeClass('visited-box');
      $("#intro-button").css('display','block').css('margin-left', '520px');
    },
    function () {
      console.log('out cloud-text');
      // $("#video-connect").css('background-position','0px 50px');
    }
  );
  $("#prop-four").hover(
    function () {
      $("#video-connect").css('background-position','650px -104px');
      $("#info-text").hide();
      $("#one-team-text").hide();
      $("#ccs-text").hide();
      $("#cloud-text").hide();
      $("#talent-text").show();
      $(".video-hover").show();
      // $('iframe').attr('src', 'http://player.vimeo.com/video/34780130?title=0&amp;byline=0&amp;portrait=0');
      $('#intro').attr('src', '/images/home/cake-talent.jpg').attr('name','/cake-talent.html');
      $("#prop-one").removeClass('visited-box');
      $("#prop-two").removeClass('visited-box');
      $("#prop-three").removeClass('visited-box');
      $("#prop-four").addClass('visited-box');
      $("#intro-button").css('display','block').css('margin-left', '770px');
    },
    function () {
      console.log('out talent-text');
      // $("#video-connect").css('background-position','0px 50px');
    }
  );

  $("#intro").click(
    function () {
      window.location = $(this).attr('name');
    }
  );

  $("#intro-button").click(
    function () {
      window.location = "/services.html";
    }
  );
  $("#prop-one").click(
    function () {
      window.location = "/one-team.html";
    }
  );

  $("#prop-two").click(
    function () {
      window.location = "/cake-collaboration-services.html";
    }
  );

  $("#prop-three").click(
    function () {
      window.location = "/cloud-development-services.html";
    }
  );

  $("#prop-four").click(
    function () {
      window.location = "/cake-talent.html";
    }
  );

  $("#home-advert").click(
    function () {
      window.location = "/events.html";
    }
  );

  // $("#all-videos li").click(
  //   function () {
  //     window.location = $(this).find('a').attr('href');
  //   }
  // );
  // 
  // $("#all-videos li").hover(
  //   function () {
  //     $this = $(this);
		// 	$('#all-videos li').removeClass('over')
		// 	$this
		// 	  .addClass('over')
		// 		.find("div.hidden").show().end()
		// 		.find('div').not('.hidden').hide();
		// 	switch($(this).attr('id')) {
		// 		case "intro-thumb":
		//       $('iframe').attr('src', 'http://player.vimeo.com/video/34774401?title=0&amp;byline=0&amp;portrait=0');
		// 		;
		// 		case "video1-thumb":
		//       $('iframe').attr('src', 'http://player.vimeo.com/video/34780475?title=0&amp;byline=0&amp;portrait=0');
		// 		;
		// 		case "video2-thumb":
		// 		  $('iframe').attr('src', 'http://player.vimeo.com/video/15592712?title=0&amp;byline=0&amp;portrait=0');
		// 		;
		// 		case "video3-thumb":
		//       $('iframe').attr('src', 'http://player.vimeo.com/video/30079778?title=0&amp;byline=0&amp;portrait=0');
		// 			;
		// 		case "video4-thumb":
	 //    		$('iframe').attr('src', 'http://player.vimeo.com/video/34780130?title=0&amp;byline=0&amp;portrait=0');
		// 		;
		//   }
  //   }, function () {
  //     $this = $(this);
  //     $this
		// 	  .find('div.hidden').hide().end()
  //       .find('div').not('.hidden').show();
  //   }
  // );

  // $('#brochure-banner').click(function(){
  //   window.location = $('#brochure-banner .moreinfo a').attr('href');
  // });
  // $('#hiring-banner').click(function(){
  //   window.location = $('#hiring-banner .moreinfo a').attr('href');
  // });

  if($.trim($('#secondary-nav-holder ul.secondary').html()) == "") {
    $('#nav').css('height','29px');
  } else {
    $('#nav').css('height','58px');
  };
  $('#clients-slider').tinycarousel({ interval: true, display: 1 });
  $('#partners').tinycarousel({ interval: true, display: 1 });
  $("p").filter(function() {
    if ($.trim($(this).text()) === "") {
      $(this).css('margin','0').css('padding','0');
    };
  });

  function fadeFlash() {
    $('#flash').fadeOut('slow');
  }
  setTimeout(fadeFlash, 10000);

  $('#events-content').cycle({fx: 'scrollUp', speed: 1000, timeout: 6000, height:  '58px'});
  $('#block-box-four .row_holder').cycle({fx: 'scrollUp', speed: 1000, timeout: 6000, height: '58px'});
  $('#banner').cycle({fx: 'scrollLeft', speed: 1000, timeout: 10000, height: '275px', width: '730px'});
  $('#brochure-banner .moreinfo').show();

  $("table tbody > tr:first").addClass('first-row')

});

