var _channels_menu_links_ =  [
//{link : 'http://haj.m3com.com.sa/'  , title : "الحج"   , isNew : true  },
{link : 'http://islam.m3com.com.sa/'  , title : "اسلام"   },
{link : 'http://news.m3com.com.sa/'   , title : "اخبار"   },
{link : 'http://family.m3com.com.sa/'   , title : "الاسرة"   },
{link : 'http://sports.m3com.com.sa/'   , title : "الرياضة"   },
{link : 'http://sfl1.m3com.com.sa/'   , title : "الكرة السعودية"   },
{link : 'http://album.m3com.com.sa/'   , title : "البوم الصور" },
{link : 'http://games.m3com.com.sa'    , title : 'العاب'  },
{link : 'http://tube.m3com.com.sa'   , title : '<span style="line-height:14px;">معكم</span>&nbsp;<span style="line-height:14px;">Tube</span>' },
{link : 'http://www.m3com.com.sa/welcome/view/rnd/'   , title : 'بريد'  },
{link : 'http://cards.m3com.com.sa/'   , title : 'بطاقات' },
{link : 'http://calendar.m3com.com.sa'   , title : 'تقويم'},
{link : 'http://forum.m3com.com.sa/'   , title : 'منتديات'  },
{link : 'http://ask.m3com.com.sa/'   , title : 'سؤال وجواب' },   
{link : 'http://ecare.m3com.com.sa/'   , title : 'العناية الإلكترونية'  },
{link : 'http://friends.m3com.com.sa'   , title : 'اصحاب'  },
{link : 'http://travel.m3com.com.sa'   , title : 'السياحة و السفر'},
{link : 'http://mypage.m3com.com.sa'   , title : 'صفحتي'  },
{link : 'http://tv.m3com.com.sa'   , title : '<span>معكم</span>&nbsp;<span>TV</span>'  },
{link : 'http://jokes.m3com.com.sa'   , title : 'نكت'  },
{link : 'http://finance.m3com.com.sa'   , title : 'سوق الاسهم'  },
{link : 'http://kids.m3com.com.sa'   , title : 'اطفال'} ,
{link : 'http://manutd.m3com.com.sa'   , title : 'مانشستر يونايتد' }
];

var _services_menu_links_  = [
{link : 'http://safenet.m3com.com.sa/'   , title : 'نقاء نت'   },
{link : 'http://storage.m3com.com.sa/'   , title : 'ملفاتي'  },
{link : 'http://arsel.m3com.com.sa'   , title : 'خدمات الرسائل'  },
{link : 'http://ta3lem.m3com.com.sa'   , title : 'تعليم'  },
{link : 'http://ecare.m3com.com.sa/index.php?_m=downloads&_a=viewdownload&downloaditemid=15&nav=0'   , title : 'حماية الانترنت'  }
];



function _menu_build_list(menu){
	var menu_list = "";
	var isNew_text='';
	for(l=0;l<menu.length;l++){

		cstyle= "";
		last_item = "";
		if(l == menu.length-1){
			last_item = 'class="last"';
		}
		if(menu[l].instyle){
			cstyle = 'style="' + menu[l].instyle+'" ';
		}
		if(menu[l].isNew){
			isNew_text = '<sup style="color:#ff0000;"><blink>جديد</blink></sup>';
		} else {
			isNew_text = '';
		}
		if(menu[l].isCompetition){
			isNew_text = '<sup style="color:#ff0000;"><blink>مسابقة</blink></sup>';
		}		
		
		if(menu[l].target){
			target_text = 'target = ' + menu[l].target;
		} else {
			target_text = '';
		}
		
		menu_list +='<li '+last_item+' ><h2><a '+cstyle+' ' + target_text + ' href="'+menu[l].link+'" target="_top">'+menu[l].title+' ' + isNew_text + '</a></h2></li>';
	}

	return menu_list;
}

