function findFirstListLink(ele)
{
	var c = ele.find('ul li').size();
	if(c > 0)
	{
		var i = 0;
		//for(var i=0; i < c; i++)
		{
			if(ele.find('ul li:eq('+i+') a[href!="'+site_url+'"]').size() > 0)
			{
				return findFirstListLink(ele.find('ul li:eq('+i+')'));
				//break;
			}
		}
	}
	else
	{
		return ele.find('a').attr('href');
	}
	return false;
}

function increment(current, increment, count)
{
	current+=increment;
	if(current == count)
	{
		return 0;
	}
	else if(current < 0)
	{
		return count-1;
	}
	return current;
}

function getSegs(str, start, end, delimiter)
{
	if(delimiter == null)
	{
		delimiter = '/';
	}
	if(str != null)
	{
		var pa = str.split(delimiter);
		if(pa.length > 0)
		{
			if(end == null)
			{
				pa = pa.slice(start);
			}
			else
			{
				pa = pa.slice(start, end);
			}
		}
		return pa.join(delimiter);
	}
	return str;
}

function str_array(str, delimiter)
{
	if(str == null)
	{
		str = '';
	}
	if(delimiter == null)
	{
		delimiter = ',';
	}
	var a = [];
	if(str!="")
	{
		 a = str.split(delimiter);
	}
	return a;
}

function array_str(a, delimiter)
{
	if(a == null)
	{
		a = [];
	}
	if(delimiter == null)
	{
		delimiter = ',';
	}
	return a.join(delimiter);
}

function popSegs(str, popNum, delimiter)
{
	if(delimiter == null)
	{
		delimiter = '/';
	}
	if(str != null)
	{
		var pa = str.split(delimiter);
		if(pa.length > 1)
		{
			pa = pa.slice(0, (0-popNum));
			return pa.join(delimiter);
		}
	}
	return str;
}

function lastSeg(str, delimiter)
{
	if(delimiter == null)
	{
		delimiter = '/';
	}
	if(str != null)
	{
		var pa = str.split(delimiter);
		if(pa.length > 1)
		{
			return pa.pop();
		}
	}
	return str;
}

function removeEmpty(a)
{
	var rtn = [];
	for (i=0; i<a.length; i++)
	{
		var item = a[i]+'';
		if(item != '' && item != ' ' && item.length > 0)
		{
			rtn.push(item);
		}
	}
	return rtn;
}

var aHAtt = 'data-aH';
var aWAtt = 'data-aW';

function removeActualHeight(item)
{
	item.removeAttr(aHAtt);
}

//stores the actual height as a property
function actualHeight(item)
{
	var r = data(item, aHAtt, item.height());
	
	//set default actual height
	item.height(r*1);
	
	return r*1;
}

function getActualHeight(item)
{
	var r = data(item, aHAtt);	
	if(r)
	{
		return r*1;
	}
	return false;
}

function setActualHeight(item, val)
{
	//defined actual height of before resize
	data(item, aHAtt, val, true);
}

function removeActualHeight(item)
{
	item.removeAttr(aHAtt);
}

function setActualWidth(item, val)
{
	//defined actual height of before resize
	data(item, aWAtt, val, true);
}

function getActualWidth(item)
{
	var r = data(item, aWAtt);
	if(r)
	{
		return r*1;
	}
	return false;
}

function removeActualWidth(item)
{
	item.removeAttr(aWAtt);
}

//stores the actual width as a property
function actualWidth(item)
{
	var r = data(item, aWAtt, item.width(), false);
	
	//set default actual height
	item.width(r*1);
	
	return r*1;
}

function data(item, att, val, add)
{
	//get value
	if(att.indexOf('data-') < 0)
	{
		att = 'data-'+att;
	}
	var r = item.attr(att);
	
	//if is undefined
	if(r == undefined || (val != null && add != null && add == true))
	{
		//if att is height or width
		r = val;
		if(r != null)
		{
			//set att
			item.attr(att, r);
		}
	}
	return r;
}

function getNumber(item, att)
{
	return item.attr(att)*1;
}

function pixelToNum(pixel)
{
	if(pixel != undefined)
	{
		return (pixel.replace('px', ''))*1;
	}
	return 0;
}

//where o, is container
//and n, is new object
function ratio(ow, oh, nw, nh, flag)
{
	var fac = 0;
    if((nw > ow && flag == null) || flag == "height")
	{
		h = ow*(nh/nw);
		w = ow;
		if(h > oh)
		{
			ratio(ow, oh, nw, nh, "width");
		}
	}
    else if((nh > oh && flag == null) || flag == "width")
	{
    	w = oh*(nw/nh);
		h = oh;
		if(w > ow)
		{
			ratio(ow, oh, nw, nh, "height");
		}
	}
    else
    {
    	w = nw;
    	h = nh;
    }
    
    w = Math.floor(w);
    h = Math.floor(h);
    
    return [w, h];
}


