
$(document).ready(function() { docIsReady() });


function docIsReady() {

		// Focus the desired input item
	$('.focus_me').focus();

	$('.form_input').focus(function() {
			try {
				$("#" + $(this).attr('id') + "Hint").css('display', 'inline');
			}
			catch (err) { }
		});
	$('.form_input').blur(function() {
			try {
				$("#" + $(this).attr('id') + "Hint").css('display', 'none');
			}
			catch (err) { }
		});


	if($('.flash_message').length > 0) {
		//$('.flash_message').effect('highlight',{color:'#EF7938'},3000);
	}
	
	IESelectHack('#more_services_list');
	$('#more_services_list').css({'zIndex':'5000'});
	$('#more_services').css({'display':'block'});
	$('#more_services').click(function() {
								  $('#more_services_list').css({'display':'block'});
							  });
	$('#more_services').mouseover(function() {
								  showMoreServices();
							  });
	$('#more_services').mouseout(function() {
								  hideMoreServices();
							  });
	$('#more_services_list').mouseover(function() {
								  showMoreServices();
							  });
	$('#more_services_list').mouseout(function() {
								  hideMoreServices();
							  });
	
	if(typeof $('body').lightBox == 'function') {
			// lightbox
		var lbParam = {
				imageLoading:'/js/lightbox/images/loading.gif',
				imageBtnPrev:'/js/lightbox/images/prev.gif',	
				imageBtnNext:'/js/lightbox/images/next.gif',		
				imageBtnClose:'/js/lightbox/images/close.gif',	
				imageBlank:'/js/lightbox/images/blank.gif'
				};
		//$('a[@rel*=lightbox]').lightBox(lbParam); // Select all links that contains lightbox in the attribute rel
		$('a[rel*=lightbox]').lightBox(lbParam); // Select all links that contains lightbox in the attribute rel
	}
	
	
	fixContentOverflow('.main_content_left');
	fixContentOverflow('.main_content_right');

}





var serviceMenuTimeout = {};
var showMoreServices = function() {
	clearTimeout(serviceMenuTimeout);
	serviceMenuTimeout = setTimeout(function() { $('#more_services_list').css({'display':'block'});  }, 500);
}
var hideMoreServices = function() {
	clearTimeout(serviceMenuTimeout);
	serviceMenuTimeout = setTimeout(function() { $('#more_services_list').css({'display':'none'}); }, 800);
}

function IESelectHack(elmStr) {
	var userAgent = navigator.userAgent.toLowerCase();
	if (/msie 6.0/.test( userAgent ) && !/opera/.test( userAgent )) {
		$('<iframe style="display:block;position:absolute;top:0;left:0;z-index:-1;filter:mask();width:expression(this.parentNode.offsetWidth);height:expression(this.parentNode.offsetHeight)"/>').insertAfter(elmStr);
	}
}




function ajaxLoad(selector, url, cache) {
	$.ajax({
		   	type: "GET",
		   	url: url,
			cache: cache,
			success: function(html){
			 $(selector).html(html);
		  	}
		   });
}

function sessionSaver() {
	$.ajax({
		   	type: "GET",
		   	url: '/settings/ping/',
			cache: false,
			success: function(html){
				
		  	}
		   });
	setTimeout(sessionSaver, 360000);

}



function getID(inid) {
	if (inid.lastIndexOf('_') != -1) {
		return inid.substring(inid.lastIndexOf('_') + 1);
	}
	return false;
}

function addFriend(id) {
	//modal_ajax('Loading...','/friends/add/' + id + '/');
	return false;
}

function gotourl(url) {
	document.location.href = url;
}

function loadPhotoPosition(id) {
	//modal_replace('/compose/photoposition/?data[Post][1][id]=' + id);
	
}



function waitingMessage(msg, w, h) {
	
	bgheight = $('body').height();

	$('body').append('<div style="width:100%; height:'+bgheight+'px; position:absolute; top:0; left:0; background:#FFFFFF; z-index:500; filter:alpha(opacity=60); -moz-opacity:.60; opacity:.60; text-align:center; padding:auto;" id="wtgMsgBg"></div>');
	$('body').append('<div id="wtgMsg" style="width:100%; position:absolute; top:'+(parseInt(bgheight) / 2)+'px; left:0; z-index:501; text-align:center; padding:auto;"><div style="width:'+w+'; height:'+h+'; background:#FFFFFF; padding:15px; margin:auto; border:3px solid #ADADAD; color:#333;">'+msg+'</div><div>');
}





function fixContentOverflow(selector) {
	if ($.browser.msie) {
		if (parseInt($.browser.version) == 6) {
			if ($(selector).length > 0) {
				$(selector).css('overflow', 'hidden');
				var selectorWidth = $('.content_container').width() - getPaddingMargin(selector) - 5;
				$(selector).width(selectorWidth);
			}
		}
	}
}

function getPaddingMargin(selector) {
	total = 0;
	
	pr = $(selector).css('padding-right');
	pl = $(selector).css('padding-left');
	mr = $(selector).css('margin-right');
	ml = $(selector).css('margin-left');
	
	total += ((pr != 'auto') ? parseInt(pr) : 0);
	total += ((pl != 'auto') ? parseInt(pl) : 0);
	total += ((mr != 'auto') ? parseInt(mr) : 0);
	total += ((ml != 'auto') ? parseInt(ml) : 0);
	
	return total;
}


/**
 * @author Remy Sharp
 * @date 2008-02-25
 * @url http://remysharp.com/2008/01/21/fixing-ie-overflow-problem/
 * @license Creative Commons License - ShareAlike http://creativecommons.org/licenses/by-sa/3.0/
 *
 * Usage: $('pre').fixOverflow(); -- only runs code if in IE
 */
(function ($) {
    $.fixOverflow = function (padding) {
        if (!$.browser.msie) {
            return this;
        } else {
            return this.each(function () {
                if (this.scrollWidth > this.offsetWidth) {
                    $(this).css({ 'overflow-y' : 'hidden', 'padding-bottom' : padding + 'px' });
                }
            });
        }      
    };
})(jQuery);





