// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

/*
 * Casarotto Scripts
 *
 * Author: Lachlan Laycock (kennedia.com)
 * Date: 31 Oct 2006
 *
 *====================================*/

//
// Helper Functions
//
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

//
// Colossus Specific Functions and Helpers
//
var Casarotto = Class.create(); 
Casarotto = {
	
	banners : $H({
		marsh: '/images/casarotto_marsh_banner.gif',
		ramsay: '/images/casarotto_ramsay_banner.gif'
	}),

	setBanner : function(group_name) {
		$('banner').src = this.banners.get(group_name);
		
		// Set Print banner
		if (group_name == "ramsay") {
			$('print_banner_marsh').hide();
			$('print_banner_ramsay').show();
		} else if (group_name == "marsh") {
			$('print_banner_marsh').show();
			$('print_banner_ramsay').hide();
			}
	},
	
	splash_page : function(event) {
		new Effect.Appear($('intro'), {duration: 6});
	},
	
	toggle_categories_scroll : function() {
		dom_height = $('header').getDimensions().height
		+$('categories_marsh').getDimensions().height
		+$('categories_ramsay').getDimensions().height
		+$('footer').getDimensions().height;
		window_height = window.innerHeight;
		if (window_height < dom_height) {
			$('client_categories').setStyle({position: "absolute"});
			$('client_categories').setStyle({display: "block"});
		}
	},
	
	toggle_clients : function(group) {
		cat_ramsay = $("categories_ramsay");
		cat_marsh = $("categories_marsh");

		tgl_ramsay = $("toggle_ramsay");
		tgl_marsh = $("toggle_marsh");
		
		if (group == "ramsay") {
			cat_marsh.hide();
			cat_ramsay.show();
		}

		if (group == "marsh") {
			cat_ramsay.hide();
			cat_marsh.show();
		}
	},
	
	alphabet_scroll_to : function(origin, target) {
		if ($(target)) {
			if ((version >= 5.5) && (document.body.filters)) {
				window.location = origin.href
			} else {
				new Effect.ScrollTo(target, {offset: -190});
			}
		}
	},

	client_scroll_to : function(origin, target) {
		target = 'client_details';
		if ($(target)) {
			if ((version >= 5.5) && (document.body.filters)) {
				new Effect.ScrollTo(target);
			}
		}
	},
	
	client_select : function(link) {
		$$('#category_clients ul li a').each(function(a){
			a.className = '';
		});
		link.className = 'selected';
	},

	category_select : function(link, group) {
		$$('ul.categories_list li a').each(function(a){
			a.className = '';
		});
		link.className = 'selected';
		
		$$('div.group_title').each(function(a){
			a.className = 'group_title';
		});
		
		if (group == 'ramsay') {
			$$('div.group_title').first().className = 'group_title selected'
		} else if (group == 'marsh') {
				$$('div.group_title').last().className = 'group_title selected'
			}
	},
	
	setCategoriesPositions : function() {
		// If bottom is below the fold then make absolute to force scroll bars if not IE as IE is always absolute
		elem = $('client_categories');
		if (elem && !Prototype.Browser.IE) {
			if (document.viewport.getDimensions().height < (elem.viewportOffset().top+elem.getDimensions().height)) {
				elem.setStyle({position: 'absolute', left: '27px', top: '0px'})
				elem.up().setStyle({width: '100%'}) // Fix layout bug in Safari
			}
		}
	}
};

// Apply Rules onload event
document.observe("dom:loaded", function() {
	Casarotto.setCategoriesPositions()
})

