/*
 * hrefID jQuery extention - returns a valid #hash string from link href attribute in Internet Explorer
 */
(function($){$.fn.extend({hrefId:function(){return $(this).attr('href').substr($(this).attr('href').indexOf('#'));}});})(jQuery);

/*
 * Scripts
 *
 */
jQuery(function($) {
 
	var Engine = {
		utils : {
			links : function(){
				$('a[rel*=external]').click(function(e){
					e.preventDefault();
					window.open($(this).attr('href'));						  
				});
			},
			mails : function(){
				$('a[href^=mailto:]').each(function(){
					var mail = $(this).attr('href').replace('mailto:','');
					var replaced = mail.replace('/at/','@');
					$(this).attr('href','mailto:'+replaced);
					if($(this).text() == mail) {
						$(this).text(replaced);
					}
				});
			},
			qa : function() {
				$("div.collapse h3").each( function () {
					$(this).next().hide();
					$(this).next().append('<p><a href="#" onclick="$(this).closest(\'div\').prev(\'h3\').removeClass(\'active\'); $(this).closest(\'div\').slideUp(\'fast\'); return false;">Hide Answer</a></p>');
				});
				
				$("div.collapse h3").click( function () {
					$(this).toggleClass('active');
					$(this).next().slideToggle('fast');
					return false;
				});
			},
			contactvalidate : function() {
				$("#contactform").each(function(){
						$(this).validate();							
				});
			},
			contactprefill : function() {
				var Hash = window.location.hash;
				if( Hash != '' ) {
					Hash = Hash.substr(1).split('_').join(' ');
					$('#Request_Type').val(Hash);
				}
			},
			homebanner : function() {
				$('.banner-big-about-us img:gt(0)').hide();
				setInterval(function(){
				  $('.banner-big-about-us img:first').fadeOut(1500)
					 .next('img').fadeIn(1000)
					 .end().appendTo('.banner-big-about-us');}, 
				  5000);
			}
		}
	};
	
	Engine.utils.homebanner();
	Engine.utils.links();
	Engine.utils.mails();
	Engine.utils.qa();
	Engine.utils.contactprefill();
	Engine.utils.contactvalidate();
	
});