geogoerFunc.prototype.site = function()
{
	return new geogoerSite();
}
function geogoerSite(){

}
geogoerSite.prototype.switchDivs = function(className, selectedClass)
{
	$(className).each(function(){
		$(this).hide();
	});
	if(selectedClass){
		$(selectedClass).show();
	}
}
geogoerSite.prototype.switchTabsClass = function(this_object, elements, selectedClassName)
{
	$(elements).each(function(){
		$(this).removeClass(selectedClassName)
	});
	$(this_object).addClass(selectedClassName);
}
geogoerSite.prototype.switchDivsToggle = function(className)
{
	$(className).each(function(index){
		if($(this).css('display') != 'none'){
			$(this).hide();
		}
		else{
			$(this).show();
		}
	});
}
geogoerSite.prototype.showHide = function(identifier)
{
	element = $(identifier);
	if(element.css('display') == "none"){
		element.show();
	}
	else{
		element.hide();
	}
}
geogoerSite.prototype.easyCheckbox = function(ident, options)
{
	areas = $(ident);
	areas.each(function(i){
		area = $(this);
		area.opt = options;
		checkbox = $(this).find('input[type=checkbox]');
		checkbox.hide();
		$(area).bind("click", function(e, func){
			if($(this).find('input[type=checkbox]').attr("checked") == true){
				$(this).find('span').removeClass('checkbox1_checked');
				$(this).find('input[type=checkbox]').attr("checked", false);
			}
			else{
				$(this).find('span').addClass('checkbox1_checked');
				$(this).find('input[type=checkbox]').attr("checked", true);
			}
			area.opt.onclick();
		});
	});
}

geogoerSite.prototype.vchecks = function(id)
{
	$(id).addClass('geogoer_vchecks');
	object = $(id);
	object.find("li:first").addClass('first');
	object.find("li:last").addClass('last');
	//removing checkboxes
	object.find("input[type=checkbox]").each(function(){
		$(this).hide();
	});
	//adding images true false
	object.find("li").each(function(){
		if($(this).find("input[type=checkbox]").attr('checked') == true){
			$(this).addClass('checked');
			$(this).append('<div class="check_div"></div>');
		}
		else{
			$(this).addClass('unchecked');
			$(this).append('<div class="check_div"></div>');
		}
	});
	//binding onClick function
	object.find("li").find('span').click(function(e){
		e.preventDefault();
		check_li = $(this).parent('li');
		checkbox = $(this).parent('li').find("input[type=checkbox]");
		if(checkbox.attr('checked') == true){
			checkbox.attr('checked',false);
			check_li.removeClass('checked');
			check_li.addClass('unchecked');
		}
		else{
			checkbox.attr('checked',true);
			check_li.removeClass('unchecked');
			check_li.addClass('checked');
		}
	});
	
	//mouse over / out
	//simple
	object.find("li:not(:last,:first)").find('span').bind('mouseover', function(e){
		$(this).parent('li').addClass('hover');
	});
	object.find("li:not(:last,:first)").find('span').bind('mouseout', function(e){
		$(this).parent('li').removeClass('hover');
	});
	//first
	object.find("li:first").find('span').bind('mouseover', function(e){
		$(this).parent('li').addClass('first_hover');
	});
	object.find("li:first").find('span').bind('mouseout', function(e){
		$(this).parent('li').removeClass('first_hover');
	});
	//last
	object.find("li:last").find('span').bind('mouseover', function(e){
		$(this).parent('li').addClass('last_hover');
	});
	object.find("li:last").find('span').bind('mouseout', function(e){
		$(this).parent('li').removeClass('last_hover');
	});	
}
geogoerSite.prototype.mainTable = function(identifier)
{
	element = $(identifier);
	element.addClass("main_table");
	element.find("th:first").addClass("first");
	element.find("th:last").addClass("last");
	element.find("tr.row").children("td").addClass("coll");
	element.find("tr.row:not(:last)").children("td.coll").addClass("bottom_border");
}
geogoerSite.prototype.paneButtonToggle = function(identifier, names)
{
	element = $(identifier);
	span = element.find("span");
	if(span.text() == names[0]){
		span.text(names[1]);
		element.removeClass('pane_button_pressed');
	}
	else{
		span.text(names[0]);
		element.addClass('pane_button_pressed');
	}
}
geogoerSite.prototype.textToggle = function(identifier, names)
{
	element = $(identifier);
	span = element.find("span");
	if(span.text() == names[0]){
		span.text(names[1]);
	}
	else{
		span.text(names[0]);
	}
}
geogoerSite.prototype.mapPopup = function(url, div_id, top_div_id, css, draggable)
{
	top_div = $(top_div_id);
	if(document.getElementById(div_id)){
		$.post(url,
		{},
		function(response){
			$("#" + div_id).find('.message_content').html(response);
		});
	}
	else{
		$.post('index.php?controller=main&action=map_popup',
		{'div_id' : div_id},
		function(response){
			top_div.append(response);
			$.post(url,
			{},
			function(response){
				$("#" + div_id).find('.message_content').html(response);
			});
		});
	}
}

