/*********** coremetrics               ***********************************************/
/*********** Version 1.0               ***********************************************/
/*********** Author Yoann Phung Van    ***********************************************/
/*********** taggage coremetrics  ************************************/
jQuery.fn.coremetrics = function(o,url) {
	
	// Paramètres par defaut
	var settings = jQuery.extend({
		pageViewPrefixClass : "cmpageview_"		
	}, o);	
	
	var tabCategoryId = new Array();
  var categoryId = "";
  var cpt = 0;
  var pageViewPrefixLength = settings.pageViewPrefixClass.length; 
  if (typeof HashTableCategories == "object" || typeof HashTableCategories == "array") {
  	//On selectionne les class qui contiennent le suffixe
    $(".[class*='"+settings.pageViewPrefixClass+"']").click(function() {
        tabCategoryId = $(this).attr('class').split(" ");          
        cpt = 0;         
        while(cpt<tabCategoryId.length && categoryId == ""){
          if(tabCategoryId[cpt].indexOf(settings.pageViewPrefixClass)>-1){
             categoryId = tabCategoryId[cpt];
          }
          cpt++;
        }
        categoryId = categoryId.substring(pageViewPrefixLength);            
        if(categoryId!= "" && HashTableCategories[categoryId]!=null){        
          cmCreatePageviewTag(HashTableCategories[categoryId], categoryId, null, null);
          console.log("cmCreatePageviewTag("+HashTableCategories[categoryId]+", "+categoryId+", null, null);");  
        }                       
  	});    	
  }	
}; 