// GORDON'S AJAX FORM SUBMISSION
function submitCustomerData() {
	var name  		= document.getElementById('main-name');
	var companyName = document.getElementById('main-company');
	var phone 		= document.getElementById('main-phone');			
	var noticeArea 	= document.getElementById('header-form-text-area');
	
	//Reset the input field classes
	name.className = 'input-text';
	companyName.className = 'input-text';
	phone.className = 'input-text';	
	
	if(name.value != '' && companyName.value != '' & phone.value != '') {
   		submitData(name.value,companyName.value,phone.value,noticeArea);
	} else {				
		if(name.value == '') {
			name.className = 'input-text incomplete'
		}		
		if(companyName.value == '') {
			companyName.className = 'input-text incomplete'
		}		
		if(phone.value == '') {
			phone.className = 'input-text incomplete'
		}	
		noticeArea.innerHTML = '<p>Please fill in the form below and we&#039;ll contact you to discuss your requirements, or call us on <strong>0845 36 77 200</strong>. <em>Please complete all the fields.</em></p>'						        
	}
	return false;		
}

// SLIDING CONTENT SECTIONS
$(document).ready(function () {

var $panels = $('#slider .scrollContainer > div');
var $container = $('#slider .scrollContainer');

// if false, we'll float all the panels left and fix the width 
// of the container
var horizontal = true;

// float the panels left if we're going horizontal
if (horizontal) {
	$panels.css({
		'float' : 'left',
		'position' : 'relative' // IE fix to ensure overflow is hidden
	});

	// calculate a new width for the container (so it holds all panels)
	$container.css('width', $panels[0].offsetWidth * $panels.length);
}

// collect the scroll object, at the same time apply the hidden overflow
// to remove the default scrollbars that will appear
var $scroll = $('#slider .scroll').css('overflow', 'hidden');


// handle nav selection
function selectNav() {
  $(this)
    .parents('ul:first')
      .find('a')
        .removeClass('selected')
      .end()
    .end()
    .addClass('selected');
}

$('#slider .navigation').find('a').click(selectNav);

// go find the navigation link that has this target and select the nav
function trigger(data) {
  var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
  selectNav.call(el);
}

if (window.location.hash) {
  trigger({ id : window.location.hash.substr(1) });
} else {
  $('ul.navigation a:first').click();
}

// offset is used to move to *exactly* the right place, since I'm using
// padding on my example, I need to subtract the amount of padding to
// the offset.  Try removing this to get a good idea of the effect
var offset = parseInt((horizontal ? 
  $container.css('paddingTop') : 
  $container.css('paddingLeft')) 
  || 0) * -1;


var scrollOptions = {
  target: $scroll, // the element that has the overflow

  // can be a selector which will be relative to the target
  items: $panels,

  navigation: '.navigation a',

  // selectors are NOT relative to document, i.e. make sure they're unique
  prev: 'img.left', 
  next: 'img.right',

  // allow the scroll effect to run both directions
  axis: 'xy',

  onAfter: trigger, // our final callback

  offset: offset,

  // duration of the sliding effect
  duration: 500,

  // easing - can be used with the easing plugin: 
  // http://gsgd.co.uk/sandbox/jquery/easing/
  easing: 'swing'
};

// apply serialScroll to the slider - we chose this plugin because it 
// supports// the indexed next and previous scroll along with hooking 
// in to our navigation.
$('#slider').serialScroll(scrollOptions);

// now apply localScroll to hook any other arbitrary links to trigger 
// the effect
$.localScroll(scrollOptions);

// finally, if the URL has a hash, move the slider in to position, 
// setting the duration to 1 because I don't want it to scroll in the
// very first page load.  We don't always need this, but it ensures
// the positioning is absolutely spot on when the pages loads.
scrollOptions.duration = 1;
$.localScroll.hash(scrollOptions);

});


