<!--//
//Various individual functions
var rndmImgs = new Array(
	"fade1",
	"fade2",
	"fade3",
	"fade4",
	"fade5",
	"fade6",
	"fade7"
);

var rndmImg = ".s-home #logo";

function goBack(){ history.back(); }

function lookingGlass() {this.location.href="/admin/";}

function openWin(link,w,h,s,t,u,m,r)  {
/****************      SETTINGS      *******************
		'w' =	width
		'h' = 	height
		's' = 	scrollbars - 'yes' or 'no' 
		't' = 	toolbar - 0 / 1
		'u' = 	status - 'yes' or 'no'
		'm' = 	menubar - 0 / 1
		'r' = 	resizeable - 'yes' or 'no'
		
		eg: <a href="javascript:popup2('link[URL]','width[px]','height[px]','scroll[yes/no]','tools[1/0]','status[yes/no]','menu[0/1]','resize[yes/no]');">link item</a>
*******************************************************/
	sH = ((screen.availHeight - h) / 2);
	sW = ((screen.availWidth - w) / 2);
	dummy2=window.open(link,"newindow","address=yes, toolbar="+t+",status="+u+",menuBar="+m+",scrollbars="+s+",resizable="+r+",width="+w+",height="+h+",left="+sW+",top="+sH+"");
}

function closeWin(){
	close();	
}

function post(){
	this.protocol = "mailto";
	this.hostname = "jon@randomprecision.co.uk";
//	this.location.href="mailto:jon@randomprecision.co.uk";
}

function randomValue(rndmImgs){
   return rndmImgs[Math.round(Math.random()*(rndmImgs.length-1))];
}

$.fn.addRandomClass = function (rndmImgs){
	return this.addClass(randomValue(rndmImgs));
};
//Start JQuery
$(document).ready(function() {

	$(rndmImg).addRandomClass(rndmImgs);

	$('.slideshow').cycle({ 
		fx:    		'scrollLeft', 
 	  	timeout: 	4000,  // milliseconds between slide transitions (0 to disable auto advance) 
    	speed:		1000,  // speed of the transition (any valid fx speed value) 
		cssBefore: {
			left: 0,
			top:  0
		},
		pause: 1
	});

	$('#show time').cycle({ 
		fx:    		'scrollLeft', 
 	  	timeout: 	4000,  // milliseconds between slide transitions (0 to disable auto advance) 
    	speed:		1000,  // speed of the transition (any valid fx speed value) 
		cssBefore: {
			left: 0,
			top:  0
		},
		pause: 1
	});

//Featured Build Switcher:
	$('.pSlideshow a').hoverIntent( function() {
			var container = "#" + $(this).parent().parent().parent().attr("id");
			var imgSrc = $(this).attr("href");
			$(container + ' .slideshow').cycle('pause');
			$(container + ' .slideshow .img1').attr("src", imgSrc );
			$(container + ' .slideshow').width(200).find('.img1').width(200).css("left",0);
			$(container + ' .slideshow').height(142).find('.img1').height(142).css("top",0);
		},
		function(){
			var container = "#" + $(this).parent().parent().parent().attr("id");
			var orgSrc = $(this).attr("rel");
			$(container + ' .slideshow').width(100).find('.img1').width(100).css("left",0);
			$(container + ' .slideshow').height(71).find('.img1').height(71).css("top",0);
			$(container + ' .slideshow .img1').attr("src", orgSrc );
			$(container + ' .slideshow').cycle('resume');
	});

//Portfolio thumbnail link list hover control
		$('.pThumbnail a').hoverIntent( function() {
			var imgSrc = $(this).attr("href");
			$(this).find('img').attr("src", imgSrc );
			$(this).find('img').width(200).css("left",-200);
			$(this).find('img').height(142).css("top",-142);
		},
		function(){
			var container = "#" + $(this).parent().parent().parent().attr("id");
			var orgSrc = $(this).attr("rel");
			$(this).find('img').width(100).css("left",0);
			$(this).find('img').height(71).css("top",0);
			$(this).find('img').attr("src", orgSrc );
	});

	
	$('.thumbLink').click( function() {
		return false;
	});
	
	$('#rabbithole').click( function() {
		lookingGlass();					 
		return false;
	});


//$(".s-contact option:odd").css("color", "#807571").css("background-color", "#000");
	

	$(".s-updates .updateLink").ajaxContent({
		loaderType:'img',
		loadingMsg:'/img/global/loadingAnimation.gif',
		target:'#fullArticle'
	});

	$("#geoData").find("dd#optNfo").hide().end().find("dt.trigger").click( function() {
		var box = $(this).next();
		if ( box.is(":visible")){
			$(this).find("a").text("[expand]");
			box.slideUp(100);
			return false;
		} else {
			$(this).find("a").text("[collapse]");
			box.slideDown(100);
			return false;
		}																	  
	});
	
	$("#login").find("dd#optLogin").hide().end().find("dt.trigger").click( function() {
		var box = $(this).next();
		if ( box.is(":visible")){
			$(this).find("a").text("[expand]");
			box.slideUp(100);
			return false;
		} else {
			$(this).find("a").text("[collapse]");
			box.slideDown(100);
			return false;
		}																	  
	});	
	
	$("#backBtn").click( function() { 
		goBack();
		return false;
	});

//Accordion Function for the Utility Navigation:
$('#utility').find('dd.secDesc').hide().end();

$('a.toggle').click(function() {
	$(this).parent('dt').next('dd').slideToggle(100).next('dd').show();
});

$('.s-portfolio .p-home #utility').find('dd.secDesc:first').show().end();
$('.s-portfolio .p-personal #utility').find('dd.secDesc:eq(1)').show().end();
$('.s-portfolio .p-digital #utility').find('dd.secDesc:last').show().end();
$('.s-portfolio .p-traditional #utility').find('dd.secDesc:last').show().end();


//Accordion Function for the Utility Navigation:
/*	$('#utility').find('dd.subsection').hide().end().find('dt.section').click(function() {
		var answer = $(this).next();
		if (answer.is(':visible')) {
//			$('dt.section').remove("- ");
			answer.slideUp(100);
			return false;
		} else {
//			$('dt.section').("- ");
			answer.slideDown(100);
			return false;
		}
	});
*/
//	$('#content').find('dd#structure').show().end();
//	$('#content').find('dt#struct').find('.ctrl').text("collapse").end()
/*
// Highlight Table Row on FloorPlans Page:
	$('.s-building .p-floor').find('tr').not('.first').hover(
	  function () {
		$(this).addClass("hover");
	  },
	  function () {
		$(this).removeClass("hover");
	  }
	);	

*/	
//Erase the dotted line around links
	$('a').click( function() { this.blur(); });
	$('a');
	
	$('#newPortSiteTitle').focus( function() {
		var currVal = $(this).val();
		currVal == "Project Title" ? $(this).val("") : $(this).val(currVal);					   
	});

	$('#newPortDescripion').focus( function() {
		var currVal = $(this).val();
		currVal == "Project Synopsis" ? $(this).val("") : $(this).val(currVal);					   
	});
	
	$('#newPortfolioSlides').click( function() {
		var currVal = $('#newPortSiteTitle').val();
		currVal != "Project Title" ? openWin($(this).attr("href") + '&t=' + currVal, '500','325','no',0,'no',0,'yes') : alert("You must enter a Project Title BEFORE you add new images.\n\nSorry for any inconvenience.");
//		openWin($(this).attr("href"), '500','200','no',0,'no',0,'yes');
		return false;
	});

	$('.styleswitch').click(function(){
		switchStylestyle(this.getAttribute("rel"));
		return false;
	});
	var c = readCookie('style');
	if (c) switchStylestyle(c);

    Shadowbox.init();


}); ///jquery

