﻿
// File: Dictionary.js

// Start function when DOM has completely loaded 


jQuery(document).ready(function()
{
  jQuery.ajax({
    type: "GET",
    url: "/WebServices/DictionaryService.asmx/GetTerms",
    dataType: "xml",
    success: getTerms
  });
});

function getTerms(xml){

jQuery('string',xml).each(function(){
creatHyperlinkTags(jQuery(this).text(),'productdescription')
});
    
}

function getDefinition(term){
jQuery.ajax({
    type: "GET",
    url: "/WebServices/DictionaryService.asmx/GetDefinition?term="+term,
    dataType: "xml",
    success: function(xml){
    return jQuery('string',xml).text();
    }});
//return jQuery.load("/WebServices/DictionaryService.asmx/GetDefinition?term="+term).('string').Text();
}


function creatHyperlinkTags(regexString, elementName) 
{   
        var el = jQuery('#'+elementName);
        el.html(el.html().replace((regexString), '<span class="dictionaryWord">'+regexString+'</span>','gi'));   
        
        jQuery(".dictionaryWord").mouseover( function(e){
            jQuery("#dictionaryToolTip").remove();
            def = jQuery.ajax({
            type: "GET",
            url: "/WebServices/DictionaryService.asmx/GetDefinition?term="+jQuery(this).text(),
            dataType: "xml",
            success: function(xml){  
            jQuery("body").append("<div id='dictionaryToolTip' style='left:"+e.pageX+"px;top:"+e.pageY+"px;' class='dictionaryTooltip'>"+jQuery('string',xml).text()+"</div>");
            //alert(jQuery('string',xml).text());
            }});
        });
        
        jQuery(".dictionaryWord").mouseout(function(e){
            jQuery("#dictionaryToolTip").remove();
        });
}
   
  
function parseXml(xml){	
		// Build an HTML string
		myHTMLOutput = '';
	  	
	  	var numberOfItems = jQuery('string',xml).length;
	  	
		// Run the function for each item tag in the XML file
		jQuery('item',xml).slice(numberOfItems-3,numberOfItems).each(function(i) {
			itemTitle = jQuery(this).find("title").text();
			itemDate = jQuery(this).find('[nodeName="dc:date"]').text();
			itemLink = jQuery(this).find("link").text();
			itemContent = jQuery(this).find('[nodeName="content:encoded"]').text().slice(0,255);
						
			// Build row HTML data and store in string
			mydata = BuildHTML(itemTitle,itemDate,itemLink,itemContent);
			myHTMLOutput = mydata + myHTMLOutput;
		});
		
		// Update the DIV called Content Area with the HTML string
		jQuery("#RssContent").append(myHTMLOutput);
		
	}
 
 
 
// function BuildHTML(itemTitle,itemDate,itemLink,itemContent){
//	
//	// Build HTML string and return
//	output = '';
//	output += '<div class="rssItemDiv">';
//	output += '<div class="rssItemTitle"><h3><a href="' + itemLink + '" title="Link to rss feed item ' + itemTitle + '">'+ itemTitle + '</a></h2></div>';
//	output += '<div class="rssItemDate">'+ itemDate +'</div>';
//	output += '<div class="rssItemContent">' + itemContent + '... <a href="' + itemLink + '">read more ></a></div>';
//	output += '</div>';
//	return output;
//}
	 



//var tooltip=function(){
//	var id = 'tt';
//	var top = 3;
//	var left = 3;
//	var maxw = 300;
//	var speed = 100;
//	var timer = 0;
//	var endalpha = 95;
//	var alpha = 0;
//	var tt,t,c,b,h;
//	var ie = document.all ? true : false;
//	return{
//		show:function(v,w){
//			if(tt == null){
//				tt = document.createElement('div');
//				tt.setAttribute('id',id);
//				t = document.createElement('div');
//				t.setAttribute('id',id + 'top');
//				c = document.createElement('div');
//				c.setAttribute('id',id + 'cont');
//				b = document.createElement('div');
//				b.setAttribute('id',id + 'bot');
//				tt.appendChild(t);
//				tt.appendChild(c);
//				tt.appendChild(b);
//				document.body.appendChild(tt);
//				tt.style.opacity = 0;
//				tt.style.filter = 'alpha(opacity=0)';
//				document.onmousemove = this.pos;
//			}
//			tt.style.display = 'block';
//			c.innerHTML = v;
//			tt.style.width = w ? w + 'px' : 'auto';
//			if(!w && ie){
//				t.style.display = 'none';
//				b.style.display = 'none';
//				tt.style.width = tt.offsetWidth;
//				t.style.display = 'block';
//				b.style.display = 'block';
//			}
//			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
//			h = parseInt(tt.offsetHeight) + top;
//			clearInterval(tt.timer);
//			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
//		},
//		pos:function(e){
//			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
//			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
//			tt.style.top = (u - h) + 'px';
//			tt.style.left = (l + left) + 'px';
//		},
//		fade:function(d){
//			var a = alpha;
//			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
//				var i = speed;
//				if(endalpha - a < speed && d == 1){
//					i = endalpha - a;
//				}else if(alpha < speed && d == -1){
//					i = a;
//				}
//				alpha = a + (i * d);
//				tt.style.opacity = alpha * .01;
//				tt.style.filter = 'alpha(opacity=' + alpha + ')';
//			}else{
//				clearInterval(tt.timer);
//				if(d == -1){tt.style.display = 'none'}
//			}
//		},
//		hide:function(){
//			clearInterval(tt.timer);
//			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
//		}
//	};
//}();
