﻿( function($) {
	$.fn.readcontent = function(xmlpath, css) {
		$
				.get(
						xmlpath,
						function(read) {
							 /**bug fix provide by Whelan - start
					    	    * When getting xml string from an url, the variable d will be treated as String rather than XML Object.
					    	    * The code doesn't work with String object so that the menu fail to show up.
					    	    * Below code parse the String into XML Object to make the code work.
					    	    * It is just the fix tested for Firefox and IE 7 only. To "hardcode" the fix here should not be encouraged,
					    	    * also, the code didn't check for the objec type.
					    	    * please find a better way to solve it.
					    	   **/
					          if( window.DOMParser ){
									// added by Wing Tse to trim the space before parsing
									read = read.replace( /^\s+|\s+$/g, "" );
									//console.log(read);
					        	   read = (new DOMParser()).parseFromString(read, 'text/xml');
					           }else if( window.ActiveXObject && window.GetObject ) {
					        	   var dom = new ActiveXObject( 'Microsoft.XMLDOM' );
					               dom.loadXML( read );
					               read = dom;
					           }
					           /**bug fix provide by Whelan - end**/
					        /* add code to control box bgcolor and title css Kevin 20090204*/
					        var curcss='red';
					        var curtitlecss='exp_Title_red';
					        var commimgpath='/resources/Common/images/';
					        var tmpleftimg='title_Blue_left.jpg';
					        var tmprightimg='title_Blue_right.jpg';
							switch (current)
							{
					        case "business":
					        {
					          curcss='blue';
					          curtitlecss='exp_Title_blue';
					          tmpleftimg='title_Blue_left.jpg';
					          tmprightimg='title_Blue_right.jpg';
							  break;
					        }
							 case "consumer": 
					        {
					          curcss='red';
					          curtitlecss='exp_Title_red';
					          tmpleftimg='title_red_left.jpg';
					          tmprightimg='title_red_right.jpg';
							  break;
					        }
							 case "customer_service": 
					        {
					          curcss='green';
					          curtitlecss='exp_Title_green';
					          tmpleftimg='title_green_left.jpg';
					          tmprightimg='title_green_right.jpg';
							  break;
					        }
							 case "careers":
					        {
					          curcss='pureYellow';
					          curtitlecss='exp_Title_yellow';
					          tmpleftimg='title_pureYellow_left.jpg';
					          tmprightimg='title_pureYellow_right.jpg';
							  break;
					        }
							default:
							{
								curcss='pureBlue';
								curtitlecss='exp_Title_pureBlue';
								tmpleftimg='title_pureBlue_left.jpg';
					            tmprightimg='title_pureBlue_right.jpg';
							    break;
							}
							}
							var leftimgpath=commimgpath+tmpleftimg;
							var rightimgpath=commimgpath+tmprightimg;
                            var thtml='';
							var lefthtml = '<div class="floatLeft"><div id="list1b" class="basic ' + curcss + '" >';
							var righthtml = '<div class="floatRight"><div id="list1c" class="basic ' + curcss + '">';              
							var lang=$(read).find('lang').text();
                                                         var stylebold="";
if (lang =="en-uk")
												{
												stylebold="style=\"font-weight: bold;\"";
												}
							$(read)
									.find('CHANNELINFO-DETAIL')
									.each(
											function() {
                                                
												var $channelinfo = $(this);
												var sum = $(read).find(
														'CHANNELINFO-DETAIL')
														.size();
												var id = $channelinfo
														.attr("ID");
												var title = $channelinfo
														.find(
																'CHANNELINFO-TEASER-TITLE')
														.text();
												var description = $channelinfo
														.find(
																'CHANNELINFO-TEASER-BODY')
														.text();
												if (lang =="zh-hk")
												{
													description=description.replace('>更多</a>','>更多<img src="/resources/Common/images/arrow.gif" style="vertical-align:middle;" border="0"></a><div style="clear:both;"></div>');
												}
												else
													{
													
													description=description.replace('>more</a>','>more<img src="/resources/Common/images/arrow.gif" style=" vertical-align:middle;" border="0"></a><div style="clear:both;" ></div>');
													}
												var linkfircss="mid_g";
												if (title.length >35)
												{
													linkfircss="mid_glong";
												}
												
                                              
												if (id%2==1) {
												     if(id ==1)
												    {
													 if(linkfircss=="mid_glong" )
													 {
												     lefthtml += '<div class="floatLeft"><img src="'+leftimgpath+'" alt="" /></div><blink  class="'+linkfircss+'" '+stylebold+'>' + title + '</blink><div class="floatLeft" ><img src="'+rightimgpath+'" alt="" /></div><div class="height0"></div>';
													 }
													 else
													 {
														  lefthtml += '<div class="floatLeft"><img src="'+leftimgpath+'" alt="" /></div><blink  class="'+linkfircss+'" '+stylebold+'>&nbsp;&nbsp;' + title + '</blink><div class="floatLeft" ><img src="'+rightimgpath+'" alt="" /></div><div class="height0"></div>';
													 }
													 /**change  a to blink**/
													 lefthtml += '<div class="tbsp">' + description + '</div>';
												    }
												     else
												    {
														if (title.length >40)
														{
													lefthtml += '<blink class="long" '+stylebold+'>' + title + '</blink>';
														}
														else
														{
															lefthtml += '<blink '+stylebold+'>' + title + '</blink>';
														}
													 /**change  a to blink**/
													lefthtml += '<div class="tbsp">' + description + '</div>';
													}
												}
												if (id%2==0) {
												  if(id ==2)
												    {
													 if(linkfircss=="mid_glong" )
													 {
												     righthtml += '<div class="floatLeft"><img src="'+leftimgpath+'" alt="" /></div><blink  class="'+linkfircss+'" '+stylebold+'>' + title + '</blink><div class="floatLeft" ><img src="'+rightimgpath+'" alt="" /></div><div class="height0"></div>';
													 }
													 else
													 {
														 righthtml += '<div class="floatLeft"><img src="'+leftimgpath+'" alt="" /></div><blink  class="'+linkfircss+'" '+stylebold+'>&nbsp;&nbsp;' + title + '</blink><div class="floatLeft" ><img src="'+rightimgpath+'" alt="" /></div><div class="height0"></div>';
													 }
													 /**change  a to blink**/
													 righthtml += '<div class="tbsp">' + description + '</div>';
												    }
												   else
												   {
													if (title.length >34 && $.trim(title)!='International Directory Inquiry Form')
														{
													righthtml += '<blink class="long" '+stylebold+'>' + title + '</blink>';
														}
														else
														{
															righthtml += '<blink '+stylebold+'>' + title + '</blink>';
														}
													 /**change  a to blink**/
													righthtml += '<div class="tbsp">' + description + '</div>';
												    }
												}
											});
							lefthtml += '</div> </div>';
							righthtml += '</div> </div>';
							var thrhtml=thtml;
							var html = lefthtml + righthtml;
							var sumsum = $(read).find(
														'CHANNELINFO-DETAIL')
														.size();
							 
							   $('#childexp').empty();
							$('#childexp').append($(html));
							$('#list1b').accordion( {
								autoHeight :false
							});
							$('#list1c').accordion( {
								autoHeight :false
							});
						});

	};

})(jQuery);

