
jQuery.noConflict();

jQuery(document).ready(function(){

	jQuery('#mainSlider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:1500, //Slide transition speed
		pauseTime:4000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8 //Universal caption opacity

	});

	jQuery('.slide-out-div').tabSlideOut({
		tabHandle: '.handle',                              //class of the element that will be your tab
		toggleButton: '.magicButton',
		pathToTabImage: 'images/contact_tab2.png',          //path to the image for the tab *required*
		imageHeight: '122px',                               //height of tab image *required*
		imageWidth: '40px',                               //width of tab image *required*    
		tabLocation: 'left',                               //side of screen where tab lives, top, right, bottom, or left
		speed: 300,                                        //speed of animation
		action: 'click',                                   //options: 'click' or 'hover', action to trigger animation
		topPos: '200px',                                   //position from the top
		fixedPosition: true                               //options: true makes it stick(fixed position) on scroll
	});
	
	jQuery(".defaultText").focus(function(srcc)
	{
		if (jQuery(this).val() == jQuery(this)[0].title)
		{
			jQuery(this).removeClass("defaultTextActive");
			jQuery(this).val("");
		}
	});
	
	jQuery(".defaultText").blur(function()
	{
		if (jQuery(this).val() == "")
		{
			jQuery(this).addClass("defaultTextActive");
			jQuery(this).val(jQuery(this)[0].title);
		}
	});
	
	jQuery(".defaultText").blur(); 	

  var currentPosition = 0;
  var slideWidth = 300;
  var slides = jQuery('.slide');
  var numberOfSlides = slides.length;

  // Remove scrollbar in JS
  jQuery('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides.wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  jQuery('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert controls in the DOM
  jQuery('#slideshow')
    .prepend('<span class="control" id="leftControl">Clicking moves left</span>')
    .append('<span class="control" id="rightControl">Clicking moves right</span>');

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  jQuery('.control')
    .bind('click', function(){
    // Determine new position
	currentPosition = (jQuery(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
    
	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    jQuery('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
  });

  // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
	if(position==0){ jQuery('#leftControl').hide() } else{ jQuery('#leftControl').show() }
	// Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ jQuery('#rightControl').hide() } else{ jQuery('#rightControl').show() }
  }	
});

function sendRequest() {
	var txt;
	var bValid = true;
	var warning;
	
	txt = document.getElementById("name");
	if (txt.value == "" || txt.value == "Name") {
		bValid = false;
		warning = "Name required";
	}
	
	txt = document.getElementById("phone");
	if (txt.value == "" || txt.value == "Phone" && (bValid)) {
		bValid = false;
		warning = "Phone required";
	}
	
	txt = document.getElementById("warningLabel");
	if (bValid) {
		txt.innerHTML = "";
		new Ajax.Request("requestcallback.php", 
			{ 
			method: 'post', 
			postBody: 'name='+ $F('name') + '&email='+ $F('email') + '&phone='+ $F('phone') + '&enquiry='+ $F('enquiry'),
			onComplete: showResponse 
			});
	} else {
		txt.innerHTML = warning;
	}
}

function showResponse(req){
	document.getElementById("magicButton").click();
}


