/***********************************************
* jQuery functions execute
***********************************************/

$(document).ready(function() {
					//check that the characters entered only contain alphanumeric characters
					$("input[@name=SameAsAbove]").click(toggleShippingSameAs)

					function toggleShippingSameAs() {
						//for the delivery type
						if ( $("input[@name=SameAsAbove]:checked").val() == 1 ) {
							copyValue()
						} else {
							clearValue()
						}
					}

					function copyValue() {
						$('input.copy-value').each(function () {
							$("input[name!=" + $(this).attr("name") + "][name*=" + $(this).attr("name") + "].paste-value").val($(this).val())
						});
					}

					function clearValue() {
						$('input.paste-value').each(function () {
							$(this).val("")
						});
					}

					/* Handles clicking on a ul and the link working */
					$('ul.link-block').click(function() {
							var link = $(this).find("a.link-block").attr("href")
							if ( link != undefined && link != '' ) {
								location.href = link
							}
					});
					
               /*cmx form */
					if(jQuery.browser.mozilla) {
                                $('form.cmxform').hide().find('label:not(.nocmx)').each(function(){
                                                var $labelContent = $(this).html();
                                                var $labelWidth = $(this).css('width');
                                                $(this).empty();
                                                $(this).append('<span style="display: block; width: '+$labelWidth+';">');
                                                $(this).prepend('</span>');
                                                $(this).css('display', '-moz-inline-box');
                                                $(this).find('span').html($labelContent);
                                                $('form.cmxform').show();
                                });
                };             


					/*external link*/
					$('a[@rel$="external"]').click(function(){this.target = "_blank";});
					/*thickbox opacity*/	
					$('.thickbox').click(function() {$('.TB_overlayBG').css('opacity', '0.75');});
					
					/*email protect*/
					$("span.safemail").each(function(){
						exp = $(this).text().search(/\((.*?)\)/) != -1 ? new RegExp(/(.*?) \((.*?)\)/) : new RegExp(/.*/);
						match = exp.exec($(this).text());
						addr = match[1] ? match[1].replace(/ at /,"@").replace(/ dot /g,".") : match[0].replace(/ at /,"@").replace(/ dot /g,".");
						link = match[2] ? match[2] : addr;
						subject = $(this).attr('title') ? "?subject="+$(this).attr('title').replace(/ /g,"%20") : "";
						$(this).after('<a href="mailto:'+addr+subject+'">'+ link + '</a>');
						$(this).remove();
					});

					/*on focus for input boxes*/
					$.fn.search = function() {
							return this.focus(function() {if( this.value == this.defaultValue ) {this.value = "";}
							}).blur(function() {
							if( !this.value.length ) {this.value = this.defaultValue;}});
						};
					  $("input.searchbox").search();
					  $("input.mailing").search();
					  $("input.loginbox").search();
					
										
					/*set hover class for :hover for ie6*/
					  /*dropdown fix*/
						$('ul#catalogue-nav li').hover(function() {$(this).addClass('nav-hover');}, function() {$(this).removeClass('nav-hover');});
						$('ul#catalogue-nav ul').hover(function() {$('.nav-hover').addClass('onsection');}, function() {$('nav-hover').removeClass('onsection');});
					  /*ie6 fix for :hover*/
					  $('a.send').hover(function() {$(this).addClass('hover');}, function() {$(this).removeClass('hover');});
					  $('input.send').css('cursor', 'pointer').hover(function() {$(this).addClass('sendhover');}, function() {$(this).removeClass('sendhover');});
					  $('input.searchnow').css('cursor', 'pointer').hover(function() {$(this).addClass('searchnowhover');}, function() {$(this).removeClass('searchnowhover');});
					   $('input.go').css('cursor', 'pointer').hover(function() {$(this).addClass('gohover');}, function() {$(this).removeClass('gohover');});
						$('input.loginnow').css('cursor', 'pointer').hover(function() {$(this).addClass('loginnowhover');}, function() {$(this).removeClass('loginnowhover');});
						$('input.logoutnow').css('cursor', 'pointer').hover(function() {$(this).addClass('logoutnowhover');}, function() {$(this).removeClass('logoutnowhover');});
						$('input.add').css('cursor', 'pointer').hover(function() {$(this).addClass('addhover');}, function() {$(this).removeClass('addhover');});
						$('input.more').css('cursor', 'pointer').hover(function() {$(this).addClass('morehover');}, function() {$(this).removeClass('morehover');});
						$('input.enquire').css('cursor', 'pointer').hover(function() {$(this).addClass('enquirehover');}, function() {$(this).removeClass('enquirehover');});
						// highlight news listing box on hover
						$('.news-box').css('cursor', 'pointer').hover(function(){$(this).addClass("over");}, function(){$(this).removeClass("over");});

});


/* Overriding Javascript's Confirm Dialog using simpleModal.js */

$(document).ready(function () {
	$('.confirm').click(function (e) {
		e.preventDefault();
			$('#login-alert').modal({
				close: false,
				overlayId: 'confirmModalOverlay',
				containerId: 'confirmModalContainer',
    			onOpen: function (dialog) {
					dialog.overlay.fadeIn(300, function () {
					dialog.container.fadeIn(300, function () {
					dialog.data.fadeIn(200);
				});
			});
			},
				onShow: function (dialog) {
					dialog.data.find('.message');
			},
				onClose: function (dialog) {
					dialog.data.fadeOut(200, function () {
					dialog.container.fadeOut(300, function () {
					dialog.overlay.fadeIn(300, function () {
					$.modal.close();
					});
				});
			 });
			}
		});
	});	
	
	$('.confirm1').click(function (e) {
		e.preventDefault();
			$('#privacy').modal({
				close: false,
				overlayId: 'confirmModalOverlay',
				containerId: 'confirmModalContainer',
    			onOpen: function (dialog) {
					dialog.overlay.fadeIn(300, function () {
					dialog.container.fadeIn(300, function () {
					dialog.data.fadeIn(200);
				});
			});
			},
				onShow: function (dialog) {
					dialog.data.find('.message');
			},
				onClose: function (dialog) {
					dialog.data.fadeOut(200, function () {
					dialog.container.fadeOut(300, function () {
					dialog.overlay.fadeIn(300, function () {
					$.modal.close();
					});
				});
			 });
			}
		});
	});	
	
	$('.confirm2').click(function (e) {
		e.preventDefault();
			$('#terms').modal({
				close: false,
				overlayId: 'confirmModalOverlay',
				containerId: 'confirmModalContainer',
    			onOpen: function (dialog) {
					dialog.overlay.fadeIn(300, function () {
					dialog.container.fadeIn(300, function () {
					dialog.data.fadeIn(200);
				});
			});
			},
				onShow: function (dialog) {
					dialog.data.find('.message');
			},
				onClose: function (dialog) {
					dialog.data.fadeOut(200, function () {
					dialog.container.fadeOut(300, function () {
					dialog.overlay.fadeIn(300, function () {
					$.modal.close();
					});
				});
			 });
			}
		});
	});	

});



/***********************************************
* Safe email links - hide Email To field
***********************************************/

function hide_EmailForm() {
	var s1 = 'info';
	var s2 = '@';
	var s3 = 'capsaust.com.au';
	document.write('<input type="hidden" name="Em' + 'ail_To" value="' + s1 + s2 + s3 + '" />');
}

/***********************************************
* ShowandHide Script - if not using jquery
***********************************************/

//<!--
function viewinfos(id) {
	box = document.getElementById(id);
	if(box.className == "visible") {
		box.className = "hidden";
	} else {
		box.className = "visible";
	}
}
//-->


