// JavaScript Document
if (document.images) {
    homebuttonup       = new Image();
    homebuttonup.src   = "img/home.png" ;
    homebuttondown     = new Image() ;
    homebuttondown.src = "img/homeP.png" ;

    appbuttonup       = new Image();
    appbuttonup.src   = "img/app.png" ;
    appbuttondown     = new Image() ;
    appbuttondown.src = "img/appP.png" ;
	
	orderbuttonup       = new Image();
    orderbuttonup.src   = "img/order.png" ;
    orderbuttondown     = new Image() ;
    orderbuttondown.src = "img/orderP.png" ;
	
	orderbuttonup       = new Image();
    orderbuttonup.src   = "img/order.png" ;
    orderbuttondown     = new Image() ;
    orderbuttondown.src = "img/orderP.png" ;
	
	order2buttonup       = new Image();
    order2buttonup.src   = "img/order2.png" ;
    order2buttondown     = new Image() ;
    order2buttondown.src = "img/orderP2.png" ;
	
	aboutusbuttonup       = new Image();
    aboutusbuttonup.src   = "img/aboutus.png" ;
    aboutusbuttondown     = new Image() ;
    aboutusbuttondown.src = "img/aboutusP.png" ;
	
	contactbuttonup       = new Image();
    contactbuttonup.src   = "img/contact.png" ;
    contactbuttondown     = new Image() ;
    contactbuttondown.src = "img/contactP.png" ;
}
function buttondown( buttonname )
{
    if (document.images) {
      document[ buttonname ].src = eval( buttonname + "down.src" );
    }
}
function buttonup ( buttonname )
{
    if (document.images) {
      document[ buttonname ].src = eval( buttonname + "up.src" );
    }
}

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');
	
	//For future ref.: Uncomment these 3 lines for random mode!
	//var $sibs  = $active.siblings();
    //var rndNum = Math.floor(Math.random() * $sibs.length );
   	//var $next  = $( $sibs[ rndNum ] );
	
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2500, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 4000 );
});

var gal = {
		init : function() {
			if (!document.getElementById || !document.createElement || !document.appendChild) return false;
			if (document.getElementById('gallery')) document.getElementById('gallery').id = 'jgal';
			
			var li = document.getElementById('jgal').getElementsByTagName('li');
			
				li[0].className = 'active';
			for (i=0; i<li.length; i++) {
				li[i].style.backgroundImage = 'url(' + li[i].getElementsByTagName('img')[0].src + ')';
				li[i].title = li[i].getElementsByTagName('img')[0].alt;
			gal.addEvent(li[i],'click',function() {
			
				var im = document.getElementById('jgal').getElementsByTagName('li');
					for (j=0; j<im.length; j++) {
					im[j].className = '';
				}
				this.className = 'active';
			});
		}
	},
	addEvent : function(obj, type, fn) {
		if (obj.addEventListener) {
			obj.addEventListener(type, fn, false);
		}
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
}
	gal.addEvent(window,'load', function() {
		gal.init();
});

function newPopup(url) {
	popupWindow = window.open(
		url,'popUpWindow','height=414,width=542,top=300px,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=yes')
}

function initialize() {
    var myLatlng = new google.maps.LatLng(43.65198,-79.390412);
    var myOptions = {
      zoom: 15,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
    var marker = new google.maps.Marker({
        position: myLatlng, 
        map: map,
        title:"qp925: DESIGN. INSPIRED."
    });   
}

function validate_form ( )
{
	valid = true;

        if ( document.contact_form.CustName.value == "" )
        {
                alert ( "Please fill in the 'Name' box." );
                valid = false;
        }
		
		if ( document.contact_form.CustEmail.value == "" )
        {
                alert ( "Please fill in the 'Email' box." );
                valid = false;
        }

        return valid;
}
