// JavaScript Document





//HideIt check function
function hideIt(a)
{
	$(a).stop(true,false);
	var b = $(a).attr('cPin');
	if(b == 'no'){
		$(a).mouseleave(function(){hideItOut(a)});
	}
	$(a).click(function(){hideItPin(a)});
	var t = $('.HideItContainer',a).height();
	//adnimate to the right size
	if(t > 105)
	{
		$(a).animate({height : t}, 500, function(){});
	}
	
	
	//mouse out
	
}
function hideItOut(a)
{
	$(a).stop(true,false).animate({height : 105}, 500, function(){});
	//unbind the mouse out
	$(a).unbind('mouseleave');
	$(a).unbind('click');
	
}

function hideItPin(a)
{
	var b = $(a).attr('cPin');
	
	if(b == 'no')
	{
		$(a).unbind('mouseleave');
		$(a).attr('cPin', 'yes');
		$(a).prepend('<div class="pin"></div>');
	}
	else
	{
		$(a).mouseleave(function(){hideItOut(a)});
		$(a).attr('cPin', 'no');
		$('.pin', a).remove();
	}
	
	//remove function when the mouse leaves
	$(a).mouseleave(function(){$(a).unbind('click');});
	
}





var autoSlideTimer;
var autoSlideEventCheck = 0;
function autoSlide(is)
{
	//start the slides show and attach the events
	if(!is)
	{
		is = 8000;
	}
	
	
	
	var target = $('.slideShowHolder');
	autoSlideTimer = setTimeout("autoSlideNext()",is);
	
	if(autoSlideEventCheck == 0)
	{
		autoSlideEventCheck++;
		//add the event listeners
		target.mouseenter(function(){autoSlideEnter()});
		autoSlideMessage();
	}
	
	
}

function autoSlideNext()
{
	//contolls the sliding
	//find the position of the track
	var track = $('.slideShowTrack');
	track.pos = track.position();
	var trackLeft = track.pos.left;	
	
	
	
	if(trackLeft > -1874)
	{
		//move track to the next
		var trackNext = trackLeft - 937;
		track.animate({left : trackNext}, 1000, function(){autoSlideMessage()});	
	}
	else
	{
		track.animate({left : 0}, 200, function(){autoSlideMessage()});
	}	
	
	autoSlide();
}

function autoSlideEnter()
{
	//actions to take when mouse over in the slider
	
	var target = $('.slideShowHolder');
	var track = $('.slideShowTrack');
	var arrows = $('.slideShowArrowHolder');
	var message = $('.slideShowMessage');
	
	//track.stop(true,true);// stop the animation
	arrows.stop(true,true);// stop the animation
	message.stop(true,true);// stop the animation	
	
	clearTimeout(autoSlideTimer);//clear the time out
	arrows.fadeIn();
	message.fadeIn();
	
	target.mouseleave(function(){autoSlideExit()});
	
}

function autoSlideExit()
{
	
	//unbind the mouseleave event listener
	var target = $('.slideShowHolder');
	var arrows = $('.slideShowArrowHolder');
	var message = $('.slideShowMessage');	
	
	arrows.stop(true,true);// stop the animation
	message.stop(true,true);// stop the animation

	arrows.fadeOut();
	message.fadeOut();
	
	target.unbind("mouseleave");
	autoSlide(3000);
}

function autoSlideN()
{
	//next image
	var track = $('.slideShowTrack');
	track.stop(true,true);// stop the animatio
	track.pos = track.position();
	var trackLeft = track.pos.left;
	
	
	
	if(trackLeft > -1874)
	{
		//move track to the next
		var trackNext = trackLeft - 937;
		track.animate({left : trackNext}, 1000, function(){autoSlideMessage()});	
	}
	else
	{
		track.animate({left : 0}, 200, function(){autoSlideMessage()});
	}
}

function autoSlideB()
{
	//back image
	var track = $('.slideShowTrack');
	track.stop(true,true);// stop the animation
	track.pos = track.position();
	var trackLeft = track.pos.left;
	
	
	
	if(trackLeft < 0)
	{
		//move track to the next
		var trackNext = trackLeft + 937;
		track.animate({left : trackNext}, 1000, function(){autoSlideMessage()});	
	}
	else
	{
		track.animate({left : -1874}, 200, function(){autoSlideMessage()});
	}
}

function autoSlideMessage()
{
	var track = $('.slideShowTrack');
	track.pos = track.position();
	var trackLeft = track.pos.left;
	var count = 0;
	
	if(trackLeft == 0){count = 0;}
	if(trackLeft == -937){count = 1;}
	if(trackLeft == -1874){count = 2;}	
	//find the section
	var currentMessage = $('.slideImage').get(count);
	var heading = $(currentMessage).attr('cTitle');
	var message = $(currentMessage).attr('cMessage');
	
	var advert = '<h2>'+heading+'</h2><p>'+message+'</p>';
	
	$('.slideShowMessage').html(advert);
	
}
































































var popIt = function(a,b)
{
	//link being called
	var call = $(a).attr('address');
	var extra = $(a).attr('extra');
	var title = $(a).attr('title');
	
	popIt.remove();//close any other boxes that are open
	
	//create the popIt
	//$('body').prepend(popIt.contents);
	popIt.create(call, extra, title,b);
}

