// JavaScript Document
	
var runFlash;
var openLightbox;
var openVideoLightbox;
		
jQuery.noConflict();
jQuery(function($){
	
	formValid = 'none';
	
	$(document).ready(function(){
		
		var ie6 = false;
		if($.browser.version && $.browser.version <= 6){
		   ie6 = true;
		};
		
		// open lightbox when called from flash
		openLightbox = function OL(u){
			$('.mod_photoGallery .lb').attr('href',u).click();
		}
		
		// open lightbox when called from flash
		openVideoLightbox = function OL(u){
			$('.mod_photoGallery .lb').attr('href',u).click();
		}
		
										
		//FS.run = runFlash;
		
		//FS.run = 
		runFlash = function (i,t){
			var $f = $(t);
			var ID = $f.attr('id');
			if(!ID.length){
				ID = 'flashID'+i; 
				$f.attr('id',ID)
			}
			
			var findFlashvar = $f.find('input[name=flashvars]').attr('value');
			var swf = $f.find('input[name=flashFile]').attr('value');
			var s = $f.find('input[name=flashSize]').attr('value').split('&');
			
			var params = {
				flashvars: findFlashvar,
				allowFullScreen: 'true',
				allowScriptAccess: 'sameDomain',
				wmode: "transparent" // a common request to make the 
			};
			
			var attributes = {};
			
			// get sizes
			var w = 570; // default width
			var h = 432; // default height
			for (var i=s.length; i--;){
				if(s[i].match('w') || s[i].match('W')){
					w = parseInt(s[0].slice(2,s[0].length))
				} else if(s[i].match('h') || s[i].match('H')){
					h = parseInt(s[1].slice(2,s[0].length))
				}
			}
			
			//load flash
			swfobject.embedSWF(swf, ID, w, h, "9.0.0", "/assets/f/expressInstall.swf", findFlashvar, params, attributes);			
		}
		
		// flash videos
		$('.flashHolder').each(function(i){
			runFlash(i, this)
		})



		// activate module TABS
		if($('.tabbed').length){
			$('.tabbed a').click(function(e){
				e.preventDefault();
				if(!$(this).parent().hasClass('on')){
					$(this).parent().siblings('.on').removeClass('on')
					
					$(this).parent().addClass('on')
					$(this).parent().next('.modInner').addClass('on')
				}
			});
		};

		// lightboxes
		if($('.lb').length){
			$('.lb').ATlightbox();
		};
		
		
		// Accessibility
		// Reset Font Size
		var originalFontSize = 10;
		var currentFont;
		
		$('#fontRS a').click(function(){
		    var that = $(this);
		    var multiply = 1;
		    
		    if(that.parent('li').attr('id') === 'fsMed'){
		        multiply = 1
		    }else if(that.parent('li').attr('id') === 'fsSml'){
		        multiply = 0.8
		    }else if(that.parent('li').attr('id') === 'fsLrg'){
		        multiply = 1.2
		    };
		    
		    $('#fontRS a.on').removeClass('on');
		    that.addClass('on');
		    $('body').css('font-size', originalFontSize*multiply);
			
		});
		
		
		
		// add hover to submit buttons
		$('input[type=submit]').bind("mouseenter", function(e){
        	$(this).addClass("hover");
			$(this).siblings('span.icon').addClass("hover")
    	}).bind("mouseleave", function(e){
        	$(this).removeClass("hover");
			$(this).siblings('span.icon').removeClass("hover")
    	});
		
		
		// form posts - detect next submit button
		var curSubmit;
		$('input[type=text], textarea, select').focus(function(){
			curSubmit = $(this).parents('fieldset').find('input[type=submit]:first');
		});
		
		$().keydown(function(e){
			if(e.keyCode === 13 && $(curSubmit).length){
				$(curSubmit)[0].click()
				return false
			};
		});
		
		
		if($('fieldset:visible').length && ie6 === false){
			$('fieldset:visible').ATform();
		};
				
		
		/*
		// form posts - ajax call on form
		$('input[type=submit]').live("click",function(e){
			e.preventDefault();
			var field = $(this).closest('fieldset');
			var content = ('#'+field.attr('id'));
			var form = $('form:first');
			
			var method = form.attr('method');
			var action = form.attr('action');
			var serializedFrom = form.serialize()+'&'+$(this).attr('name')+'='+method;
			
			$.ajax({
				type: method,
				url: action,
				data: serializedFrom,
				success: function(html){
					var newHTML = $(html).find(content);
					var $lb = $('#lb');
					$(content).replaceWith(newHTML)
					$(content).append('<p>form completed and returned</p>')
				}
			})		
		});
		*/
		
		
		// Added by KHH
	    // add a "rel" attrib if Opera 7+
	    if(window.opera) {
		    if ($("a.jqbookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
			    $("a.jqbookmark").attr("rel","sidebar");
		    }
	    }

	    $("a.jqbookmark").click(function(event){
		    event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		    var url = this.href;
		    var title = this.title;

		    if (window.sidebar) { // Mozilla Firefox Bookmark
			    window.sidebar.addPanel(title, url,"");
		    } else if( window.external ) { // IE Favorite
			    window.external.AddFavorite( url, title);
		    } else if(window.opera) { // Opera 7+
			    return false; // do nothing - the rel="sidebar" should do the trick
		    } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			     alert('Unfortunately, this browser does not support the requested action,'
			     + ' please bookmark this page manually.');
		    }

	    });

	}) // END doc.ready	
}); // END $ function
