function show_frame(loc){
	window.scrollTo(0,0);
	$('#ifnav_q').attr('value',loc);
	$("#naviFrame").attr('src',loc);
	$("#ifnav_a").attr('href',loc);
	$(".iframeNav").show();
	$("#pgDim").show();
	return false;
};
function scroll_home(tis){
	var tis = '#'+tis;
	$(".yl-homedisp").removeClass("sel-disp");
	$("#yl-hmd"+$(tis).attr('rel')).addClass("sel-disp");
};
function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
};
var pCarousel = {
	animationId: null,
	animationDir: 'right',
	auto: 0,
	/*time in miliseconds to wait before scrolling*/
	animationTimeout: 0,
	/*time in miliseconds for the scrolling transition*/
	animationSpeed: 250,
	init: function(carousel) {
	$('.jcnext').bind('click', function() {
	  pCarousel.halt();
	  carousel.next();
	  return false;
	 });
	$('.jcprev').bind('click', function() {
	  pCarousel.halt();
	  carousel.prev();
	  return false;
	});
	},
	animate: function(carousel) {
	pCarousel.animationId = setInterval( function() {
	  if( carousel.last == carousel.options.size ) { pCarousel.animationDir = 'left'; }
	  else if( carousel.first == 1 ) { pCarousel.animationDir = 'right'; }

	  if( pCarousel.animationDir == 'right' ) { carousel.next(); }
	  else { carousel.prev(); }
	}, pCarousel.animationTimeout );
	},

	halt: function() {
	if( pCarousel.animationId ) {
	  clearInterval(pCarousel.animationId);
	}
	}
};
var tCarousel = {
	animationId: null,
	animationDir: 'right',
	auto: 0,
	animationTimeout: 0,
	animationSpeed: 250,
	init: function(carousel) {
	$('.scmid-next').bind('click', function() {
	  tCarousel.halt();
	  carousel.next();
	  return false;
	 });
	$('.scmid-prev').bind('click', function() {
	  tCarousel.halt();
	  carousel.prev();
	  return false;
	});
	},

	animate: function(carousel) {
	tCarousel.animationId = setInterval( function() {
	  if( carousel.last == carousel.options.size ) { tCarousel.animationDir = 'left'; }
	  else if( carousel.first == 1 ) { tCarousel.animationDir = 'right'; }

	  if( tCarousel.animationDir == 'right' ) { carousel.next(); }
	  else { carousel.prev(); }
	}, tCarousel.animationTimeout );
	},

	halt: function() {
	if( tCarousel.animationId ) {
	  clearInterval(tCarousel.animationId);
	}
	}
};
function edit_side(m){
	var me = $(m).parents("a");
	var intext = me.html();
		intext = intext.replace(/(<([^>]+)>)(.*)(<([^>]+)>)/ig,""); 
	var inurl = me.attr("href");
	$(this).addClass("leftSelCur");
	
	$(".linkEditor").fadeIn();
	$(".linkInner b").html('Edit Link <i>' + intext + '</i>');
	$("#linkName").attr("value", intext);
	$("#linkUrl").attr("value", inurl);
	return false;
};
$(document).ready(function(){
	$(".appNav a").not(".mid-homesel a, .selectTheme").corner("round 3px");
	$(".tick7").corner("round 3px");
	$(".pt_closer").click(function() {
		$(this).parents(".tShowPop").css('zIndex','-9999999');
		return false;
	});
	$(".tShow li").hover(function() {
		$(this).children(".tShowPop").css('zIndex','9999999');
	});
	$(".tShow li .tShowPop p").each(function(){
		var tchild = $(this).children("a:first-child");
		var maina = $(this).parents(".tShowPop").parents("li").children("a:first-child");
		maina.attr('href',maina.attr('name')+maina.attr('href'));
		tchild.attr('href','#top');
		tchild.click(function(){
			var tc_maina = $(this).parents(".tShowPop").parents("li").children("a:first-child").attr('href');
			show_frame(tc_maina); 
		});
	});
	$(".topTopEdit").click(function() { 
		$(".chooseEdition").toggle("slow");
		return false; 
	});
	$("#subz").click(function(){
		var iv = $("#zipInp").val();
			$(".weatherDisplayer").html('<img class="loader" src="/images/v_me.gif">');
			$.get('/servContent/site_g_weather','zip='+iv,function(d){ 
				$(".weatherDisplayer").html(d) 
			});
		return false;
	});
	$("#pgDim").css("height", $(document).height());
	$("#pgDim").click(function(){
		$(this).fadeOut();$(".resetOptions").fadeOut();
		return false;
	});
	
	var theB = '<b onclick="show_frame($(this).parents(\'a\').attr(\'href\'));" class="sfLeftb"></b>';
	var thelB = '<b onclick="show_frame($(this).parents(\'a\').attr(\'href\'));" class="sfLeftb"></b>';
	
	$("._ylink-edit").append(thelB);
	$('.sframe').not("._ylink-edit").append(theB);
	$('.sframe').click(function(){ return false;  });
	$('.stframe').click(function(){ show_frame($(this).attr('href')); return false;  });
	$(".searchInput").attr("autocomplete","off");
	
	/**/
	$("#customBtn").click(function(){
		$(".optionsDisp").slideToggle("slow");
		return false;
	});
	$(".moveTick").click(function(){
		if($(this).parents(".tick7").children(".tShow").is(":hidden")) {
			$(this).css('background-position','-3px -587px');
			$(this).parents(".tick7").children(".tShow").slideDown();
		}
		else {
			$(this).css('background-position','-24px -586px');
			$(this).parents(".tick7").children(".tShow").slideUp();
		}
	});
	/***/
	$('#_yl-homecr').jcarousel({
		wrap: 'last',
		auto: 0,
		scroll: 2,
		visible: 3,
		initCallback: pCarousel.init,
		easing: 'linear',
		animation: pCarousel.animationSpeed,
		buttonPrevHTML: null,
		buttonNextHTML: null
	});
	$('#_ymidj').jcarousel({
		wrap: 'last',
		auto: 0,
		scroll: 4,
		visible: 4,
		initCallback: tCarousel.init,
		easing: 'linear',
		animation: tCarousel.animationSpeed,
		buttonPrevHTML: null,
		buttonNextHTML: null
	});

	$("._ylcr").hover(function(){
		var tis = $(this).attr('id');
		$("._ylcr").removeClass("selyl");
		$(this).addClass("selyl");
		$(".yl-homedisp .per-p").hide();
		setTimeout("scroll_home('"+tis+"')", 300);
	});

	var navframe = $("#naviFrame");
	$("#ifnav_full").click(function(){ 
		if($(this).css('font-weight') === '100'){
			$(".iframeNav").css({'width':'75%'});
			$(".ifhold").css({'height':'600px'}); 
			$(this).css({'font-weight':'normal'});
			$(this).html('Wide view');
		}
		else {
			$(".iframeNav").css({'width':'97%','top':'5px','left':'5px'});
			$(".ifhold").css({'height':'700px'});
			$(this).css({'font-weight':'100'});
			$(this).html('Narrow view');
		}
	});
	$("#ifnav_mini").click(function(){ 
		if($(this).css('font-weight') === '100'){
			$(".ifhold").css({'height':'0px'});
			$(this).css({'font-weight':'normal'});
			$("#pgDim").hide();
			$(this).html('Restore');
		}
		else {
			$(".ifhold").css({'height':'600px'}); 
			$(this).css({'font-weight':'100'});
			$("#pgDim").fadeIn();
			$(this).html('Minimize');
		}
	});
	$("#ifnav_back").click(function(){ 
		window.history.go(-1);
		$('#ifnav_q').attr('value',$("#naviFrame").attr('src'));  
	});
	$("#ifnav_fwd").click(function(){ 
		window.history.go(+1);
		$('#ifnav_q').attr('value',$("#naviFrame").attr('src'));  
	});
	$("#ifnav_go").click(function(){ 
		var io = $('#ifnav_q').val();
		var loc = io.search('http://')==-1?'http://'+io:io;
			navframe.attr("src",loc); 
			$('#ifnav_q').attr('value',loc);
	});
	$(".ifnav_form").submit(function(){ 
		var io = $('#ifnav_q').val();
		var loc = io.search('http://')==-1?'http://'+io:io;
			navframe.attr("src",loc); 
			$('#ifnav_q').attr('value',loc);
		return false;
	});	
	$("#ifnv_a").hover(function(){ 
		var io = $('#ifnav_q').val();
		var loc = io.search('http://') == -1 ? 'http://' + io : io;
		$(this).attr('href',loc.replace('http://brwsr/','abcd'));  
	});
	$("#ifnav_close").click(function(){ 
		$(".iframeNav").hide();$("#naviFrame").attr('src','/servContent/site_loading');
		$("#pgDim").fadeOut();  
	});
	
	$(".chooseEdition a").click(function(){
		var ed = $(this).text();
		setCookie('edition',ed,100);
		window.location.reload();
		return false;
	});

	$(".links-nav span").click(function(){
		$(".links-nav span").removeClass("sel-linknav");
		$(this).addClass("sel-linknav");
		return false;
	});
	$(".yl-homedisp .per-p").fadeOut('medium');
	$(".yl-homedisp").append('<div class="righ-control" style="display:none;"><div></div></div>');
	$(".righ-control").fadeIn('slow');
	$(".righ-control").each(function(){
		$(this).hover(function(){
			$(".yl-homedisp .per-p").fadeIn('slow');
		});
	});
	/**/
	$("#pgPosCent").click(function(){
		$(".bodyHolder").css({'margin-left':'auto','margin-right':'auto'});
		$("#pgPos").attr("value",$(this).attr("rel"));
		return false;
	});
	$("#pgPosLeft").click(function(){
		$(".bodyHolder").css({'margin-left':'5px','margin-right':'5px'});
		$("#pgPos").attr("value",$(this).attr("rel"));
		return false;
	});
	/**/
	$("#resetBtn").click(function(){
		$("#pgDim").fadeIn();
		$(".resetOptions").fadeIn();
		return false;
	});
	$("#resetCancel").click(function(){
		$("#pgDim").fadeOut();
		$(".resetOptions").fadeOut();
		return false;
	});
	/***/

	$("#send985").click(function(){ 
		var ip = $("#ie985").val();
		var msg = $("#msg985").val();
		$.post('/servContent/site_int','sub=true&ie='+ip+'&msg='+msg, function(d){ 
			$(".form-p985").html(d);  
		});
		return false;
	});
	
	$(".middleNav a").click(function(){
		var navnum = $(this).attr("rel");
		for (i=1;i<5;i++) {
			$(".middleNavContent"+i).hide();
		}
		$(".middleNavContent"+navnum).removeClass("hide");
		$(".middleNavContent"+navnum).show();
		$(".middleNav a").each(function(){ 
			$(this).removeClass("midSel"); 
		});
		$(this).addClass("midSel");
		return false;
	});

	$('.cscrollb a').click(function(){ 
		show_frame($(this).attr('href')); 
		return false; 
	});
	$(".morescroll div").click(function(){ 
		if( $(this).css('vertical-align') === 'top' ){
			$('.cscrollb').addClass("fullcscroll");
			$(this).html( $(this).attr('class') );
			$(this).css({'vertical-align':'middle'});
		}
		else{
			$('.cscrollb').removeClass("fullcscroll");
			$(this).html( $(this).attr('title') );
			$(this).css({'vertical-align':'top'});
		}
	});

	$("._ylink-edit").not(".editSidebar a").hover(
	  function () {
		$(this).append("<span class='editSideB' onclick='edit_side(this);return false;'>Edit</span>");
	  }, 
	  function () {
		$(this).find("span:last").remove();
	  }
	);

	/***specific***/
	$("#addSideLink").click(function(){
		$(".linkEditor").fadeIn();
		$(".linkInner b").html('Add a Favorite');
		$("#linkName").attr("value", '');
		$("#linkUrl").attr("value", '[U]http://');
		return false;
	});
	/***/
	$("#linkCancel").click(function(){
		$(".linkEditor").fadeOut();
		return false;
	});
	$("#linkSave").click(function(){
		$(".linkEditor").fadeOut(); 
		var linkurl = $("#linkUrl").attr("value");
		var linkname = $("#linkName").attr("value");
		var sidb = 'func=sidebar&adl='+linkurl+'&adn='+linkname;
		$.post("/turnerM;_msess=9", sidb, function(sOutput){
			$.post("/turnerM;_msess=9", "temp=t&var1=side_bar", function(d){ $(".side-bar-links").html(d); });
		});
	});
	$("#linkDel").click(function(){
		$(".linkEditor").fadeOut();
		var linkurl = $("#linkUrl").attr("value");
		var linkname = $("#linkName").attr("value");
		var sidb = 'func=sidedel&adl='+linkurl+'&adn='+linkname;
		$.post("/turnerM;_msess=9", sidb, function(sOutput){ $("#error").html(sOutput); });
		$("#_uslink-" + linkname).hide("medium");
	});
	/**customize**/
	$(".selectBg").each(function(i){
	var each_id = $(this).attr("color");
		$(this).css({'background' : '#' + each_id });
		$(this).click(function(){ 
			$(".selectBg").css('border-width', '1px'); 
			$(this).css('border-width', '2px'); 
		});
	});
	$(".selectTheme").each(function(i){
		var each_id = $(this).attr("color");
		$(this).css({'background' : '#' + each_id });
		$(this).click(function(){
			$(".selectTheme").css('border-width', '1px'); 
			$(this).css('border-width', '2px'); 
		});
	});
	$(".selectBg").click(function(){
		var reg_r = $(this).attr("color");
		$("#custBg").attr("value", reg_r);
		return false;
	});
	$(".selectTheme").click(function(){
		var reg_r = $(this).attr("color");
		$("#mColor").attr("value", reg_r);
		return false;
	});
	/*theme start**/
	function colorscale(hexstr, scalefactor) {
	  var r = scalefactor;
	  var a, i;
	  if (r < 0 || typeof(hexstr) != 'string')
		return hexstr;
		hexstr = hexstr.replace(/[^0-9a-f]+/ig, '');
		if (hexstr.length == 3) {
		a = hexstr.split('');
	  } else if (hexstr.length == 6) {
		a = hexstr.match(/(\w{2})/g);
	  } else
		return hexstr;
	  for (i=0; i<a.length; i++) {
		if (a[i].length == 2)
		  a[i] = parseInt(a[i], 16);
		else {
		  a[i] = parseInt(a[i], 16);
		  a[i] = a[i]*16 + a[i];
	}}
	var maxColor = parseInt('ff', 16);
	function relsize(a) {
	  if (a == maxColor)
	  return Infinity;
	  return a/(maxColor-a);
	}
	function relsizeinv(y) {
	  if (y == Infinity)
	  return maxColor;
	  return maxColor*y/(1+y);
	}
	for (i=0; i<a.length; i++) {
	  a[i] = relsizeinv(relsize(a[i])*r);
	  a[i] = Math.floor(a[i]).toString(16);
	  if (a[i].length == 1)
	  a[i] = '0' + a[i];
	}
	return a.join('');
	}
	function colorTune(f,sca) {
	  var colorcell, hex, i, nhex;
	  hex = f;
	  hex = hex.replace(/\W/g, '');
	  nhex = colorscale(hex, sca-0);
	  if (nhex != hex) {return nhex;}
	};
	/*window.onbeforeunload = function (e) {
	if($("#naviFrame").attr('src')!=='/servContent/site_loading' ){
	  var e = e || window.event;

	  if (e) {
		$("#naviFrame").attr('src','/servContent/site_loading');
		//return alert("You're leaving MailEthio");
	  }
		$("#naviFrame").attr('src','/servContent/site_loading');
	  //return alert("You're leaving MailEthio");
	}
	};*/

	$("#custApply").click(function(){
		var cust_bg = $("#custBg").val();
		var main_col = $("#mColor").val();
		cust_bg = (cust_bg==''?'-':cust_bg);
		main_col = (main_col==''?'000':main_col);

		var color_1 = colorTune(main_col, '0.9');
		var color_2 = colorTune(main_col, '1.3');
		var color_4 = colorTune(main_col, '30');
		var pg_pos = $("#pgPos").attr("value");
		var qr_bg =  (cust_bg!=='-' ? '&pgbg=' + cust_bg : '');
		var themsel = 'func=theme&color1='+main_col+'&color2='+color_2+'&color3='+color_1+'&color4='+color_4+'&pgpos='+pg_pos+ qr_bg;
		$.post("/turnerM;_msess=9", themsel, function(){
			$("head").append('<link href="/wwwimgdn/___mcell_vg/media/css/swmzUq/vi-Main_style;en_us.css?'+Math.random()+'" type="text/css" rel="stylesheet">');
		});
		return false;
	});
	$(".selectTheme").click(function(){
		var cust_bg = $("#custBg").val();
		var main_col = $(this).attr("color");
		cust_bg = (cust_bg==''?'-':cust_bg);
		main_col = (main_col==''?'000':main_col);
		var color_1 = colorTune(main_col, '0.9');
		var color_2 = colorTune(main_col, '1.3');
		var color_4 = colorTune(main_col, '30');
		var pg_pos = $("#pgPos").attr("value");
		var qr_bg =  (cust_bg!=='-' ? '&pgbg=' + cust_bg : '');
		var themsel = 'func=theme&color1='+main_col+'&color2='+color_2+'&color3='+color_1+'&color4='+color_4+'&pgpos='+pg_pos + qr_bg;
		$.post("/turnerM;_msess=9", themsel, function(){
			$("head").append('<link href="/wwwimgdn/___mcell_vg/media/css/swmzUq/vi-Main_style;en_us.css?'+Math.random()+'" type="text/css" rel="stylesheet">');
		});
	});
/**customize -end**/
	$(function(){
		$("._yls-ra").sortable({ 
			connectWith: '._yls-ra',
			placeholder: 'ui-state-highlight',
			opacity: 0.6, 
			cursor: 'move', 
			update: function() {
				var order =	$("#_yls-ra1").sortable("serialize") + 
							'&' + $("#_yls-ra2").sortable("serialize") + '&' + 
							$("#_yls-ra3").sortable("serialize") + 
							'&func=url&spl1=' + $("#_yls-ra1 .tick7").size() + 
							'&spl3=' + $("#_yls-ra3 .tick7").size(); 
				$.post("/turnerM;_msess=9", order, function(mOutput){
					$("#ct").html(mOutput);
				}); 															 
			}								  
		});
	});
});

$(window).bind("resize", function(){  
	$("#pgDim").css("height", $(window).height());  
});  

