/* CONFIGURATION AREA */
/*
	browsers:
		IE - Microsoft Internet Explorer
		FF - FireFox
		Safari - Safari browser
		Opera - Opera browser
		all - includes IE, FF, Opera and Safari
		
	id:
		any existing Id attribute 
	setBack:
		specify if the script should return default value if the field is empty
*/

var popup_url = '/_modules/memberpop.php';

var browsers = 'all';
var config = {
	inputFields:new Array(
		{
			id:'search',
			setBack:true
		}
	)
};

var isLinkHover = false;
var isPopupHover = false;

/* CODE AREA */

/* inputFields */

var initInputFields = function()
{
	currentState.inputFields = new Array();

	for (var index in config.inputFields){
		var conf = config.inputFields[index];
		var el = document.getElementById(conf.id);
		if (el){
			el.configIndex = index;
			currentState.inputFields[index] = el.value;
			el.onfocus = function(){
				var prevValue = currentState.inputFields[this.configIndex]; 
				if (this.value == prevValue){
					this.value = '';
				}
			}
			if (conf.setBack){
				el.onblur = function(){
					var prevValue = currentState.inputFields[this.configIndex];
					if (this.value == ''){
						this.value = prevValue;
					}
				}
			}
		}
	}
}

/* common */

var currentState = {};

var opera = window.opera;
var safari = navigator.appVersion.indexOf("Safari") != -1;
var ie = document.all && !window.opera;
var ff = navigator.userAgent.indexOf("Firefox") != -1;

