Template = new Object();

Template.is_safari = (document.childNodes)&&(!document.all)&&(!navigator.taintEnabled)&&(!navigator.accentColorName)?true:false;
Template.is_ie55 = (document.all && document.fireEvent && !document.createComment);
Template.win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);

$(document).ready(function() {
 externalLinks();
 replaceHrTag();
 styleSecondCol();
 addSafariCss();
 $('#fdbk_screen').css({'opacity':'0.3'});
 chooseTestimonial();
 $('#testimonials').fadeIn(1000);

});

var RecaptchaOptions = {
    theme : 'white'
  }

function updatefeedheight(){
	var feedheight = $('#feedback').height();
	$('#fdbk_iframe').css({'height':'feedheight'});
}

function externalLinks(){
    if (document.getElementsByTagName){
        var objAnchors = document.getElementsByTagName('a');
        for (var iCounter=0; iCounter<objAnchors.length; iCounter++){
            if (objAnchors[iCounter].getAttribute('href') && objAnchors[iCounter].getAttribute('rel') == 'external'){
                objAnchors[iCounter].onclick = function(event){return launchWindow(this, event);};
                objAnchors[iCounter].onkeypress = function(event){return launchWindow(this, event);};
            }
        }
    }
}

function launchWindow(objAnchor, objEvent){
    var iKeyCode;
	
    if (objEvent && objEvent.type == 'keypress'){
        if (objEvent.keyCode)
            iKeyCode = objEvent.keyCode;
        else if (objEvent.which)
            iKeyCode = objEvent.which;
        if (iKeyCode != 13 && iKeyCode != 32)
        return true;
	}

	return !window.open(objAnchor);
}



function replaceHrTag(){	
	$(".maincontent hr").wrap("<div class='divider2'></div>");
	$("#sidenavcontainer hr").wrap("<div class='divider2'></div>");
	$("#gallerycontainer hr").wrap("<div class='divider3'></div>"); 
	$("#secondarycontent hr").wrap("<div class='divider4'></div>");  
}

// must include table plugin to use this function
function StripeTable(){				
	$(".stripeMe tr").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
	$(".stripeMe tr:even").addClass("alt");  
}


function styleSecondCol() {
	
    $('tr').each(function(){
						  
		var count=1;
      
    		$('td').each(function(){
      			count++;
				//alert(count);
				if(count%2 != 0){ 
					$(this).addClass("txtright");
				}
    	})
    })
  }

  
function addSafariCss() {
	  
	var userAgent = navigator.userAgent.toLowerCase();
	  
    
    // Is this a version of Safari?
    if($.browser.safari){
        $('body').addClass('browserSafari');
        
        // Add the version number
        userAgent = userAgent.substring(userAgent.indexOf('version/') +8);
        userAgent = userAgent.substring(0,1);
        $('body').addClass('browserSafari');
    }
}

// pick a testimonial and display it
// add/change testimonials in content/testimonials.html
function chooseTestimonial() {
  $('#testimonials div div').hide();
  var howMany = $('#testimonials div div').size();
  if (! howMany) return;
  // selected is a pseudo random number between 0 and howMany-1
  var selected = Math.floor(Math.random() * howMany);
  $('#testimonials div div:eq(' + selected + ')').fadeIn(1000);
  // call me again soon!
  setTimeout('chooseTestimonial()', 10000);
}
