	var loggedIn = false;
	var loggedInUserName = jQuery.cookies.get("user_name");

	// send user to my page if it the login information saved but user is not logged in
	if (jQuery.cookies.get("login") == null && jQuery.cookies.get("rememberme") == "true") {
		window.location.href = "/member/loginRedirect.do";
	}
	
	if (jQuery.cookies.get("login") != null) {
		loggedIn = true;
	} 
	
	function loadNewsTicker() {
		jQuery.getJSON("/servlet/ajax/newsTicker",{newsCount:50},renderNewsTicker);
	}
	
	function renderNewsTicker(data) {
		var newsHtml = "";
		jQuery.each(data.news,
			   function(i,value){
			   		newsHtml += '<div class="sNewsLine">';
			   		newsHtml += '<a href="' + value.link + '" ';
			   		if (value.bold)
			   			newsHtml += 'style="color: ' + value.color + '; font-weight: bold;" ';
			   		else
			   			newsHtml += 'style="color: ' + value.color + ';" ';
			   		newsHtml += 'target="_blank">' + value.title + '</a></div>';
			   }
		);
		jQuery('#sNews').append(newsHtml);
		startNewsTicker();
	}
	
	function startNewsTicker() {	
		jQuery(function( $ ){
			var news = jQuery('#sNews');
			news.serialScroll({
				items:'div',
				duration:2000,
				force:true,
				axis:'y',
				easing:'linear',
				lazy:true,// NOTE: it's set to true, meaning you can add/remove/reorder items and the changes are taken into account.
				interval:5000, // yeah! I now added auto-scrolling
				step:1, // scroll 1 news each time
				cycle:false,
				onAfter:function(currentNews){
					jQuery('#sNews').append('<div class="sNewsLine">'+jQuery(currentNews).html()+'</div>');
				}
			});	
		});
	}
	
	var focusFlag = false;
	function setFocusFlag(flag) {
		focusFlag = flag;
	}
	
	function submitSearch() {
		if (focusFlag && document.skres_h_search_form.name.value != "") {
			document.skres_h_search_form.submit();
		} else {
			window.location = "/searchResult.do?type=member";
		}
	}
		
	var notificationIconObjIds = ['skres_t1on1Tab','skres_tFriendsLiveTab','skres_tNotificationTab'];
	var notificationIconActiveObjIds = ['skres_t1on1TabActive','skres_tFriendsLiveTabActive','skres_tNotificationTabActive'];
	var notificationLayerIds = ['skres_t1on1','skres_tFriendsLive','skres_tNotification'];
	
	function loadOne2OneLayer() {
		invitationLayerOpen = true;
		var one2OneIFrame= document.getElementById("iframeOne2One");
		if (one2OneIFrame)
			one2OneIFrame.src = "/invitation/index.do";
	}
	
	function unloadOne2OneLayer() {
		invitationLayerOpen = false;;
		var one2OneIFrame= document.getElementById("iframeOne2One");
		if (one2OneIFrame)
			one2OneIFrame.src = "";
			
		getInvitationNotification();
	}
	
	function showNotificationLayer(notificationIconObjId,notificationIconActiveObjId,notificationLayerId) {
		hideNotificationLayers();
		
		if (notificationIconObjId == 'skres_t1on1Tab')
			loadOne2OneLayer();
		else if (invitationLayerOpen)
			unloadOne2OneLayer();	
		
		var notificationIconObj = document.getElementById(notificationIconObjId);
	    if (notificationIconObj)
	        notificationIconObj.style.display="none";
	        
		var notificationIconActiveObj = document.getElementById(notificationIconActiveObjId);
	    if (notificationIconActiveObj)
	        notificationIconActiveObj.style.display="block";
	        
		var NotificationLayer = document.getElementById(notificationLayerId);
	        if (NotificationLayer)
	        	NotificationLayer.style.display="block";
	}
	
	function hideNotificationLayers() {
		notificationLayerOpen = false;
		liveFriendsLayerOpen = false;
		
	    for (i = 0; i < notificationLayerIds.length; ++i) {
			var notificationLayer = document.getElementById(notificationLayerIds[i]);
	        if (notificationLayer)
	        	notificationLayer.style.display="none";
	    }
	    
	    for (i = 0; i < notificationIconObjIds.length; ++i) {
			var notificationIconObj = document.getElementById(notificationIconObjIds[i]);
	        if (notificationIconObj)
	        	notificationIconObj.style.display="block";
	    }
	    
	    for (i = 0; i < notificationIconActiveObjIds.length; ++i) {
			var notificationIconActiveObj = document.getElementById(notificationIconActiveObjIds[i]);
	        if (notificationIconActiveObj)
	        	notificationIconActiveObj.style.display="none";
	    }
	}
    
    function showHint(hintDivId){
    	var hintDiv = document.getElementById(hintDivId);
    	if (hintDiv)
    		hintDiv.style.display="block";
    }
    
    function hideHint(hintDivId){
    	var hintDiv = document.getElementById(hintDivId);
    	if (hintDiv)
    		hintDiv.style.display="none";
    }
    
    //*************************************************************************************************************
    
    
    var notificationLayerOpen = false;
	var liveFriendsLayerOpen = false;
	
    var notificationTimer;
    
    var notificationCounter = 0;
	
	var currentLatestNotificationId = 0;
	var storedLatestNotificationId = jQuery.cookies.get("notificationId_" + loggedInUserName);
	
	var currentLatestLiveFriendId = 0;
	var storedLatestLiveFriendId = jQuery.cookies.get("liveFrindsId_" + loggedInUserName);
		
	function setNotificationCookie(){
		var nextYear = new Date();
		nextYear.setFullYear(nextYear.getFullYear()+1);
		var cookieName = "notificationId_" + loggedInUserName;
		document.cookie= cookieName + "=" + currentLatestNotificationId + ";version=" + document.lastModified + ";expires=" + nextYear.toGMTString() + ";path=/";// + ";domain=stickam.com;";
		
		var notificationTabDiv = document.getElementById('skres_tNotificationTab');
		if (notificationTabDiv) {
			notificationTabDiv.innerHTML = '<a class="skres_aTab" href="javascript:;" onClick="setNotificationCookie();showNotificationLayer(\'skres_tNotificationTab\',\'skres_tNotificationTabActive\',\'skres_tNotification\');notificationLayerOpen=true;" onmouseover="showHint(\'notificationHint\');" onmouseout="hideHint(\'notificationHint\');">'
										 + '<img width="16" height="16" border="0" src="/images/en/header/notification.gif"></a>'
										 + '<div id="notificationHint" class="skres_menuHint" style="display:none;">Notification</div>';
		}
	}
	
	function setLiveFriendsCookie(){
		var nextYear = new Date();
		nextYear.setFullYear(nextYear.getFullYear()+1);
		var cookieName = "liveFriendId_" + loggedInUserName;
		document.cookie = cookieName + "=" + currentLatestLiveFriendId + ";version=" + document.lastModified + ";expires=" + nextYear.toGMTString() + ";path=/";// + ";domain=stickam.com;";
		
		var friendsLiveTabDiv = document.getElementById('skres_tFriendsLiveTab');
		if (friendsLiveTabDiv) {
			friendsLiveTabDiv.innerHTML = '<a class="skres_aTab" href="javascript:;" onClick="setLiveFriendsCookie();showNotificationLayer(\'skres_tFriendsLiveTab\',\'skres_tFriendsLiveTabActive\',\'skres_tFriendsLive\');liveFriendsLayerOpen=true;" onmouseover="showHint(\'liveFriendsHint\');" onmouseout="hideHint(\'liveFriendsHint\');">'
										+ '<img width="16" height="16" border="0" src="/images/en/header/livefriends.gif"></a>'
										+ '<div id="liveFriendsHint" class="skres_menuHint" style="display:none;">Live Friends</div>';
		}
	}
	
	function setUserNotificationResponse(data){
		var response = JSON.stringify(data);
 		var cookieName = "userNotification_" + loggedInUserName;
		jQuery.cookies.set(cookieName, response, {path: "/", hoursToLive: 1/30});
	}

	function getUserNotificationResponse(){
		var data = null;
		var response = jQuery.cookies.get("userNotification_" + loggedInUserName);
		if (response != null)
			data = JSON.parse(response);
		return data;
	}
	
	function getUserNotification() {
		var userNotificationResponse = getUserNotificationResponse();

		if (userNotificationResponse == null) {
			notificationCounter++;
			// if page is left open for more than 6 hours
			if (notificationCounter < 180) {
				var now = new Date();
				var sig = jQuery.cookies.get("login") + now.getTime();
				jQuery.getJSON("/servlet/ajax/getNotifications",{sig:sig},completeUserNotification);
			} else {
				document.location.href = "/logout.do";
			}
		}
		else {
			showUserNotification(userNotificationResponse);
		}
		notificationTimer = setTimeout("getUserNotification()",120000);
	}
	
	function completeUserNotification(data){
		setUserNotificationResponse(data);
		showUserNotification(data);
	}
	
	function showUserNotification(data) {
		if(data.loggedIn == 'true') {							
			var notificationsId = data.notificationsId;
			var notificationsIcon = data.notificationsIcon;
			var notificationsMessage = data.notificationsMessage;
			var notificationsTime = data.notificationsTime;
					
			var liveFriendsCount = data.liveFriendsCount;
			var userIds = data.userIds;
			var userNames = data.userNames;
			var screenNames = data.screenNames;
			var imageNames = data.imageNames;
								
			replaceContent(notificationsId, notificationsIcon, notificationsMessage, notificationsTime, liveFriendsCount, userIds, userNames, screenNames, imageNames);								
		} else {
			clearTimeout(notificationTimer);
		}	
	}
	
	function replaceContent(notificationsId, notificationsIcon, notificationsMessage, notificationsTime, liveFriendsCount, userIds, userNames, screenNames, imageNames) {
		
		// Updating User Notification Layer
		var notificationDiv = document.getElementById('skres_tNotification');
		if (notificationDiv) {
			var newHTML = '<div id="skres_tNotificationTitle" class="skres_tBoxTitle"><a href="javascript:;" onClick="hideNotificationLayers();"><span>-</span>Notification</a></div>'
						+ '<div class="skres_tNotificationBody">';
			if (notificationsId.length > 0) {
				for (i = 0; i < notificationsId.length; ++i) {
					var notificationTime = Date.parse(notificationsTime[i]);
					var notificationDate = new Date();
					notificationDate.setTime(notificationTime);
					newHTML += '<div class="skres_tNotificationCell"><div class="skres_tNotificationIcon"><img src="/images/en/header/' + notificationsIcon[i] + '.gif" width="16" height="16" border="0"></div>' 
							+ '<div class="skres_tNotificationR">' + notificationsMessage[i] + '<span>&nbsp;on&nbsp;' + notificationDate.formatDate("l, g:i A") + '</span></div></div>';
				}
			} else {
				newHTML += '<div class="skres_tNotificationCell">No New Notifications</div>';
			}
			newHTML += '</div>';
			newHTML += '<div class="skres_tNotificationSeeAll"><a href="/member/notifications.do">view all</a></div>'
			notificationDiv.innerHTML = newHTML;
		}
			
			// keep id of latest notification in the cookie for later comparison
			if (notificationsId.length > 0) {
				currentLatestNotificationId = notificationsId[0];
				storedLatestNotificationId = getCookie("notificationId_" + loggedInUserName);
				if (notificationLayerOpen) {
					setNotificationCookie();
				} else {
					if (storedLatestNotificationId == "" || storedLatestNotificationId < currentLatestNotificationId) {
						var notificationTabDiv = document.getElementById('skres_tNotificationTab');
						if (notificationTabDiv) {
							notificationTabDiv.innerHTML = '<a class="skres_aTab" href="javascript:;" onClick="setNotificationCookie();showNotificationLayer(\'skres_tNotificationTab\',\'skres_tNotificationTabActive\',\'skres_tNotification\');notificationLayerOpen=true;" onmouseover="showHint(\'notificationHint\');" onmouseout="hideHint(\'notificationHint\');">'
														 + '<img width="16" height="16" border="0" src="/images/en/header/notification_blink.gif"></a>'
										 				 + '<div id="notificationHint" class="skres_menuHint" style="display:none;">Notification</div>';
						}
					}
				}
			}
			
			
	
		// Updating Live frinds Layer	
		var friendsLiveDiv = document.getElementById('skres_tFriendsLive');
		if (friendsLiveDiv)	{
			friendsLiveDiv.innerHTML = '<div id="skres_tFriendsLiveTitle" class="skres_tBoxTitle"><a href="javascript:;" onClick="hideNotificationLayers();"><span>-</span>Live Friends</a></div>';
			if (liveFriendsCount > 0) {
				for (i = 0; i < userNames.length; ++i) { 
					friendsLiveDiv.innerHTML += '<div class="skres_tFlRow"><div class="skres_tFlPix">' +
												'<a href="/'+userNames[i]+'"><img src="'+imageNames[i]+'" width="40" height="30"></a></div>' +
												'<div class="skres_tFlName"><a href="/'+userNames[i]+'">'+screenNames[i]+'</a></div>' +
												'<div class="skres_tFlLiveIcon"><a href="javascript:;" onclick="MM_openBrWindow(\'/largeChat.do?uId='+userIds[i]+'\',\'member_big_vchat_'+userIds[i]+'\',\'width=550,height=630\')" title="live">Live</a></div>' +
												'</div>';
				}
				friendsLiveDiv.innerHTML += '<div class="skres_tFlSeeAll"><a href="/member/liveStream.do?filter=friends">view all (' + liveFriendsCount + ')</a></div>';
				
				currentLatestLiveFriendId = userIds[0];
				storedLatestLiveFriendId = getCookie("liveFriendId_" + loggedInUserName);
				if (liveFriendsLayerOpen) {
					setLiveFriendsCookie();
				} else {
					if (storedLatestLiveFriendId == "" || storedLatestLiveFriendId != currentLatestLiveFriendId) {
						var friendsLiveTabDiv = document.getElementById('skres_tFriendsLiveTab');
						if (friendsLiveTabDiv) {
							friendsLiveTabDiv.innerHTML = '<a class="skres_aTab" href="javascript:;" onClick="setLiveFriendsCookie();showNotificationLayer(\'skres_tFriendsLiveTab\',\'skres_tFriendsLiveTabActive\',\'skres_tFriendsLive\');liveFriendsLayerOpen=true;" onmouseover="showHint(\'liveFriendsHint\');" onmouseout="hideHint(\'liveFriendsHint\');">'
														+ '<img width="16" height="16" border="0" src="/images/en/header/livefriends_blink.gif"></a>'
														+ '<div id="liveFriendsHint" class="skres_menuHint" style="display:none;">Live Friends</div>';
						}
					}
				}
			} else {
				friendsLiveDiv.innerHTML += '<div class="skres_tFlRow"><center><b>No Live Friends</b></center></div>';
			}
		}
	}
	
	
	