// FANCYBOX MODAL WINDOW CODE
$(document).ready(function() {
	$("a.swanky-movie-zoom").fancybox({
		'zoomSpeedIn':200,
		'zoomSpeedOut':200,
		'overlayOpacity':0.5,
		'frameWidth':691,
		'frameHeight':615,
		'padding':0,
		'hideOnContentClick':false
	});
	$("a.swanky-image-zoom").fancybox({
		'zoomSpeedIn':500,
		'zoomSpeedOut':500,
		'frameWidth':641,
		'overlayShow':true,
		'overlayOpacity':0.5,
		'padding':0,
		'hideOnContentClick':true
	});
	$("a.padded-swanky-image-zoom").fancybox({
		'zoomSpeedIn':500,
		'zoomSpeedOut':500,
		'frameWidth':591,
		'frameHeight':400,
		'overlayShow':true,
		'overlayOpacity':0.5,
		'padding':0,
		'hideOnContentClick':true
	});
	$("a.padded-swanky-text-zoom").fancybox({
		'zoomSpeedIn':500,
		'zoomSpeedOut':500,
		'frameWidth':650,
		'frameHeight':350,
		'overlayShow':true,
		'overlayOpacity':0.5,
		'padding':0,
		'hideOnContentClick':true
	});
	$("a.contact-form-popup").fancybox({
		'zoomSpeedIn':500,
		'zoomSpeedOut':500,
		'frameWidth':550,
		'frameHeight':550,
		'overlayShow':true,
		'overlayOpacity':0.5,
		'padding':0,
		'hideOnContentClick':false
	});
	//fancybox for yahoo!local section
	$("a.swanky-zoom-yahoo-wyg").fancybox({
		'zoomSpeedIn':500,
		'zoomSpeedOut':500,
		'frameHeight':440,
		'frameWidth':667,
		'overlayShow':true,
		'overlayOpacity':0.5,
		'padding':0,
		'hideOnContentClick':true
	});
	$("a.swanky-zoom-cv-wyg").fancybox({
		'zoomSpeedIn':500,
		'zoomSpeedOut':500,
		'frameHeight':440,
		'frameWidth':571,
		'overlayShow':true,
		'overlayOpacity':0.5,
		'padding':0,
		'hideOnContentClick':true
	});
	$("a.fancybox-cv-listing-comparison").fancybox({
		'zoomSpeedIn':500,
		'zoomSpeedOut':500,
		'frameHeight':490,
		'frameWidth':571,
		'overlayShow':true,
		'overlayOpacity':0.5,
		'padding':0,
		'hideOnContentClick':true
	});
	$("a.fancybox-siv-listing-comparison").fancybox({
		'zoomSpeedIn':500,
		'zoomSpeedOut':500,
		'frameHeight':500,
		'frameWidth':571,
		'overlayShow':true,
		'overlayOpacity':0.5,
		'padding':0,
		'hideOnContentClick':true
	});
	$("a.fancybox").fancybox({
		'zoomSpeedIn':500,
		'zoomSpeedOut':500,
		'overlayShow':true,
		'overlayOpacity':0.5,
		'padding':0,
		'hideOnContentClick':true
	});
});

// FAQ ACCORDIAN
$(document).ready(function(){
	$('#faq-accordion').accordion();
});

// IMAGE SLIDESHOW (USED ON SIV SECTION)
function slideSwitch() {
    var $active = $('#siv-slideshow img.active');

    if ( $active.length == 0 ) $active = $('#siv-slideshow img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#siv-slideshow img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1500, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 3000 );
});


// JS FOR GOOGLE ADWORDS TABS
function toggleAdWordsTab(combo, id, adWordsTabArrayString){ 
    var adWordsTab = new Array();
    adWordsTabArray = adWordsTabArrayString.split(',');
    var adWordsTab = id.replace(combo, '');

    for ( var i in adWordsTabArray ){
        if(adWordsTab == adWordsTabArray[i]){
            document.getElementById(combo + adWordsTabArray[i]).className = 'on';
            document.getElementById(combo + adWordsTabArray[i] + "-content").className = 'adwords-tab';
        }
        else{
            document.getElementById(combo + adWordsTabArray[i]).className = '';
            document.getElementById(combo + adWordsTabArray[i] + "-content").className = 'adwords-tab hidden';
        }
    }
}