var addEvent = function(browsers,event,initMethod)
{
	if (opera && (browsers.match(/Opera/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (safari && (browsers.match(/Safari/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (ie && (browsers.match(/IE/) || browsers.match(/all/))) {
		window.attachEvent("on" + event, initMethod);
	} else if (ff && (browsers.match(/FF/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (!ie && !ff && !safari && !opera) {
		if (window.addEventListener){
			window.addEventListener(event, initMethod, false);
		}
		else if (window.attachEvent){
			window.attachEvent("on" + event, initMethod);
		}
	} 
}

var CheckHovers = function()
{
	var popup = document.getElementById('popup');
	if( !isPopupHover && !isLinkHover ){
		popup.style.display = 'none';
	}
}

var initPopup = function()
{
	var pageWidth = document.body.clientWidth;
	var popup = document.getElementById('popup');
	if (pageWidth < 1054){
		popup.style.left='458px'
	}
	else{
		popup.style.left=eval((pageWidth-1054)/2+458) + 'px';
	}
	
	
	
	var links = document.getElementsByTagName('a');
	for(var i=0;i<links.length;i++){
		if(links[i].getAttribute('rel')){
			if(links[i].getAttribute('rel')=='popup-link'){
				links[i].onmouseover = function(){
					var id = this.id.substring(6);
					isLinkHover = true;
					var offset = $(this).offset();
					var length = $(this).width();
					var left_offset = offset.left + length;
					var top_offset = offset.top - 80;
					popup.style.left = left_offset+'px';
					popup.style.top = top_offset+'px';
					$(popup).load(popup_url+'?id='+id);
					popup.style.display = 'block';
				}
				links[i].onmouseout = function(){
					isLinkHover = false;
					setTimeout('CheckHovers()',500);
				}
			}
		}
	}
	popup.onmouseover = function(){
		isPopupHover = true;
	}
	popup.onmouseout = function(){
		isPopupHover = false;
		setTimeout('CheckHovers()',500);
	}
}

addEvent(browsers,'load',initInputFields);
addEvent(browsers,'load',initPopup);
addEvent(browsers,'resize',initPopup);
addEvent(browsers,'load',initNav);


$(document).ready(function(){
	//initAccordion();
	initSliding();
	initSliding2();
	initSliding3();
	initSliding4();
	//loadAjaxedAnswers('0');
});

var initAccordion = function(){
	$('.jobs').accordion({
		active: 1,
		header: '.jobs-h',
		autoHeight: false,
		alwaysOpen: false
	});
}

var initSliding = function(){
	var links = $('.feat-top ul li a');
	//var contents = $('.feat-bot .feat-cont');
	var container = $('#container'); 
	var content = $('#scroll-content');
	

	container.css('height', '265px');
	container.css('overflow', 'hidden')
	
	links.parent().removeClass('active');
	
	$(links[0]).parent().addClass('active')
	
	links.click(function(e){
		e.preventDefault();
		var i = links.index(this);

		links.parent().removeClass('active');
		$(this).parent().addClass('active');
		
		slideTo(content, i, 265);
	});
}

var initSliding2 = function(){
	var links = $('.feat3-top ul li a');
	
	var container = $('#featured3-container'); 
	var content = $('#featured3-scroll-content');
	

	container.css('height', '463px');
	container.css('overflow', 'hidden')
	
	links.parent().removeClass('active');
	
	$(links[0]).parent().addClass('active')
	
	links.click(function(e){
		e.preventDefault();
		var i = links.index(this);

		links.parent().removeClass('active');
		$(this).parent().addClass('active');
		
		slideTo(content, i, 463);
		var tid=document.getElementById('anlist').value;
		if(i == 0) loadAjaxedAnswers('0',tid);

	});
}

var initSliding3 = function(){
	var links = $('.map-top ul li a');
	
	var container = $('#map-container'); 
	var content = $('#map-scroll-content');
	

	container.css('height', '400px');
	container.css('overflow', 'hidden')
	
	links.parent().removeClass('active');
	
	$(links[0]).parent().addClass('active')
	
	links.click(function(e){
		//e.preventDefault();
		var i = links.index(this);

		links.parent().removeClass('active');
		$(this).parent().addClass('active');

		var m = i + 1;
		loadedMap(m);
	});
}

var initSliding4 = function(){
	var links = $('.feat2-top ul li a');
	//var contents = $('.feat-bot .feat-cont');
	var container = $('#featured2-container'); 
	var content = $('#featured2-scroll-content');
	

	container.css('height', '1200px');
	container.css('overflow', 'hidden')
	
	links.parent().removeClass('active');
	
	$(links[0]).parent().addClass('active')
	
	links.click(function(e){
		e.preventDefault();
		var i = links.index(this);
		links.parent().removeClass('active');
		$(this).parent().addClass('active');
		
		slideTo(content, i, 1200);
		
	});
}

var slideTo = function(content, i, pxls){
		content.animate({
          marginTop: "-"+i*pxls+"px"
      }, 1000);
}

function initNav()
{
	if (typeof document.body.style.maxHeight == 'undefined')
	{
		var nav = document.getElementById("menu");
		if(nav)
		{
			var lis = nav.getElementsByTagName("li");
			for (var i=0; i<lis.length; i++)
			{
				lis[i].onmouseover = function()
				{
					this.className += " hover";
				}
				lis[i].onmouseout = function()
				{
					this.className = this.className.replace(" hover", "");
				}
			}
		}
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function selectAll(formObj, isInverse) 
{
   for (var i=0;i < formObj.length;i++) 
   {
      fldObj = formObj.elements[i];
      if (fldObj.type == 'checkbox')
      { 
         if(isInverse)
            fldObj.checked = (fldObj.checked) ? false : true;
         else fldObj.checked = true; 
       }
   }
}

function postJob()
{
	GB_showCenter('Post A Job', 'http://www.myworkster.com/mainb.php?p=jobopportunity', 500, 500);
}

function getJob(id)
{
	GB_showCenter('Job Opportunity', 'http://www.myworkster.com/mainb.php?p=jobinfo&id='+id, 500, 500);
}

function getEvent(id)
{
	GB_showCenter('Event Info', 'http://www.myworkster.com/mainb.php?p=eventinfo&id='+id, 450, 450);
}

//Network Confirms

function leaveNetwork(id) {
	var answer=confirm("Are you sure you want to leave this network?")
	if(answer)
	window.location="/member/secondary/&mode=leave&id="+id
}

function joinNetwork(id) {
	var answer=confirm("Are you sure you want to join this network?")
	if(answer)
	window.location="/member/secondary/&mode=join&id="+id
}

//Contact Confirms

function addContact(id) {
	var answer=confirm("Add this member to your contacts?")
	if(answer)
	window.location="/main.php?p=friends&mode=add&id="+id
}

function deleteContact(id) {
	var answer=confirm("Remove this member from your contacts?")
	if(answer)
	window.location="/main.php?p=networks&mode=contacts&a=delete&del_id=" + id;
}

//Group Confirms

function joinGroup(id) {
	var answer=confirm("Are you sure you want to join this group?")
	if(answer)
	window.location="/main.php?p=groups&mode=info&a=join&id="+id
}

function leaveGroup(id) {
	var answer=confirm("Are you sure you want to leave this group?")
	if(answer)
	window.location="/main.php?p=groups&mode=leave&id="+id
}

function deleteGroup(id) {
	var answer=confirm("Are you sure you want to delete this group?")
	if(answer)
	window.location="/main.php?p=groups&mode=own&a=delete&gid="+id
}

function deleteEndorse(id, post) {
	var answer=confirm("Are you sure you want to delete this post?")
	if(answer)
	window.location="/main.php?p=groups&mode=info&a=deletepost&id="+id+"&postid="+post
}

function deleteJob(id) {
	var answer=confirm("Are you sure you want to delete this job?")
	if(answer)
	window.location="/main.php?p=jobs&mode=delete&id="+id
}

function deleteAccount(id)
{
Modalbox.show('<div class=\'warning\'><p>Are you sure you want to delete your account? </p> <input type=\'button\' value=\'Yes\' onClick=\'deleteAccounts()\' /> or <input type=\'button\' value=\'No\' onclick=\'Modalbox.hide()\' /></div>',{title: this.title, width: 300});
}

function deleteAccounts()
{
	window.location = "/main.php?p=editprofile&sub=account&a=delete"
}

function applyForJob( id )
{
	var answer = confirm( "Are you sure you want to apply for this job? Your direct link will be sent to the employer for access to your credentials and profile." )
	if(answer)
	window.location = "/member/jobs/&mode=view&id="+id+"&a=apply"
}

function removeEndorsement( user_id, id )
{
	var answer = confirm( "Are you sure you want to delete this endorsement?" )
	
	if( answer )
	{
		window.location = "/profile.php?mode=delete&id="+user_id+"&mid=" + id + "#endorse";
	}
}


function deleteYSolution(id, sid)
{
	var answer = confirm( "Are you sure you want to delete this solution?" )
	
	if( answer )
	{
		window.location = "/member/solutions/answers/&id="+id+"&action=delete&sid=" + sid;
	}
}

function deleteNetwork(id) {
	var answer=confirm("Are you sure you want to delete this network?")
	if(answer)
	window.location="/?p=viewnetworks&a=delete&id=" + id;
}

function showMe (it, box) {
  var vis = (box.checked) ? "block" : "none";
  document.getElementById(it).style.display = vis;
}

function CopyToClipboard()

{

   document.Form1.profileL.focus();

   document.Form1.profileL.select();

   CopiedTxt = document.selection.createRange();

   CopiedTxt.execCommand("Copy");

}