popIt.create = function(call, extra, title,b)
{
	//the preloader
	var preloader = '<br/><p>LOADING ...</p><br/>';
	//add the popIt to the stage
	var box = popIt.contents_head + title + popIt.contents_headb + popIt.contents_foot;
	$('body').prepend(box);
	$('.popItHolder').html(preloader);
	//set a custom width
	if(b)
	{
		$('.popItCon').css({width : b});
		$('.popItConG').css({width : b});	
		
	}
	popIt.position(true);//position
	
	//call the content
	var contents = "";
	$.post("/includes/php/popIt/"+call+".php", {extra:extra},
	function(data) {
		$('.popItHolder').html(data);
		popIt.position(true);
		
	});
}

popIt.position = function(a)
{
	//position the popIt into the center of the stage
	var l = 0;
	var r = 0;	
	//width and height of the container
	var Dwidth = $('.popItCon').width()+24;//+50 for the sides that are absulute
	var Dheight = $('.popItCon').height()+50;	
	//find screen width and hieght
	//var Swidth = window.innerWidth;
	//var Sheight = window.innerHeight;
	
	var Swidth = "";
	var Sheight = "";
	
	if (typeof window.innerWidth != 'undefined')
	 {
		  Swidth = window.innerWidth,
		  Sheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   Swidth = document.documentElement.clientWidth,
		   Sheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   Swidth = document.getElementsByTagName('body')[0].clientWidth,
		   Sheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	
	
	
	//get the amount the the window has been scrolled	
	var ws = $(window).scrollTop();	
	//get the width of the whole container	
	l = Swidth / 2;
	l = l - (Dwidth / 2);	
	r = Sheight / 2;
	r = r - (Dheight / 2) + ws;	
	
	//makes sure that the popIt doesnt go above the window !!
	if(r < 30)
	{
		r = 100;
	}
	
	
			$('.popIt').stop(true,false);
			$('.popIt').animate({top : r, left : l},500, function(){});
		
}


popIt.remove = function()
{
	$('.popIt').remove();
	$('.h_tool_ho').remove();
	
}

popIt.contents_head = '<div class="popIt">'+
						'<div class="popItConG">'+
							'<div class="popItclose" onclick="popIt.remove()">Close</div>';
							
popIt.contents_headb = 		'<div class="popItT"></div> ' +     
							'<div class="popItLg"></div>'+
							'<div class="popItRg"></div>'+
							'<div class="popTl"></div>'+
							'<div class="popTr"></div>'+							
						'</div>'+
											
						'<div class="popItCon">';	   
						
popIt.contents_foot = 	    '<div class="popItHolder"></div>'+
							'<div class="popItB"></div>'+
							'<div class="popItL"></div>'+
							'<div class="popItR"></div>'+
							'<div class="popBr"></div>'+
							'<div class="popBl"></div> ' +     
						'</div>'+
					'</div>';
					
					
					
popIt.basicLoad = function(info, title, b)
{
	popIt.remove();//close any other boxes that are open
	var box = popIt.contents_head + title + popIt.contents_headb + popIt.contents_foot;
	$('body').prepend(box);
	$('.popItHolder').html(info);
	//set a custom width
	if(b)
	{
		$('.popItCon').css({width : b});
		$('.popItConG').css({width : b});	
		
	}
	popIt.position(true);//position
	
	
}					


var setTxt = function (obj, type) {
	setTxt.txt = $(obj).attr('txt');
	switch (type) {
	case "area":
		setTxt.otxt = $(obj).html();
		if (setTxt.otxt == setTxt.txt) {
			$(obj).html("");
		}
		break;
	case "box":
		setTxt.otxt = $(obj).val();
		if (setTxt.otxt == setTxt.txt) {
			$(obj).val("");
		}
		break;
	}
	$(obj).focusout(function () {
			setTxt.out(obj, type)
		});
}
setTxt.out = function (obj, type) {
	setTxt.txt = $(obj).attr('txt');
	switch (type) {
	case "area":
		setTxt.otxt = $(obj).html();
		if (setTxt.otxt == "") {
			$(obj).html(setTxt.txt);
		}
		break;
	case "box":
		setTxt.otxt = $(obj).val();
		if (setTxt.otxt == "") {
			$(obj).val(setTxt.txt);
		}
		break;
	}
	$(obj).focusout(function () {});
}



function contact_mail(a)
{
	var n = a.name.value;
	if(!n || n == "Name *"){$('.error').html('Your form is missing values');}
	
	var c = a.cell.value;
	
	var e = a.email.value;
	if(!e || n == "Email *"){$('.error').html('Your form is missing values');}
	
	var m = a.message.value
	if(!m || n == "Message ..."){$('.error').html('Your form is missing values');}
	
	
	var er = $('.error').html();
	if(!er)
	{
		$('.error').html('LOADING, Please wait ...');
		$.post("/includes/php/controls/mail.php", {n:n, c:c, e:e, m:m}, function (data) {			
					
					$('.popItHolder').html(data);
							
			});
	}
}













