var jqueryslidemenu = {

    animateduration: { over: 200, out: 100 }, //duration of slide in/ out animation, in milliseconds

    buildmenu: function(menuid) {
        jQuery(document).ready(function($) {
            var $mainmenu = $("#" + menuid + ">ul")
            var $headers = $mainmenu.find("ul").parent()
            $headers.each(function(i) {
                var $curobj = $(this)
                var $subul = $(this).find('ul:eq(0)')
                this._dimensions = { w: this.offsetWidth, h: this.offsetHeight, subulw: $subul.outerWidth(), subulh: $subul.outerHeight() }
                this.istopheader = $curobj.parents("ul").length == 1 ? true : false
                $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
				    if ($targetul.queue().length <= 1) //if 1 or less queued animations
				        $targetul.css({ left: menuleft + "px", width: this._dimensions.subulw + 'px' }).slideDown(jqueryslidemenu.animateduration.over)
				},
				function(e) {
				    var $targetul = $(this).children("ul:eq(0)")
				    $targetul.slideUp(jqueryslidemenu.animateduration.out)
				}
			) //end hover
            }) //end $headers.each()
            $mainmenu.find("ul").css({ display: 'none', visibility: 'visible' })
        }) //end document.ready
    }
}

// build menu
jqueryslidemenu.buildmenu("nav");


function showLayer(layerName, shadowLayerName)
{
    if (document.getElementById) // Netscape 6 and IE 5+
    {
        var targetElement = document.getElementById(layerName);
        targetElement.style.visibility = 'visible';

    }
}  

function hideLayer(layerName)
{
   if (document.getElementById)
   {
       var targetElement = document.getElementById(layerName);
       targetElement.style.visibility = 'hidden';
   }
}


function showBlock(layerName)
{
    if (document.getElementById(layerName).style.display == 'none') // Netscape 6 and IE 5+
    {
        document.getElementById(layerName).style.display = 'block'
    } else if (document.getElementById(layerName).style.display == 'block')
	{
        document.getElementById(layerName).style.display = 'none';
	}
}  

function hideBlock(layerName)
{
   if (document.getElementById)
   {
       var targetElement = document.getElementById(layerName);
       targetElement.style.display = 'none';
   }
}

function setbg(color)
{
document.getElementById("smstexarea").style.background=color;
}

function submitMessageTXT(){
		xajax_xajaxGo(xajax.getFormValues("enterSms"), 'submitMessageP');
		return false;
} 

function submitMessageNew(){
		//var strF = xajax.getFormValues("enterSms"); // +xajax.getFormValues("followersform")'';
		//strF.concat(xajax.getFormValues("followersform")); 
		var object = $.extend({}, xajax.getFormValues("enterSms"), xajax.getFormValues("followersform"));
		xajax_xajaxGo(object, 'submitMessageNew');
		return false;
}
	
	
function closemsg(str){
		xajax_xajaxGo(str, 'closeMsgBox');
		return false;
}	
	
function textCounter(field,cntfield,maxlimit) {
		if (field.value.length > maxlimit) 
			field.value = field.value.substring(0, maxlimit);
			else
			cntfield.value = maxlimit - field.value.length;
}


function setElementOpacity(oElem, nOpacity)
{
	var p = getOpacityProperty();
	(setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;	var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;	if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
}

function getOpacityProperty()
{
	var p;
	if (typeof document.body.style.opacity == 'string') p = 'opacity';
	else if (typeof document.body.style.MozOpacity == 'string') p =  'MozOpacity';
	else if (typeof document.body.style.KhtmlOpacity == 'string') p =  'KhtmlOpacity';
	else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p =  'filter';
	
	return (getOpacityProperty = new Function("return '"+p+"';"))();
}


function fadeOpacity(sElemId, sRuleName, bBackward)
{
	var elem = document.getElementById(sElemId);
	if (!elem || !getOpacityProperty() || !fadeOpacity.aRules[sRuleName]) return;
	
	var rule = fadeOpacity.aRules[sRuleName];
	var nOpacity = rule.nStartOpacity;
	
	if (fadeOpacity.aProc[sElemId]) {clearInterval(fadeOpacity.aProc[sElemId].tId); nOpacity = fadeOpacity.aProc[sElemId].nOpacity;}
	if ((nOpacity==rule.nStartOpacity && bBackward) || (nOpacity==rule.nFinishOpacity && !bBackward)) return;

	fadeOpacity.aProc[sElemId] = {'nOpacity':nOpacity, 'tId':setInterval('fadeOpacity.run("'+sElemId+'")', fadeOpacity.aRules[sRuleName].nDalay), 'sRuleName':sRuleName, 'bBackward':Boolean(bBackward)};
}

fadeOpacity.addRule = function(sRuleName, nStartOpacity, nFinishOpacity, nDalay){fadeOpacity.aRules[sRuleName]={'nStartOpacity':nStartOpacity, 'nFinishOpacity':nFinishOpacity, 'nDalay':(nDalay || 30),'nDSign':(nFinishOpacity-nStartOpacity > 0?1:-1)};};

fadeOpacity.back = function(sElemId){fadeOpacity(sElemId,fadeOpacity.aProc[sElemId].sRuleName,true);};

fadeOpacity.run = function(sElemId)
{
	var proc = fadeOpacity.aProc[sElemId];
	var rule = fadeOpacity.aRules[proc.sRuleName];
	
	proc.nOpacity = Math.round(( proc.nOpacity + .1*rule.nDSign*(proc.bBackward?-1:1) )*10)/10;
	setElementOpacity(document.getElementById(sElemId), proc.nOpacity);
	
	if (proc.nOpacity==rule.nStartOpacity || proc.nOpacity==rule.nFinishOpacity) clearInterval(fadeOpacity.aProc[sElemId].tId);
}
fadeOpacity.aProc = {};
fadeOpacity.aRules = {};


jQuery(window).load(function() {
	image_cnt = $("#leftColumn div.image").length +
		$("#centerColumn div.image").length +
		$("#rightColumn div.image").length;
	
	if (image_cnt != 3000)
		return;

	h = [];
	h.l = $("#leftColumn").height();
	h.c = $("#centerColumn").height();
	h.r = $("#rightColumn").height();
	hmin = h.l;
	for(var a in h)
		if(hmin > h[a])
			hmin = h[a];

	$("#leftColumn").height(hmin-10);
	$("#leftColumn").css('overflow', 'hidden');
	$("#centerColumn").height(hmin-10);
	$("#centerColumn").css('overflow', 'hidden');
	$("#rightColumn").height(hmin-10);
	$("#rightColumn").css('overflow', 'hidden');
});



function ccount(max){

	/** 
	 * Character Counter for inputs and text areas 
	 */  
	$('.word_count').each(function(){

		var length = max-$(this).val().length;
		$(this).parent().find('.counter').html( '('+length+')' );

		$(this).change(function(){  
			var new_length = max-$(this).val().length;
			$(this).parent().find('.counter').html( '('+new_length+')' );
			if (new_length < 0)
				$(this).parent().find('.counter').css('color', '#ff0000');
			else
				$(this).parent().find('.counter').css('color', '#000000');
		});
		$(this).keyup(function(){  
			var new_length = max-$(this).val().length;
			$(this).parent().find('.counter').html( '('+new_length+')' );
			if (new_length < 0)
				$(this).parent().find('.counter').css('color', '#ff0000');
			else
				$(this).parent().find('.counter').css('color', '#000000');
		});
	});
}




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
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        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;
    }
};