geogoerSite.prototype.showLoginForm = function(return_url){
	geogoer().site().lightBox("index.php?controller=main&action=login&return_url=" + encodeURIComponent(return_url), true);
}

geogoerSite.prototype.showDirectionInfo = function(url)
{
	$("#direction_info_div .direction_info_content").html('');
	$("#direction_info_div .direction_info_content").load(url, $("#direction_info_div").show());
	return false;
}
geogoerSite.prototype.hideDirectionInfo = function()
{
	$("#direction_info_div").fadeOut()
	return false;
}

geogoerSite.prototype.lightBox = function(url, x)
{
	$("#general_lightbox_div .layout").empty();
	
	if(x){
		$("#general_lightbox_div .layout").html('<div class="lightbox_x_div" onclick="geogoer().site().hideLightBox(); return false;"></div>');
	}
	
	$("#general_lightbox_div .layout").append('<div class="lightbox_top"></div>');
	
	if(url.substring(0,1) == "#"){
		content = $(url).html();
		this.showLightBox(content);
	}
	else{
		$.get(url, this.showLightBox);
	}
	
	return false;
}

geogoerSite.prototype.hideLightBox = function(url)
{
	$("#general_lightbox_div .layout").append('');
	$("#general_lightbox_div").fadeOut();
	return false;
}

