window.onload = function(e) { 
resizeimg(742,'postbody');
resizeimg(670,'blogpost');
// setInterval ( "TimerSwitch()", 20000 );
$Sw1 = 2;
}

//  *** TRIGGERS
$(function() {
	// Width toggle
	$("#nav-toggle").click( function() { toggleWidthType(this); } );
	$('.nocopy').disableSelection(); 
	$('.TTip1').tipsy({fade: true, gravity: 's'});
	LoadTip1('.TTip1');
});

function LoadTip1(TT)
{
	$('.TTip1').tipsy({fade: true, gravity: 's'});
}


// AJAX load content
function loadContent(id) {
			document.getElementById('contentArea').innerHTML='';
			document.getElementById('contentArea').className='load1';
			$("#contentArea").load(id,'',showContent);
}

function showContent()
{
	document.getElementById('contentArea').className='';
}



function TimerSwitch ()
{
	switch ($Sw1)
	{
		case 1:
		$Sw1 = 2;
		loadContent('http://www.egyoff.com/sys/latest_ftopics.php');
	 	ActvButt(document.getElementById('BTopic'),'BTopicOn');
		break;
		
		case 2:
		$Sw1 = 3;
		loadContent('http://www.egyoff.com/sys/vote_result.php');
		ActvButt(document.getElementById('BMem'),'BMemOn');
		break;
		
		case 3:
		$Sw1 = 1;
		loadContent('http://www.egyoff.com/sys/rss_tufoxy.php');
		ActvButt(document.getElementById('BTufoxy'),'BTufoxyOn');
		break;
	}
}

function ActvButt(nama, cname) {
document.getElementById('BMem').className='BMem';
document.getElementById('BMag').className='BMag';
document.getElementById('BTufoxy').className='BTufoxy';
document.getElementById('BTopic').className='BTopic';
nama.className=cname;
return true;
} 

// Width toggle
function toggleWidthType(elm) {
  $(elm).toggleClass("active");
  $("#page").toggleClass("nolimit");
  toggleCookieExistence("limitwidth");	
}

// Cookies
function toggleCookieExistence(name) {
    if ($.cookie(name)=="false") { $.cookie(name, null) } else { $.cookie(name, "false", { expires: 30 } )}
}


//  *** PLUGINS
// jQuery-Cookie
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }

};


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("يوجد خطأ فى البريد الإلكترونى.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("يوجد خطأ فى البريد الإلكترونى.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("يوجد خطأ فى البريد الإلكترونى.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("يوجد خطأ فى البريد الإلكترونى.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("يوجد خطأ فى البريد الإلكترونى.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("يوجد خطأ فى البريد الإلكترونى.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("يوجد خطأ فى البريد الإلكترونى.")
		    return false
		 }

 		 return true					
	}

function resizeimg(sze,cls)
{
  maxWidth = sze;		// maximum width of images in pixels

	var aDiv = document.getElementsByTagName('div');
	var n = 0;
	for (i=0; i<aDiv.length; i++) {
		if (aDiv[i].className == cls) {
			var aImg = aDiv[i].getElementsByTagName('img');
			for (j=0; j<aImg.length; j++) {
				if(aImg[j].width > maxWidth)
				{
			
				var nd = document.createElement('div');
				var iw = aImg[j].width + 17;
				var ih = aImg[j].height + 17;
				nd.className = "BBimgDiv";
				nd.innerHTML = "<div class='BBimgDiv2'>هذه الصورة مصغرة ,اضغط هنا لمشاهدتها بمقاسها الطبيعي علماً بأن مقاسها هو: "+iw+ "x"+ih+" بيكسل.</div><div id='resimg" + n + "' onclick=\"$.nyroModalManual({url: '" + aImg[j].src + "', minHeight:" + ih + ", minWidth:" + iw + "});\"></div>"
			
				aImg[j].parentNode.insertBefore(nd, aImg[j]);
				var dv = document.getElementById('resimg'+ n);
				dv.appendChild(aImg[j]);
				n ++;

				aImg[j].style.maxWidth = maxWidth + 'px';
				aImg[j].title = 'إضغط لتكبير الصورة للحجم الطبيعى.';
			
				}
			}
		}
	}
}


var ddsmoothmenu={

transition: {overtime:300, outtime:300}, //duration of slide in/ out animation, in milliseconds

///////Stop configuring beyond here///////////////////////////

detectwebkit: navigator.userAgent.toLowerCase().indexOf("applewebkit")!=-1, //detect WebKit browsers (Safari, Chrome etc)

getajaxmenu:function($, setting){ //function to fetch external page containing the panel DIVs
	var $menucontainer=$('#'+setting.contentsource[0]) //reference empty div on page that will hold menu
	$menucontainer.html("Loading Menu...")
	$.ajax({
		url: setting.contentsource[1], //path to external menu file
		async: true,
		error:function(ajaxrequest){
			$menucontainer.html('Error fetching content. Server Response: '+ajaxrequest.responseText)
		},
		success:function(content){
			$menucontainer.html(content)
			ddsmoothmenu.buildmenu($, setting)
		}
	})
},


buildmenu:function($, setting){
	var smoothmenu=ddsmoothmenu
	var $mainmenu=$("#"+setting.mainmenuid+">ul") //reference main menu UL
	var $headers=$mainmenu.find("ul").parent()
	$headers.hover(
		function(e){
			$(this).children('a:eq(0)').addClass('selected')
		},
		function(e){
			$(this).children('a:eq(0)').removeClass('selected')
		}
	)
	$headers.each(function(i){
		var $curobj=$(this).css({zIndex: 100-i}) //reference current LI header
		var $subul=$(this).find('ul:eq(0)').css({display:'block'})
		this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
		this.istopheader=$curobj.parents("ul").length==1? true : false //is top level header?
		$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
		
		$curobj.hover(
			function(e){
				var $targetul=$(this).children("ul:eq(0)")
				this._offsets={left:$(this).offset().left, top:$(this).offset().top}
				var menuleft=this.istopheader? 0 : -this._dimensions.w
				menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft //calculate this sub menu's offsets from its parent
				menuleft = menuleft - this._dimensions.subulw + this._dimensions.w - 1;
				if ($targetul.queue().length<=1){ //if 1 or less queued animations
					$targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).animate({height:'show',opacity:'show'}, ddsmoothmenu.transition.overtime)
					
				}
			},
			function(e){
				var $targetul=$(this).children("ul:eq(0)")
				$targetul.animate({height:'hide', opacity:'hide'}, ddsmoothmenu.transition.outtime)
			}
		) //end hover
	}) //end $headers.each()
	$mainmenu.find("ul").css({display:'none', visibility:'visible'})
},

init:function(setting){
	if (typeof setting.customtheme=="object" && setting.customtheme.length==2){
		var mainmenuid='#'+setting.mainmenuid
		document.write('<style type="text/css">\n'
			+mainmenuid+', '+mainmenuid+' ul li a {background:'+setting.customtheme[0]+';}\n'
			+mainmenuid+' ul li a:hover {background:'+setting.customtheme[1]+';}\n'
		+'</style>')
	}
	jQuery(document).ready(function($){ //override default menu colors (default/hover) with custom set?
		if (typeof setting.contentsource=="object"){ //if external ajax menu
			ddsmoothmenu.getajaxmenu($, setting)
		}
		else{ //else if markup menu
			ddsmoothmenu.buildmenu($, setting)
		}
	})
}

} //end ddsmoothmenu variable

