

var TPC = function() {
	var rootFolder = '',
		$ = jQuery, //incase we fall into no conflict mode
		
		//lightbox images
		lightBoxRoot = rootFolder + '/a/i/lightbox',
		lbImageLoading = lightBoxRoot + '/lightbox-ico-loading.gif',	// (string) Path and the name of the loading icon
		lbImageBtnPrev = lightBoxRoot + '/lightbox-btn-prev.gif',		// (string) Path and the name of the prev button image
		lbImageBtnNext = lightBoxRoot + '/lightbox-btn-next.gif',	// (string) Path and the name of the next button image
		lbImageBtnClose = lightBoxRoot + '/lightbox-btn-close.gif',	// (string) Path and the name of the close btn
		lbImageBlank = lightBoxRoot + '/lightbox-blank.gif',		// (string) Path and the name of a blank image 		
		
		body, //needs to be set on init
		pwcc = PWCC,
		win = window,
		doc = document,
		nav = navigator;
		
	var init = function(){
	
		$(function() {
			body = $('body');
			//dom ready
			if (body.attr('id') == 'home') {
				//on home page
				$('#show-1').click(function(){
					win.location = './cfy/';
				}).css('cursor','pointer');
				
				$('#show-2').click(function(){
					win.location = './tbf/';
				}).css('cursor','pointer');
				
				$('#show-3').click(function(){
					win.location = './drs/';
				}).css('cursor','pointer');
			}
			else if (body.hasClass('wordpress') == true) {
				$('.cat-links  li:first-child, .tag-links  li:first-child').addClass('first-child');
			}
			else {
				//not on home page or in blog
				resizeEvent();
				$(win).resize(resizeEvent); //add to resize event.
			}
			
			//all pages
			$('body#mailinglist form').submit(checkMailingListForm);
			
			$('a.popup').click(popupCall);
			
			if (body.attr('id') == 'sub-prices') {
				$('a.lb').lightBox({
					fixedNavigation:true,
					imageLoading:	lbImageLoading,
					imageBtnPrev:	lbImageBtnPrev,
					imageBtnNext:	lbImageBtnNext,
					imageBtnClose:	lbImageBtnClose,
					imageBlank:		lbImageBlank
				});
			}
			if (body.attr('id') == 'gallery') {	
				$('#content-a a').lightBox({
					imageLoading:	lbImageLoading,
					imageBtnPrev:	lbImageBtnPrev,
					imageBtnNext:	lbImageBtnNext,
					imageBtnClose:	lbImageBtnClose,
					imageBlank:		lbImageBlank
				});
			}

		});
		
		$(win).ready(function() {
			//window ready/images loaded
			if (body.attr('id') == 'home') {
				//on home page
				$('#show-1 .countdown').flash({
					src: rootFolder + '/a/f/crazy.swf',
					wmode: 'transparent',
					width: 180,
					height: 75
				});
				$('#show-2 .countdown').flash({
					src: rootFolder + '/a/f/boyfriend.swf',
					wmode: 'transparent',
					width: 180,
					height: 75
				});
				$('#show-3 .countdown').flash({
					src: rootFolder + '/a/f/drs.swf',
					wmode: 'transparent',
					width: 180,
					height: 75
				});
			}
			else {
				//not on home page
			}
		});
	
	}(); //() autoruns





	var resizeEvent = function () {
		var viewportHeight = $(win).height();
		if (viewportHeight >= 635) {
			var setFooterHeight = viewportHeight - 635;
			pwcc.createStyleRule ('#container', 'padding-bottom: ' + setFooterHeight + 'px;', 'all');
			pwcc.createStyleRule ('#footer', 'height: ' + setFooterHeight + 'px; position: fixed; top: 635px;', 'all');
			pwcc.createStyleRule ('#content', 'background-position: 50% 618px; background-attachment: fixed;', 'all');
			body.removeClass('shortPort show-shortPort'); /* show-shortPort for ie6 */
		}
		else {
			body.addClass('shortPort');
			if (body.hasClass('show')){
				body.addClass('show-shortPort'); /* for ie6 */
			}
		}
	}


	var popupCall = function(event) {
		var classes = $(this).attr('class').split(' ');
		var width = null, 
			height = null;
		for (var i = 0; i<classes.length; i++) {
			var wh = classes[i].split('-');
			if (wh.length == 2 && isNumber(wh[1])) {
				if (wh[0] == 'width') {
					width = wh[1];
				}
				else if (wh[0] == 'height') {
					height = wh[1];
				}
			}
		}
		var popupResult = popup(this.href, width, height);
		if (popupResult == true) {
			event.preventDefault();
		}
	}

	var isNumber = function(numQ) {
		return !isNaN(numQ);
	}


	var popup = function(url,width,height,windowId,showScroll,showLocation,showToolbar,showStatus,allowResize) {
		if (!url) {
			url = "/";
		}
		if (!width) {
			width = 500;
		}
		if (!height) {
			height = 320;

		}
		if (!windowId) {
			windowId = "PopupWindow";
		}
		if (!showScroll) {
			showScroll = "yes";
		}
		if (!showLocation) {
			showLocation = "no";
		}
		if (!showToolbar) {
			showToolbar = "no";
		}
		if (!showStatus) {
			showStatus = "no";
		}
		if (!allowResize) {
			allowResize = "yes";
		}
		var idPopup = win.open(url,windowId,"width="+width+",height="+height+",scrollbars="+showScroll+",location="+showLocation+",toolbar="+showToolbar+",status="+showStatus+",resizable="+allowResize);
		return true;
	}
	
	
	var checkMailingListForm = function(event) {
		var focused = false,
			name = $('#name'),
			address = $('#address'),
			suburb = $('#suburb'),
			state = $('#state'),
			postcode = $('#postcode'),
			phone = $('#phone');
			email = $('#email');
			
			if ( name.val() == '' ) {
				$('#nameerrormsg').html('<strong style="color: #f00;">Please enter your name.</strong>');
				name.focus();
				focused = true;
				event.preventDefault();
			}
			else {
				$('#nameerrormsg').html('*');
			}
			
			if ( address.val() == '' ) {
				$('#addresserrormsg').html('<strong style="color: #f00;">Please enter your address.</strong>');
				if (focused == false) {
					address.focus();
					focused = true;
				}
				event.preventDefault();
			}
			else {
				$('#addresserrormsg').html('*');
			}
			
			if ( suburb.val() == '' ) {
				$('#suburberrormsg').html('<strong style="color: #f00;">Please enter your suburb.</strong>');
				if (focused == false) {
					suburb.focus();
					focused = true;
				}
				event.preventDefault();
			}
			else {
				$('#suburberrormsg').html('*');
			}
			
			if ( state.val() == '' ) {
				$('#stateerrormsg').html('<strong style="color: #f00;">Please enter your state.</strong>');
				if (focused == false) {
					state.focus();
					focused = true;
				}
				event.preventDefault();
			}
			else {
				$('#stateerrormsg').html('*');
			}
			
			if ( postcode.val() == '' ) {
				$('#postcodeerrormsg').html('<strong style="color: #f00;">Please enter your postcode.</strong>');
				if (focused == false) {
					postcode.focus();
					focused = true;
				}
				event.preventDefault();
			}
			else {
				$('#postcodeerrormsg').html('*');
			}
			
			if ( phone.val() == '' ) {
				$('#phoneerrormsg').html('<strong style="color: #f00;">Please enter your ph number.</strong>');
				if (focused == false) {
					phone.focus();
					focused = true;
				}
				event.preventDefault();
			}
			else {
				$('#phoneerrormsg').html('*');
			}
			return;
	}

	
}(); //() autoruns


	/* **************************************************
		Previous developers code moved into namespace
		*** move to event if time
	************************************************** */