geogoerSite.prototype.showLightBox = function(response){
	//request data for centering
	$("#general_lightbox_div .layout").append(response);
	$("#general_lightbox_div").show();
	geogoer().site().centerLightBox();
	$(function(){
		$(window).bind('resize', function(e){
			geogoer().site().centerLightBox();
		});
	});
}
geogoerSite.prototype.centerLightBox = function(){
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	var popupHeight = $("#general_lightbox_div .layout").height();
	var popupWidth = $("#general_lightbox_div .layout").width();
	//centering
	$("#general_lightbox_div .layout").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	$("#general_lightbox_div .shadow").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2 - 5,
		"left": windowWidth/2-popupWidth/2 - 5
	});
	$("#general_lightbox_div .shadow").width(popupWidth + 10);
	$("#general_lightbox_div .shadow").height(popupHeight + 10);
	//only need force for IE6
}
geogoerSite.prototype.rightManu = function(ul)
{
	ul = $(ul);
	ul.addClass("right_menu");
	
	ul.find("li:first").addClass("first");
	ul.find("li:last").addClass("last");
	
	ul.find("li.selected").each(function()
	{		
		var html = $(this).html();
		$(this).html('<div class="arrow">' 
					+ '<img src="images/geogoer_components/right_menu/arrow_left.gif" class="arrow_left" />'
					+ '<img src="images/geogoer_components/right_menu/arrow_right.gif" class="arrow_right" />'
					+ '<div class="arrow_text"></div>'
				+ '</div>');
				
		var arrow = $(this).find(".arrow");
		var left = arrow.find(".arrow_left");
		var right = arrow.find(".arrow_right");
		var arrow_text = arrow.find(".arrow_text");
				
		arrow.width($(this).width() + left.width() + right.width());
		arrow_text.html(html);
	});
}
geogoerSite.prototype.selectCheckboxes = function(identifier, action){
	if(action == "all"){
		$(identifier).each(function() { 
			$(this).attr("checked", true);
		});
	}
	if(action == "none"){
		$(identifier).each(function() { 
			$(this).attr("checked", false);
		});
	}
}
geogoerSite.prototype.selectCheckboxesLayout = function(identifier, action){
	if(action == "all"){
		$(identifier).each(function() { 
			$(this).attr("src", "images/fields/checkbox_checked.gif");
		});
	}
	if(action == "none"){
		$(identifier).each(function() { 
			$(this).attr("src", "images/fields/checkbox.gif");
		});
	}
}
geogoerSite.prototype.geogoerDropdown = function(identifier){
	$(identifier).click(function(e) { 
		e.stopPropagation(); 
	}); 
    $(identifier).each(function(i){
		element = $(this);
		element.addClass("geogoer_dropdown");
		element.css("display", "block");
	    button = element.find("span.button");
	    block = element.find("div.block");
   
	    $(button).bind('mouseover', function(e){
	        $(this).addClass("button_hover");   
	    });
	    $(button).bind('mouseout', function(e){
	        $(this).removeClass("button_hover");   
	    });
	
		element.append('<div style="width: ' + parseInt(button.width() + 10) + 'px; height: ' + parseInt(button.height()) + 'px;" class="display: block;"></div>');
		button.append('<div class="button_shadow_right"></div>');
		block.append('<div class="block_shadow_right"></div>');
		block.append('<div class="block_shadow_bottom"></div>');
    
		$(button).bind('click', function(e){
			e.stopPropagation(); 
			if($(this).parent(identifier).hasClass("geogoer_dropdown_active")){
				was_opened = true;
			}
			else{
				was_opened = false;
			}
			$(identifier).each(function(i){
				$(this).removeClass("geogoer_dropdown_active");
			});
			if(was_opened == true){
				$(this).parent(identifier).removeClass("geogoer_dropdown_active");
			}
			else{
				$(this).parent(identifier).addClass("geogoer_dropdown_active");
			}
	    });
	});
	
	$(document).click(function() { 
		$(identifier).each(function(i){
			$(this).removeClass("geogoer_dropdown_active");
		});
	});
}
geogoerSite.prototype.geogoerSelect = function(el, options){
	//defaults
	var opt = {};
	if(!options){ var options = {};}
	opt.onChange = options.onChange || function(){};
	
	var id = $(el).attr('id');
	var selection_id = id + '_geogoer_select_id';
	$(el).after('<div class="geogoer_select" id="' + selection_id + '"></div>');
	var gs_div = $(el).next('div.geogoer_select');
	var default_width = $(el).width() || 120;
	gs_div.css("width", default_width + "px");
	var default_text = $(el).find("option:selected").text() || $(el).find("option:first").text();
	gs_div.append('<span>' + $(el).find("option:selected").text() + '</span>');
	gs_div.append('<div class="geogoer_select_drop"></div>');
	var gsd_div = gs_div.find('div.geogoer_select_drop');
	gsd_div.css("width", (default_width + 4) + "px");
	gsd_div.css("z-index", 200);
	gsd_div.append('<ul class="geogoer_select_dr_list"></ul>');
	var gsdu = gsd_div.find('ul.geogoer_select_dr_list');
	$(el).find("option").each(function(i){
		gsdu.append('<li rel= ' + i + '>' + $(this).text() + '</li>');
	});
	
	
	gs_div.find("span").click(function(e){
		if(gs_div.hasClass("geogoer_select_clicked")){
			gs_div.removeClass("geogoer_select_clicked");
		}
		else{
			gs_div.addClass("geogoer_select_clicked");
			gs_div.find("input:checked").parent("li").addClass("selected");
		}
	});
	
	gs_div.find(".geogoer_select_dr_list li").click(function(e){
		$(this).parent('.geogoer_select_dr_list').find('li').each(function(e){
			$(this).removeClass("selected");
		});
		$(el).find("option").each(function(e){
			$(this).attr("selected", false);
		});
		$(this).addClass("selected");
		$(el).find("option:eq(" + $(this).attr("rel") + ")").attr("selected", true);
		gs_div.find("span").text($(this).text());
		gs_div.removeClass("geogoer_select_clicked");
		opt.onChange();
	});
	
	gs_div.find(".geogoer_select_dr_list").mouseover(function(e){
		$(this).find('li').each(function(e){
			$(this).removeClass("selected");
		});
	});
	
	$(window).click(function(e){
		var close_rad = true;
		if(e.target.id == selection_id){
			close_rad = false;
		}
		if(close_rad == true){
			var el_id = $(e.target).parents("#".selection_id).attr("id");
			if(el_id){
				close_rad = false;
			}
		}
		if(close_rad){
			gs_div.removeClass("geogoer_select_clicked");
		}
	});
									
}
geogoerSite.prototype.geogoerCheckbox = function(el, options){

	if(!options){
		options = {};
	}
	opt = {};
	
	opt.className = options.className || '';
	var id = $(el).attr('id');
	var selection_id = id + '_geogoer_checkbox_id';
	$(el).after('<img src="images/fields/checkbox.gif" id="' + selection_id + '" class="checkbox_layout_img">');
	var gs_img = $('#' + selection_id);
	gs_img.addClass(opt.className);
	
	if($(el).attr("checked") == true){
		gs_img.attr("src", "images/fields/checkbox_checked.gif");
	}
	else{
		gs_img.attr("src", "images/fields/checkbox.gif");
	}
	
	gs_img.click(function(e){
		if($(el).attr("checked") == true){
			$(this).attr("src", "images/fields/checkbox_h.gif");
			$(el).attr("checked", false);
		}
		else{
			$(this).attr("src", "images/fields/checkbox_checked_h.gif");
			$(el).attr("checked", true);
		}
	});
	
	gs_img.mouseover(function(e){
		if($(el).attr("checked") == false){
			$(this).attr("src", "images/fields/checkbox_h.gif");
		}
		else{
			$(this).attr("src", "images/fields/checkbox_checked_h.gif");
		}
	});
	gs_img.mouseout(function(e){
		if($(el).attr("checked") == false){
			$(this).attr("src", "images/fields/checkbox.gif");
		}
		else{
			$(this).attr("src", "images/fields/checkbox_checked.gif");
		}
	});								
}
geogoerSite.prototype.geogoerCheckboxes = function(el, options){
	$(el).each(function(e){
		geogoer().site().geogoerCheckbox(this, options);
	});
}
geogoerSite.prototype.geogoerRadio = function(name, options){
	//defaults
	var opt = {};
	if(!options){ var options = {};}
	for(j in options){
		opt[j] = {};
		opt[j].onClick = options[j].onClick || function(){};
	}
	
	var objects = [];
	$("input[name='" + name + "']").each(function(i){
		objects[i] = $(this);
		$(this).after('<div class="radio_layout_div ' + ($(this).attr("checked") == true ? "radio_layout_div_checked" : "") + '" id="' + name.replace("[","").replace("]","") + '_nr_' + i + '">');
		var obj = $('#' + name.replace("[","").replace("]","") + '_nr_' + i);
		var old_obj = $(this);
		var cur_obj_i = i;
		obj.click(function(e){
			$("input[name='" + name + "']").each(function(i){
				$('#' + name.replace("[","").replace("]","") + '_nr_' + i).removeClass("radio_layout_div_checked");
				$(this).attr("checked", false);
			});

			obj.addClass("radio_layout_div_checked");
			old_obj.attr("checked", true);
			opt[cur_obj_i].onClick();

		});
	});								
}