//Start jValidation
$().ready(function() {
	// validate signup form on keyup and submit
	$("#rpContactForm").validate({
		errorPlacement: function(error, element) {
			 	error.prependTo( element.parent() );
		},	 
		rules: {
			vTxtFirstName: "required",
			vTxtLastName: "required",
			vTxtEmail: {
				required: true,
				email: true
			},
			vTxtUserEnigma: {
					required: "#vTxtUserAlias:filled"
			},
			vTxtUserEnigChk: {
					required: "#vTxtUserEnigma:filled",
					equalTo: "#vTxtUserEnigma"
			},
			vNumMobile: {
					required: "#vRadPrefContMobile:checked"
			},
			vNumPhone: {
					required: "#vRadPrefContPhone:checked"
			},
			vMemoEnquiry: {
				required: true,
//				maxLength: 400,
				maxWords: 201 //Need to add one more to the count than actually needed as the script checks for spaces; think about it!
			},
			vTxtEnigma: "required"
		},
		messages: {
			vTxtFirstName: 		"Please enter your First Name &gt;&gt;&gt;",
			vTxtLastName: 		"Please enter your Last Name &gt;&gt;&gt;",
			vTxtEmail: 			"Please enter a valid Email Address &gt;&gt;&gt;",
			vTxtUserEnigma:	{
				required:		"Please provide a password &gt;&gt;&gt;"
			},
			vTxtUserEnigChk: {
				required: 		"Please provide the same password &gt;&gt;&gt;",
				equalTo: 		"Please enter the same password as above "
			},
			vNumMobile:			"Please enter your Mobile Number &gt;&gt;&gt;",
			vNumPhone:			"Please enter your Phone Number &gt;&gt;&gt;",
			vMemoEnquiry: {
				required: 		"Please provide an Enquiry &gt;&gt;&gt;",
				maxWords: 		"Your Enquiry must use<br />no more than 200 words &gt;&gt;&gt;"
			},
			vTxtEnigma:			"Please answer the control question &gt;&gt;&gt;"
		}
	});
});
///jValidation
//-->