/*
PWCC.checkForm = function () {

	// BELOW ARE THE VARIABLES FOR EACH FIELD IN THE FORM
	
	var name = document.getElementById("name");
	var address = document.getElementById("address");
	var suburb = document.getElementById("suburb");
	var state = document.getElementById("state");
	var	postcode = document.getElementById("postcode");
	var	phone = document.getElementById("phone");
	var	email = document.getElementById("email");
	
	//BELOW MAKES SURE THE NAME FIELDS ARE OCCUPIED WITH TEXT.
		  
	if (name.value == "") {
		document.getElementById("nameerrormsg").style.display="inline"; 
		$('#nameerrormsg').html('<strong style="color: #f00;">Please enter your name.</strong>');
		name.focus(); return false;
	}
	else {
		document.getElementById("nameerrormsg").style.display="none";
		$('#nameerrormsg').html(' ');
	}

	// POSTAL ADDRESS - Makes sure the fields are occupied.
	if (address.value == "") {
		document.getElementById("addresserrormsg").style.display="inline"; 
		$('#addresserrormsg').html('<strong style="color: #f00;">Please enter your address.</strong>');
		address.focus(); return false;
	}
	else {
		document.getElementById("addresserrormsg").style.display="none";
	}
	
	// SUBURB- Makes sure the fields are occupied.
	if (suburb.value == "") {
		document.getElementById("suburberrormsg").style.display="inline"; 
		$('#suburberrormsg').html('<strong style="color: #f00;">Please enter your suburb.</strong>');
		suburb.focus(); return false;
	}
	else {
		document.getElementById("suburberrormsg").style.display="none";
	}
	
	// STATE- Makes sure the fields are occupied.
	if (state.value == "") {
		document.getElementById("stateerrormsg").style.display="inline"; 
		$('#stateerrormsg').html('<strong style="color: #f00;">Please select your state.</strong>');
		state.focus();
		return false;
	}
	else {
		document.getElementById("stateerrormsg").style.display="none";
	}
	
	// POSTCODE- Makes sure the fields are occupied.
	if (postcode.value == "") {
		document.getElementById("postcodeerrormsg").style.display="inline"; 
		$('#postcodeerrormsg').html('<strong style="color: #f00;">Please enter your post code.</strong>');
		postcode.focus(); return false;
	}
	else {
		document.getElementById("postcodeerrormsg").style.display="none";
	}
	
	// PHONE FIELD - Makes sure the fields are occupied.
	if (phone.value == "") {
		document.getElementById("phoneerrormsg").style.display="inline"; 
		$('#phoneerrormsg').html('<strong style="color: #f00;">Please enter your ph number.</strong>');
		phone.focus(); return false;
	}
	else {
		document.getElementById("phoneerrormsg").style.display="none";
	}
}
*/


	
	
	
/* compact forms
   credit due: Making Compact Forms More Accessible by Mike Brittain (A List Apart)
   http://www.alistapart.com/articles/makingcompactformsmoreaccessible
*/

/*
PWCC.showHideOverLabel = function(label,input) {
	var inputValue = input.attr('value');
	if (inputValue && inputValue != '')  {
		label.addClass('active');
	}
	else {
		label.removeClass('active');
	}
	return;
}


$(function() {
	$('form div.overlabel').each(function() {
		var div = $(this),
			winLoad = $(window);
		div.addClass('overlabel-apply');
		div.find('label').each(function() {
			var label = $(this);
			var isFor = label.attr('for');
			if (isFor) {
				var input = $('#' + isFor);
				//initialise, waiting for browser set values
				winLoad.ready(function(){
					setTimeout(function(){
						PWCC.showHideOverLabel(label,input)
					},50); 
				});
				input.focus(function() {
					label.addClass('active');
				});
				input.blur(function(){PWCC.showHideOverLabel(label,input)});
			}
		});
	});
});

*/