geogoerSite.prototype.setPageTitle = function(string)
{
	window.document.title = string;
}

geogoerSite.prototype.confirm = function(obj, textmsg, icon_url, yes_text, yes_link, no_text, no_link, yes_form_id, yes_function)
{
	htmlmsg = '<table cellpadding="0" cellspacing="0" style="width: 100%"><tr>'; //100% needed in delete user feedback confirm. Check there if bug
	if(icon_url){
		htmlmsg += '<td valign="top" style="padding-right: 10px;"><img src="' + icon_url + '" border="0"></td>';
	}
	htmlmsg += '<td style="min-height: 60px" valign="middle">' + textmsg + '</div></td>';
	htmlmsg += '</tr></table>';
	htmlmsg += '<div style="margin-top: 5px; text-align: center">';
	if(!yes_text){
		yes_text = "OK";
	}
	
	
	htmlmsg += '<div style="margin-top: 5px; text-align: center">';
	
	//yes button
	if(!yes_link){
		htmlmsg += '<a href="javascript: void(0);" onClick="$(\'.qtip\').hide()" class="button3">';
	}
	else{
		if(yes_form_id){
			htmlmsg += '<a href="javascript: void(0);" class="button4" onClick="$(\'' + yes_form_id + '\').submit();">';
		}
		else if(yes_function){
			htmlmsg += '<a href="javascript: void(0);" class="button4" onClick="' + yes_link + '; $(\'.qtip\').hide(); return false;">';
		}
		else{
			htmlmsg += '<a href="' + yes_link + '" class="button3">';
		}
	}
	htmlmsg += '<span>' + yes_text + '</span></a>';
	
	if(no_text){
		if(!no_link){
			htmlmsg += '<a style="margin-left: 5px" href="javascript: void(0);" onClick="$(\'.qtip\').hide()" class="button4">';
		}
		else{
			htmlmsg += '<a  style="margin-left: 5px" href="' + no_link + '" class="button4">';
		}
		htmlmsg += '<span>' + no_text + '</span></a>';
	}
	
	htmlmsg += '</div>';
	
	
	
	$(obj).qtip({
		content: {
			text : htmlmsg
		},
		position: {
			target: $(document.body), // Position it via the document body...
			corner: 'center' // ...at the center of the viewport
		},
		style: { 
			name: 'light', // Inherit from preset style
			width: { min: 300, max: 300 },
			padding: '14px',
			border: {
				color: '#6699CC',
				radius: 3,
				width: 1
			}

		},
		show: {
		  when: false, // Don't specify a show event
		  ready: true // Show the tooltip when ready
		  //solo: true
	   },
	   hide: false // Don't specify a hide event
	}); 
}