//Initialize Menu instance(s):

ddsmoothmenu.init({
	mainmenuid: "smoothmenu1", //menu DIV id
	//customtheme: ["#1c5a80", "#18374a"], //override default menu CSS background values? Uncomment: ["normal_background", "hover_background"]
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

// Disable Selection
jQuery.fn.extend({ 
        disableSelection : function() { 
			$(this).bind('mousedown mouseup mouseenter mouseleave', function() {
				 document.selection.empty();
				 return false;
			});

           this.each(function() { 
					$(this).css('-moz-user-select', 'none'); 
			 		$(this).css('cursor','default'); 
                    this.onselectstart = function() { return false; }; 
					this.ondragstart = function() { return false; }; 
           }); 
        } 
}); 


<!--
// Ticker startup
function startTicker()
{
 // Define run time values
 theCurrentStory	 = -1;
 theCurrentLength	= 0;
 // Locate base objects
 if (document.getElementById) { 
	  theAnchorObject	 = document.getElementById("tickerAnchor");
   runTheTicker();	
   }
 else {
			document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
			return true;
 }
}
// Ticker main run loop
function runTheTicker()
{
 var myTimeout;  
 // Go for the next story data block
 if(theCurrentLength == 0)
 {
  theCurrentStory++;
  theCurrentStory	  = theCurrentStory % theItemCount;
  theStorySummary	  = theSummaries[theCurrentStory].replace(/"/g,'"');  
  theTargetLink		= theSiteLinks[theCurrentStory];
  theAnchorObject.href = theTargetLink;
  thePrefix 	  = "<span class=\"tickls\">" + theLeadString + "</span>";
 }
 // Stuff the current ticker text into the anchor
 theAnchorObject.innerHTML = thePrefix + 
 theStorySummary.substring(0,theCurrentLength) + whatWidget();
 // Modify the length for the substring and define the timer
 if(theCurrentLength != theStorySummary.length)
 {
  theCurrentLength++;
  myTimeout = theCharacterTimeout;
 }
 else
 {
  theCurrentLength = 0;
  myTimeout = theStoryTimeout;
 }
 // Call up the next cycle of the ticker
 setTimeout("runTheTicker()", myTimeout);
}
// Widget generator
function whatWidget()
{
 if(theCurrentLength == theStorySummary.length)
 {
  return theWidgetNone;
 }

 if((theCurrentLength % 2) == 1)
 {
  return theWidgetOne;
 }
 else
 {
  return theWidgetTwo;
 }
}
// -->