/*Swift Javascript*/
$(document).ready(function(){
						   
/*begin carousel*/
		try{
			 var listItems = $(".carousel-channels ul").children();			 
			 if(listItems.length>0){
				var mycarousel_itemList= new Array(listItems.length);
				for (i=0; i<listItems.length; i++)
				{
					var node = listItems[i];
					var anchorTag= $(node).children();
					var imageTag= $(node).children().children();
					var objItem = {
						href:$(anchorTag).attr('href'),
						target:$(anchorTag).attr('target'),
						url:$(imageTag).attr('src'),
						width:$(imageTag).width(),
						height:$(imageTag).height()
					};
					mycarousel_itemList[i]=objItem;
				}		
				function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
				{
					var idx = carousel.index(i, mycarousel_itemList.length);
					if(state=='next' || state=='init'){
						carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
						}
					if(state=='prev')
						{
						carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));	
						}
				};
				
				function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
				{
					carousel.remove(i);
				};
				function mycarousel_getItemHTML(item)
				{
					return '<a target="'+item.target+'" href="'+item.href+'"><img   src="' + item.url + '" alt="" style="width:'+ item.width +'px; height:'+ item.height +'px;" /></a>';
				};
				
				jQuery('.carousel-channels ul').jcarousel({
					wrap: 'circular',
					scroll:1,
					visible:5,
					
					itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback}/*,
					itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}*/
				});
			 }
		}
		catch(ex){}
	/*end carousel*/
	/* begin pluggin to add padding according table cellpadding */
	 $(".interior .mainTbl tbody td table").each(function(){
		  var tablepadding= $(this).attr("cellpadding");
		  if(tablepadding>0){
		  $(this).find("td").css( "padding", tablepadding);}
	 });
	 
	 /* end pluggin to add padding according table cellpadding */

	// lhn closed
    if($(".menu .currSection").length == 0) {
	    $("#Breadcrumb a:gt(0)").each( function(a) { 
		    var id = $(this).attr("href").match(/id=(\d)+/);	
		    //console.debug("Breadcrumb %d %s %s", a, $(this).attr("href"), id[0]);
		    if(id) {    			
			    $("#leftNav .menu > li > a").each( function(b) {
				    var href = $(this).attr("href");
				    var aTagId = href.match(/id=(\d)+/);
				    //console.debug("matched %d %s %s %s %b", b, href, aTagId[0],id[0], (aTagId[0] == id[0]) );
				    if(aTagId!=null){
				        if(aTagId[0] == id[0]) {
					        //console.debug("matched id %d %s %s", b, href, aTagId[0] );
					        $(this).parent().addClass("currSection");
					        return false;
				        }
					}
				
			});
		}
	});
	
	if($(".menu .currSection").length > 1 ) {
		$(".menu .currSection").eq(0).removeClass("currSection").addClass("headerSection");	
	}

	$(".menu .currSection li a").each( function(a) {
			var pageNameAlt = ($("div[id$=ContentBlockPage] p.first-child img").attr("alt") ) ? $("div[id$=ContentBlockPage] p.first-child img").attr("alt") : $("div[id$=ContentBlockBanner] img").attr("alt");
			pageName = pageNameAlt.split("-");
			var text = $(this).text();
			var matchRegExp = new RegExp(pageName[0], "i");
				//console.debug("%s %s %b", text, pageName[0], text.match(matchRegExp) );
			if(text.match(matchRegExp) ){
					$(this).parent().addClass("selected");
			}
				
	});


  }
});