geogoerSite.prototype.confirmHtml = function()
{
	//in project. custom confirm window with custom html text
}

$(function(){
	//dropp down image
	$('.geogoer_dropp').each(function(){
		$(this).attr('src', 'images/mini_icons/arrow_expand.gif');
	});
	//dropp down image
	$('.geogoer_dropp').bind("click", function(){
		if($(this).attr('src') == 'images/mini_icons/arrow_expand.gif'){
			$(this).attr('src', 'images/mini_icons/arrow_collapse.gif');
		}
		else{
			$(this).attr('src', 'images/mini_icons/arrow_expand.gif');
		}
	});
});

//TALK OBJECT
geogoerSite.prototype.Talk = function(talk_id, object_type, object_id)
{
	return new Talk(talk_id, object_type, object_id);
}
function Talk(talk_id, object_type, object_id){
	this.talk_id = talk_id;
	this.object_type = object_type;
	this.object_id = object_id;
	return this;
}
Talk.prototype.setType = function(type, el){
	$('#talk' + this.talk_id + ' .talk_selector').removeClass('talk_selector_selected');
	$('#talk' + this.talk_id + ' .talk_selector').removeClass('talk_selector_selected');
	$('#talk' + this.talk_id + ' .talk_selector').removeClass('talk_selector_selected');
	$(el).addClass('talk_selector_selected');
	$('#talk' + this.talk_id + ' .talk_selector_sms').find('.type_selector_image').attr('src', 'images/talk/sms_gr.png');
	$('#talk' + this.talk_id + ' .talk_selector_email').find('.type_selector_image').attr('src', 'images/talk/email_gr.png');
	$('#talk' + this.talk_id + ' .talk_selector_comment').find('.type_selector_image').attr('src', 'images/talk/comment_gr.png');
	$(el).find('.type_selector_image').attr('src', 'images/talk/' + type + '_gr_selected.png');
	$('#talk' + this.talk_id + ' .talk_compose').find('.status_image').attr('src', 'images/talk/' + type + '_gr_selected.png');
	$('#talk' + this.talk_id + '_send_type_input').val(type)
}
Talk.prototype.showFullCompose = function(){
	$('#talk' + this.talk_id + '_settings').show('fast');
}
Talk.prototype.hideFullCompose = function(){
	$('#talk' + this.talk_id + ' .compose_settings').hide('fast');
}
Talk.prototype.showHiddenMessages = function(){
	$('#talk' + this.talk_id + ' .talk_entry').show('fast');
	$('#talk' + this.talk_id + ' .talk_collapse_entries').hide();
}
Talk.prototype.addTalk = function(){
	$.post("index.php?controller=talks&action=ajax_add_talk",
	{
		'text' : $('#talk' + this.talk_id + '_textarea').val(),
		'type' : $('#talk' + this.talk_id + '_send_type_input').val(),
		'talk_id' : this.talk_id,
		'object_type' : this.object_type,
		'object_id' : this.object_id
	},
	this.addTalkResponse, "json");
}
Talk.prototype.addTalkResponse = function(response){
	if(response){
		tid = response.data.talk_id;
		if(response.status == "ok"){
			$.post("index.php?controller=talks&action=ajax_entry",
			{
			'text' : response.data.text,
			'type' : response.data.type,
			'user_id' : response.data.user_id,
			'talk_id' : response.data.talk_id,
			'entry_id' : response.data.entry_id
			},
			function(response){
				$('#talk' + tid + ' .talk_entries').append(response);
				$('#talk' + tid + '_textarea').val('');
			});
		}
	}
}
Talk.prototype.isOpenedForWriting = function(){
	if($('#talk' + this.talk_id + ' .compose_settings').css("display") == "none"){
		return false;
	}
	else{
		return true;
	}
}

