Event.observe(window, 'load', function(){
	
	$$('.collapsible').each(function(collapsible){
		trigger = collapsible.down('dt');
		Event.observe(collapsible, 'click', function(collapsible){
			var cont = this.down('dd')
			cont.toggle();
		});
	});
	
	$$('.gallery').each(function(gallery){
		var primary = $(gallery.id+'_primary');
		var thumbs = gallery.getElementsBySelector('.gallery_thumb');
		thumbs.each(function(thumb){
			Event.observe(thumb, 'click', function(){new Effect.Opacity(primary, {to: 0.1, afterFinish: function(obj){primary.src = thumb.down('img').src; new Effect.Opacity(primary, {to: 1});}});  return false;}, false);
			thumb.onclick = function(){return false;}
		});
	});
	
	$$('.media_gallery').each(function(gallery){
		var primary = $('primary');
		var primary_details = $('primary_description');
		var download_link = $('download_link');
		var thumbs = gallery.getElementsBySelector('.thumb');
		thumbs.each(function(thumb){
			Event.observe(thumb, 'click', function(){
				new Effect.Opacity(primary, {to: 0.1, afterFinish: function(obj){primary.src = thumb.href; new Effect.Opacity(primary, {to: 1});}});  
				primary_details.innerHTML = thumb.title;
				download_link.href = thumb.href;
				return false;}
			, false);
			thumb.onclick = function(){return false;}
		});
	});
	
	// External Links
	$$('a').each(function(link) {
		if(link.href.indexOf('http://') != -1 && link.href.indexOf('burnaby') == -1){
			link.target = "_blank";
		}
	});
	
	$$(' #column_2 div:last-child').each(function(heading){
		heading.setStyle({borderBottom: 0});
	});
	
	$$('#column_1 div:last-child').each(function(heading){
		heading.setStyle({borderBottomWidth: "1px"});
	});
	
	$$('#column_2 h2').each(function(heading, index){
		if(index ==0){
		heading.addClassName('first-heading');
		}
	});
	
	$$('#column_1 .bodyimage:first-child').each(function(heading){
		heading.setStyle({marginTop: '8px'});
	});
	
	$$('#column_1 .bodyimage+h2').each(function(heading){
		heading.setStyle({borderTop: 0});
	});	
	
	$$('#column_2 div.clear+div.teaser').each(function(heading){
		heading.setStyle({borderBottom: 0});
    });

    Event.observe('searchButton', 'click', function (event) {
        window.top.location = 'http://www.tourismburnaby.com/search-results.htm?q=' + $('searchBox').value;
    });	
});


function isFF2Mac() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
    var ffversion = new Number(RegExp.$1);
    if (ffversion < 3 && userAgent.indexOf('mac') != -1) {
      return true;
    }
  }
}

function searchFocus() {
    if ($('searchBox').getValue() == "Enter your search") {
        $('searchBox').setValue("");
        $('searchBox').setStyle({
            color: "#000000",
            fontStyle: "normal"
        });
    }
}

function searchBlur() {
    if ($('searchBox').getValue() == "") {
        $('searchBox').setValue("Enter your search");
        $('searchBox').setStyle({
            color: "#CCCCCC",
            fontStyle: "italic"
        });
    }
}

function newsletterFocus() {
    if ($('newsletterTB').getValue() == "Enter your email") {
        $('newsletterTB').setValue("");
        $('newsletterTB').setStyle({
            color: "#000000",
            fontStyle: "normal"
        });
    }
}

function newsletterBlur() {
    if ($('newsletterTB').getValue() == "") {
        $('newsletterTB').setValue("Enter your email");
        $('newsletterTB').setStyle({
            color: "#CCCCCC",
            fontStyle: "italic"
        });
    }
}