// GOOGLE ADWORDS FAQ SMOOTH OPENING/CLOSING
$(document).ready(function(){
	$(".faq-content").hide(); 				   
	$("a.faq").click(function(){
		if($(this).is('.active')) {
			$(this).toggleClass("active");
			$(this).next(".faq-content").slideToggle();
			return false;
		} else {
			$(".faq-content:visible").slideUp("slow"); // close all visible divs with the class of .content
			$("a.active").removeClass("active"); // remove the class active from all h1's with the class of .active
			$(this).toggleClass("active");
			$(this).next(".faq-content").slideToggle();
			return false;
		}
	});
});

// JS FOR FLI TABS
function toggleFliTab(combo, id, fliTabArrayString){ 
    var fliTab = new Array();
    fliTabArray = fliTabArrayString.split(',');
    var fliTab = id.replace(combo, '');

    for ( var i in fliTabArray ){
        if(fliTab == fliTabArray[i]){
            document.getElementById(combo + fliTabArray[i]).className = 'on';
            document.getElementById(combo + fliTabArray[i] + "-content").className = 'fli-tab';
        }
        else{
            document.getElementById(combo + fliTabArray[i]).className = '';
            document.getElementById(combo + fliTabArray[i] + "-content").className = 'fli-tab hidden';
        }
    }
}

// JS FOR ESTART TABS
function toggleEstartsTab(combo, id, estartsTabArrayString){ 
    var estartsTab = new Array();
    estartsTabArray = estartsTabArrayString.split(',');
    var estartsTab = id.replace(combo, '');

    for ( var i in estartsTabArray ){
        if(estartsTab == estartsTabArray[i]){
            document.getElementById(combo + estartsTabArray[i]).className = 'on';
            document.getElementById(combo + estartsTabArray[i] + "-content").className = 'estarts-tab';
        }
        else{
            document.getElementById(combo + estartsTabArray[i]).className = '';
            document.getElementById(combo + estartsTabArray[i] + "-content").className = 'estarts-tab hidden';
        }
    }
}


// jQuery instructions for inline form labels on header form
$(document).ready(function(){
	$("input.input-text").each(function (type) {

		$(this).focus(function () {
			$(this).prev("label.inlined").addClass("focus");
		});

		$(this).keypress(function () {
			$(this).prev("label.inlined").addClass("has-text").removeClass("focus");
		});

		$(this).blur(function () {
			if($(this).val() == "") {
				$(this).prev("label.inlined").removeClass("has-text").removeClass("focus");
			}
		});
	});
});




// Scripts for SIV jump menu
function sivSelector(targ,selObj,restore) {
	var op = selObj.options[selObj.selectedIndex];
	window.open(op.value, '', '');
	if (restore) selObj.selectedIndex = 0;
}



// Code for estart Design Gallery
function checkFirst(){
	var element = document.getElementById('estart-design-gallery');
	if(Number(element.style.left.replace('px',''))>=0) {
		return true
	} else {}
}
function checkLast(){
	var element = document.getElementById('estart-design-gallery');
	if(Number(element.style.left.replace('px',''))<=Number(Number(-508)*Number(4))) {
		return true;
	} else {}
}


$(document).ready(function() {
	$('.next-design').click(function() {
	    var lastDesign = checkLast();
		if(lastDesign){
			$('.scroll-container ul').animate({ left: '-=120', easing: 'swing' }, 50, function() {});
			$('.scroll-container ul').animate({ left: '+=120' }, 200, function() {});
		} else {
			$('.scroll-container ul').animate({	left: '-=508'}, 350, function() {});
		}
	});
	
	$('.previous-design').click(function() {
	    var firstDesign = checkFirst();
		if(firstDesign){
			$('.scroll-container ul').animate({ left: '+=120', easing: 'swing' }, 50, function() {});
			$('.scroll-container ul').animate({ left: '-=120' }, 200);
		} else {
			$('.scroll-container ul').animate({
				left: '+=508'
			}, 350, function() {
				// Animation complete.
			});
		}
	});
});