document.write('<div class="stcChannel" style="line-height:20px;" id="_channels_menu_lable"  >');
document.write('<link href="http://images.m3com.com.sa/alshamel/locale/ar_SA/Common/style_menu.css?st=6" type="text/css" rel="stylesheet" />');
document.write('<div id="_channels_menu_lable_son" style="line-height:20px;">قنوات معكم</div>');
document.write('<div id="_channels_menu"  class="stcChannelList"   style="position:absolute;margin-top:-2px;display:none;width:168px;line-height:20px;z-index:500;height:280px;margin-right:-3px;margin-right:-5px;width:167px" >')
document.write('<table border="0" width="100%"  cellspacing="0" cellpadding="0"> <tr> <td align="right">');
document.write('<div style="overflow:hidden;height:280px;width:100%" id="_scroll_menu_">');
document.write('<ul  > ');
document.write(_menu_build_list(_channels_menu_links_));
document.write("<li class='ttl' id='_servers_title_' ><h2> خدمات معكم </h2></li>");
document.write(_menu_build_list(_services_menu_links_));
document.write('</ul>');
document.write('</div>');
document.write('</td> <td class="sArrows">');
document.write('<img src="http://images.m3com.com.sa/alshamel/locale/ar_SA/Common/spacer.gif" width="15" height="140" id="mup" onmouseout="_menu_move = false" onmouseover="jQuery(\'#_scroll_menu_\').stop();_menu_scroll(\'up\' , true)" alt="" />');
document.write('<img src="http://images.m3com.com.sa/alshamel/locale/ar_SA/Common/spacer.gif" width="15" height="140" id="mdown" onmouseout="_menu_move = false" onmouseover="jQuery(\'#_scroll_menu_\').stop();_menu_scroll(\'down\' , true)" alt="" />');
document.write('</td>');
document.write('</tr></table></div>');

document.write('<iframe id="_menu_holder" class="menu_holder" frameborder="0" scrolling="No"  style="margin-right:-3px;display:none;border:0px;width:168px;position:absolute;z-index:400"></iframe></div>');



var _menu_shown = false;
var _channeles_menu_timer = null;
function _show_channels_menu(){
	if(!_menu_shown){
		/*	jQuery('#_channels_menu')[0].style.left = getPositionChannelMenu(jQuery('#_channels_menu_lable')[0] , "left")+"px";*/
		jQuery("#_menu_holder").css("left" , jQuery('#_channels_menu')[0].style.left );
		jQuery("#_menu_holder").css("top" , getPositionChannelMenu(jQuery('#_channels_menu_lable_son')[0] , "top")+jQuery('#_channels_menu_lable_son').height() + "px");
		jQuery("#_menu_holder").css("height" , jQuery('#_channels_menu').height() - 5 + "px");
		jQuery('#_channels_menu').slideDown("slow");
		jQuery("#_menu_holder").slideDown("slow" , function (){ blind_timer = setTimeout('blinkIt()',500); });
		_menu_shown  = true;
	}
	clearTimeout(_channeles_menu_timer);

}

function _wait2hide_channels_menu(){
	_channeles_menu_timer = setTimeout("_hide_channels_menu()" , 1000);
}

function getPositionChannelMenu(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}

	return totaloffset;
}
function _hide_channels_menu(e , ifmenu){
	hideIt = false;
	if(_menu_shown == true){
		if(e){

			if( !( e.target.id == 'mup' ||   e.target.id == 'mdown' || e.target.id == '_servers_title_'  ) ){

				if(ifmenu == true ||   !( e.target.id == '_channels_menu_lable_son' || e.target.id == '_channels_menu_lable')){
					hideIt = true;
				}
			}
		}else{
			hideIt = true;
		}

		if(hideIt){
			clearTimeout(_channeles_menu_timer);
			_menu_shown  = false;
			jQuery('#_channels_menu').slideUp("slow");
			jQuery("#_menu_holder").slideUp("slow");
		}
	}

	clearTimeout(blind_timer);
}
_menu_move = false;
function _menu_scroll(dir , move){
	if(move){
		_menu_move = true;
	}
	if(_menu_move){


		if(dir == 'up'){
			jQuery('#_scroll_menu_').animate({scrollTop:jQuery('#_scroll_menu_')[0].scrollTop - 10}, 50, function() { _menu_scroll(dir, false) });
		}else{
			jQuery('#_scroll_menu_').animate({scrollTop: jQuery('#_scroll_menu_')[0].scrollTop + 10}, 50 , function() { _menu_scroll(dir, false) });
		}
	}
}


function _manage_menu_display(e){
	if(true == _menu_shown){
		_hide_channels_menu(e  , true);
	}else{
		_show_channels_menu();
	}
}

function blinkIt() {
	//	if (!document.all) return;
	//	else {
	//		for(i=0;i<document.all.tags('blink').length;i++){
	//			s=document.all.tags('blink')[i];
	//			s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
	//		}
	//	}
	//	blind_timer = setTimeout('blinkIt()',500);
	if(blind_state == 1){
		jQuery(".blink").css("visibility" , "hidden");
		blind_state = 0;
	}else{
		jQuery(".blink").css("visibility" , "visible");
		blind_state = 1;
	}


}
var blind_timer =  null;
var blind_state = 1;


jQuery('#_channels_menu_lable').click(_manage_menu_display);
jQuery(document).bind("click" , _hide_channels_menu);
jQuery(document).ready(
function(){
	blinkIt();
}
);

