$('document').ready(function(){	
	ote.Setup.setTemplateID(26);
	
	/** Load the extensions for the my account page **/
	if(ote.Router.getAlias() == 'MyProfile'){
		$.getScript('/scripts/inputEdit.jquery.js', function(){		
			$.getScript('/scripts/myAccount.jquery.js');		
			$('.inputEditable').editable({callback: 'myAccount.saveDetails(element)', switchLabel: 'save'});
			$('.addressHandler').groupEdit({classHandler: 'addressGroup', callback: 'myAccount.saveDetails(element)', switchLabel: 'save', cancelLabel: 'cancel', validateUsps: true});
		});
	}
	
	$.getScript('/scripts/imagePreload.jquery.js', function(){		
		$('.menuItem').imageSwap({mode: 'imagepath', mutatorOn: 'off', mutatorOff: 'on', separator: '_', searchClass: 'active'});
		$('.imageSwap').imageSwap({mode: 'imagepath', mutatorOn: 'off', mutatorOff: 'on', separator: '_'});
	});
	
	$('.noTrendReport').click(function() {
		alert("No recent scan available at this time. Please check back later.");
	});
	
	$('.showTrendReport').click(function(){		
		var date = $(this).attr('report');
		
		if( date.length == 0 ) {
			alert("No recent scan available at this time. Please check back later.");
		} 	else	{
			var trendReportUrl = location.protocol + '//' + location.host + '/IDReport?key=' + date;
			var newWindow = window.open(trendReportUrl, '_blank');
			newWindow.focus();
		}
	});
	
	$('.menuitem').imageSwap({mode: 'imagepath', mutatorOn: 'off', mutatorOff: 'on', separator: '_', searchClass: 'activeElement'});

	$('.rounded').corner();

	$('.btn-expand').click(function() {	
		if($(this).attr('src').indexOf('expand') !== -1 ){			
			$(this).attr('src', $(this).attr('src').replace('expand', 'collapse'));
		}	else	{		
			$(this).attr('src', $(this).attr('src').replace('collapse', 'expand'));
		}
		$(this).parent().parent().next().toggle();		
	});

	 // When a link is clicked  
	 $("a.tab").click(function () {  
	
	     // switch all tabs off  
	     $(".active").removeClass("active");  
	
	     // switch this tab on  
	     $(this).addClass("active");  
	
	     // slide all elements with the class 'content' up  
	     $(".tab-content").slideUp();  
	
	     // Now figure out what the 'title' attribute value is and find the element with that id.  Then slide that down.  
	     var contentShow = $(this).attr("title");
	     $("#"+contentShow).slideDown();  
	
	 });

	

	$('a[tooltip]').each(function() { // Loop over each avatar using the .each() method
	      // Thanks to .each() "this" refers to each element within the loop
	      $(this).qtip({
	    	 content: $(this).attr('tooltip'),
	         position: {
	            my: 'bottom center', // Position the tooltip...
	            at: 'top center', // ...to the right of the avatar
	            adjust: { screen: true } // Adjust to keep in the viewport
	         },
	         show: { delay: 700 }, // Give it a reasonable delay so they don't view it accidentally
	         hide: { fixed: true, delay: 700 }, // Allow the user the mouseover the tooltip without it hiding
	         style: {
	            classes: 'ui-tooltip-cream ui-tooltip-shadow',
	            tip: {
	               corner: true,
	               width: 20,
	               height: 15,               
	               border: 5
	            }
	         }
	      });
	});
});

(function($) {

	var inc = 1;

	jQuery.fn.IDScorePlugin = function(score, level) {

	  margin = score / 3;
	  if ( $('#level').length == 0 ) {
		  return true;
	  }
	  $('#indicator').animate({
	    marginLeft: '+='+margin
	  }, { 
	    duration: 1000,   
	    step: function() {
		$('#level').html('<img src="/images/ajax_loader.gif">');
		$('#grade').html('<img src="/images/ajax_loader.gif">');
		$('#summary').html('<img src="/images/ajax_loader.gif">');
		val = inc++ + 5;
	        $('#score').text(val);     
	    },
	    complete: function() {
	    $('#level').fadeIn('slow'); 
		$('#level').html(level);
		$('#score').text(score);
	    }
	  });

	};

	jQuery.fn.IDFraudReportPlugin = function(grade, summary) {

	 if ( $('#grade').length == 0 ) {
	  return true;
	 }
	 
	 var margins = [];
  	 margins['A'] = 33;
  	 margins['B'] = 99;
  	 margins['C'] = 165;
  	 margins['D'] = 231;
  	 margins['F'] = 297;

	  margin = margins[grade];

	  $('#indicator2').animate({
	    marginLeft: '+='+margin
	  }, { 
	    duration: 1000,
	    complete: function() {
	    $('#grade').fadeIn('slow'); 
		$('#grade').html(grade);
		$('#summary').fadeIn('slow');
		$('#summary').text(summary);
	    }
	  });

	};

})(jQuery);

function loadScanReport( lastScanDate, pageName ) {
	
	if (lastScanDate == '') {
		alert ("No recent scan available at this time. Please check back later.");
	} else {	
		var url = location.protocol + '//' + location.host + '/' + pageName + '/' + lastScanDate;
		var newWindow = window.open(url);
		newWindow.focus();
	}
}
