$(document).ready(function() {
	// Preload all rollovers
		$("#mainMenu img").each(function() {
			// Set the original src
			rollsrc = $(this).attr("src");
			rollON = rollsrc.replace(/.gif$/ig,"_over.gif");
			$("<img>").attr("src", rollON);
		});

        // Navigation rollovers
		$("#mainMenu a").mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			matches = imgsrc.match(/_over/);
			matchesOn = imgsrc.match(/_on/);

			// don't do the rollover if state is already ON
			if (!matches && !matchesOn) {
				imgsrcON = imgsrc.replace(/.gif$/ig,"_over.gif"); // strip off extension
				$(this).children("img").attr("src", imgsrcON);
			}

		});
		$("#mainMenu a").mouseout(function(){
			$(this).children("img").attr("src", imgsrc);
		});

    $(".slidetabs").tabs(".images > div", {
        // enable "cross-fading" effect
        effect: 'fade',
        fadeOutSpeed: 1000,
        fadeInSpeed: 1000,

        // start from the beginning after the last tab
        rotate: true

        // use the slideshow plugin. It accepts its own configuration
    }).slideshow( {
        autoplay: true,
        interval: 5000
    });

    $(".popup").colorbox({
        width:"890px",
        href:"/popup/ div#popup",
        overlayClose:true,
        close: "",
        transition:"none",
        opacity: 0.5
    });

    // note livequery here - this is because on the DOM changing on load so its needs
    // updating due to document.ready and jquery
    $("#popMenu a").livequery('click', function(event){
        $("#popMenu a img").each(function() {
            // Set the original src
            rollsrc = $(this).attr("src");
            rollON = rollsrc.replace(/_hover.gif$/ig,".gif");
            rollON = rollsrc.replace(/_on.gif$/ig,".gif");
            $(this).attr("src", rollON);
        });

        imgsrc = $(this).children("img").attr("src");
        imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif"); // strip off extension
        $(this).children("img").attr("src", imgsrcON);

        // write script to pull correct div
        $("#pops div.popRightHolder").each(function() {
            id = $(this).hide();
        });

        showid = $(this).children("img").attr("id");
        $('#' + showid + '_pop').show();
        return false;
    });

    $(".testflick1").livequery('click', function(event){
        $(".test1").hide();
        $(".test2").show();
    });

    $(".testflick2").livequery('click', function(event){
        $(".test2").hide();
        $(".test1").show();
    });
    
    $(".closePop").livequery('click', function(event){
        $(".popup").colorbox.close();
    });

    // end of popups
});

function href( url )
{
	document.location.href= url;
}


function validate_form ( )
{
    valid = true;
    if ( document.callback.title.value == "" )
    {
        alert ( "Please Enter your Title." );
        valid = false;
        return valid;
    }

    if ( document.callback.forename.value == "" )
    {
        alert ( "Please Enter your Forename." );
        valid = false;
        return valid;
    }

    if ( document.callback.surname.value == "" )
    {
        alert ( "Please Enter your Surname." );
        valid = false;
        return valid;
    }

    if ( document.callback.callDate.value == "" )
    {
        alert ( "Please Enter a Call Back Date." );
        valid = false;
        return valid;
    }
    if ( document.callback.callTime.value == "" )
    {
        alert ( "Please Enter a Call Back Time." );
        valid = false;
        return valid;
    }
    return valid;
}

function validate_form_feedback ( )
{
    valid = true;
    if ( document.customerFeedback.title.value == "" )
    {
        alert ( "Please Enter your Title." );
        valid = false;
        return valid;
    }

    if ( document.customerFeedback.forename.value == "" )
    {
        alert ( "Please Enter your Forename." );
        valid = false;
        return valid;
    }

    if ( document.customerFeedback.surname.value == "" )
    {
        alert ( "Please Enter your Surname." );
        valid = false;
        return valid;
    }

    if ( document.customerFeedback.tel.value == "" )
    {
        alert ( "Please Enter your Telephone Number ( Inc area code )" );
        valid = false;
        return valid;
    }
    if ( document.customerFeedback.regNum.value == "" )
    {
        alert ( "Please Enter your Registration Number." );
        valid = false;
        return valid;
    }
    if ( document.customerFeedback.recieptNum.value == "" )
    {
        alert ( "Please Enter your Reciept Number." );
        valid = false;
        return valid;
    }
    return valid;
}

function popMap() {
window.open( "/map.html", "map", "status = 1, height = 620, width = 620, resizable = 0" )
}