$(document).ready(function() {

	$('#lang-select').mouseenter(function() {
		$('#lang-select .more-langs').show();
		return false;
	});
	$('#lang-select').mouseleave(function() {
		$('#lang-select .more-langs').hide();
		return false;
	});

	$('.news-title').click(function() {

		var currentArticle = $(this).closest('.article');

		if (currentArticle.find('.news-inner').css('display') == 'block') {
			return false;
		}

		$('#news-container .news-inner').closest('.article').removeClass('article-current');

		$('#news-container .news-inner').removeClass('opened');
		$('#news-container .news-inner').addClass('closed');

		currentArticle.find('.news-inner').removeClass('closed');
		currentArticle.find('.news-inner').addClass('opened');
		currentArticle.addClass('article-current');

		$('#news-container .opened').slideDown('fast');
		$('#news-container .closed').slideUp('fast');

		return false;
	});

	if ($('body').css('cursor') == 'pointer') {

		var onClick = $('body').attr('onclick');

		$('#container div').mouseenter(function() {
			$('body').css('cursor', 'default');
			$('body').unbind('click');
			$('body').attr('onclick', '');
		});
		$('#container div').mouseleave(function() {
			$('body').css('cursor', 'pointer');
			$('body').attr('onclick', onClick);
		});

	}


	$('.input-text .submit-button .submit-search-button').mouseenter(function() {
		$(this).attr('src', '/img/inputs/text-searchbutton-over.png');
	});
	$('.input-text .submit-button .submit-search-button').mouseleave(function() {
		$(this).attr('src', '/img/inputs/text-searchbutton.png');
	});


	$('.input-select').each(function() {

		var wrap = $(this);

		//$(this).find('select').parent().css('width', $(this).find('select').css('width'));

		$(this).find('span.display-value').text($(this).find('select').find("option:selected").text());

		$(this).find('select').change(function() {
			wrap.find('span.display-value').text($(this).find("option:selected").text());
		});
	});


	$.widget( "custom.catcomplete", $.ui.autocomplete, {
		_renderMenu: function( ul, items ) {
			var self = this,
				currentCategory = "";
			$.each( items, function( index, item ) {
				if ( item.category != currentCategory ) {
					ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
					currentCategory = item.category;
				}
						return $( "<li></li>" )
			.data( "item.autocomplete", item )
			.append( "<a>" + item.label + "</a>" )
			.appendTo( ul );
			});
		}
	});

	if ($("#search-query").length) {
		$("#search-query").catcomplete({
			source: function( request, response ) {
				$.ajax({
					url: "/scripts/database.php?action=keywordSearch",
					type: 'POST',
					dataType: "json",
					data: {
						query: request.term
					},
					success: function( data ) {
						response( $.map( data.keywords, function( item ) {
							return {
								label: item.label,
								value: item.value,
								keyword_type: item.keyword_type,
								category: item.category,
								head_code_id: item.head_code_id,
								placing_id: item.placing_id
							}
						}));
					}
				});
			},
			minLength: 2,
			delay: 50,
			select: function( event, ui ) {
				if (ui.item.keyword_type == 'company' && ui.item.placing_id) {
					$('#search-placing-id').val(ui.item.placing_id);
				}
				else if (ui.item.keyword_type == 'head') {
					$('#search-head-code-id').val(ui.item.head_code_id);
					$('#search-force-head-code').val(1);
				}
				this.value = ui.item.value;
				$('#keyword-search-form').submit();
			},
			open: function() {
			},
			close: function() {
			}
		});
	}

	$("#search-query").keyup(function() {
		$('#search-placing-id').val('');
	});

	if ($("#search-location").length) {
		$("#search-location").autocomplete({
			source: function( request, response ) {
				$.ajax({
					url: "/scripts/database.php?action=locationSearch",
					type: 'POST',
					dataType: "json",
					data: {
						query: request.term
					},
					success: function( data ) {
						response( $.map( data.keywords, function( item ) {
							return {
								label: item.label,
								value: item.value
							}
						}));
					}
				});
			},
			minLength: 2,
			delay: 50,
			select: function( event, ui ) {
			},
			open: function() {

			},
			close: function() {

			}
		}).data( "autocomplete" )._renderItem = function( ul, item ) {
			return $( "<li></li>" )
				.data( "item.autocomplete", item )
				.append( "<a>" + item.label + "</a>" )
				.appendTo( ul );
		};
	}

	if ($("#search-show").length) {
		$("#search-show").autocomplete({
			source: function( request, response ) {
				$.ajax({
					url: "/scripts/entertainment.php?action=showSearch",
					type: 'POST',
					dataType: "json",
					data: {
						query: request.term
					},
					success: function( data ) {
						response( $.map( data.keywords, function( item ) {
							return {
								label: item.label,
								show_id: item.show_id,
								value: item.value
							}
						}));
					}
				});
			},
			minLength: 2,
			delay: 50,
			select: function( event, ui ) {
				this.value = '';
				$('#search-show-id').val(ui.item.show_id);
				$('#entertainment-search-form').submit();
			},
			open: function() {

			},
			close: function() {

			}
		}).data( "autocomplete" )._renderItem = function( ul, item ) {
			return $( "<li></li>" )
				.data( "item.autocomplete", item )
				.append( "<a>" + item.label + "</a>" )
				.appendTo( ul );
		};
	}

	if ($("#search-show-location").length) {
		$("#search-show-location").catcomplete({
			source: function( request, response ) {
				$.ajax({
					url: "/scripts/entertainment.php?action=locationSearch",
					type: 'POST',
					dataType: "json",
					data: {
						query: request.term
					},
					success: function( data ) {
						response( $.map( data.keywords, function( item ) {
							return {
								label: item.label,
								value: item.value,
								keyword_type: item.keyword_type,
								category: item.category
							}
						}));
					}
				});
			},
			minLength: 2,
			delay: 100,
			select: function( event, ui ) {
				this.value = ui.item.value;
				$('#entertainment-search-form').submit();
			},
			open: function() {
			},
			close: function() {
			}
		});
	}


	$('#search-piletilevi').keyup(function() {
		$('#form-piletilevi').attr('action', 'http://www.piletilevi.ee/est/?search=' + Url.encode($(this).val()));
	});

	$('#form-piletilevi').submit(function() {

		if (!$('#search-piletilevi').val()) {
			return false;
		}

		$('#form-piletilevi').attr('action', 'http://www.piletilevi.ee/est/?search=' + Url.encode($('#search-piletilevi').val()));
	});

	/* Add Company Form */

	$('#add-company-form .reset-form').click(function() {

		var form = $('#add-company-form form');
		form.find('.form-inputs-text-error').removeClass('form-inputs-text-error');
		form.find('label.label-error').removeClass('label-error');
		form[0].reset();
		
	});

	$('#add-company-form .submit-form').click(function() {

		var form = $('#add-company-form form');
		form.find('.form-inputs-text-error').removeClass('form-inputs-text-error');
		form.find('label.label-error').removeClass('label-error');

		$.ajax({
			type: 'POST',
			cache: false,
			dataType: 'json',
			url: '/scripts/add_company.php?action=submit',
			data: form.serializeArray(),
			success: function(data) {
				
				if (data.success == true) {
					if (data.success_text) {
						$('#add-company-form').html(data.success_text);
					}
				}
				else {
					if (data.errors) {
						for (var i in data.errors) {
							if (i) {
								$('label[for="' + i + '"]').addClass('label-error');
								form.find('input[name="f[' + i + ']"]').addClass('form-inputs-text-error');
							}
						}
					}
				}
			}
		});
		return false;
		
		
	});

	/* Postcode Form */

	$('#postcode-search-form .submit-from').click(function() {
		$('#postcode-search-form form').submit();
	});


	$('#postcode-search-form form').submit(function() {

		var form = $(this);

		$('#postcode-search-form .results').html($('<div/>', {
			'class': 'more-rows-loading'
		}));

		$.ajax({
			type: 'POST',
			cache: false,
			dataType: 'json',
			url: '/scripts/postcodes.php?action=search',
			data: form.serializeArray(),
			success: function(data) {

				if (data.success == true) {
					if (data.results) {
						$('#postcode-search-form .results').html(data.results);
					}
				}
				else {
				}
			}
		});
		return false;
	});

	/* Main Search Form */

	$('#keyword-search-form').submit(function() {

		var form = $(this);

		$.ajax({
			type: 'POST',
			cache: false,
			dataType: 'json',
			url: '/scripts/database.php?action=getSearchUrl',
			data: form.serializeArray(),
			success: function(data) {
				
				if (data.success == true) {
					if (data.url) {
						document.location = data.url;
					}
				}

			}
		});

		return false;
	});

	$('.locations select').change(function() {

		var val = $(this).val();
		if ($('#filter-parent-id').val().length && $('#filter-parent-id').val() != 0) {
			$('#search-parent-id').val($('#filter-parent-id').val());
		}
		if ($('#filter-placing-id').val().length && $('#filter-placing-id').val() != 0) {
			$('#search-placing-id').val($('#filter-placing-id').val());
		}
		if ($('#search-head-code-id').val() > 0) {
			$('#search-force-head-code').val(1);
		}

		$('#search-region').val(val);
		$('#keyword-search-form').submit();
		
	});

	$('.search-results .result-company').mouseenter(function() {
		highlightCompanyRow($(this));
	});
	$('.search-results .result-company').mouseleave(function() {
		unhighlightCompanyRow($(this));
	});

	/* Weather box cycle */
	if ($('#weather-slides').length) {
		$('#weather-slides').cycle({
			requeueOnImageNotLoaded: false,
			timeout: 6000,
			speed: 640,
			fx: 'scrollUp',
			easing: 'easeOutBounce',
			containerResize: 0,
			cleartype: 1,
			cleartypeNoBg: true
		});
	}

	if ($('.weather-forecast').length) {
		$('.weather-forecast .slides').cycle({
			timeout: 8000,
			speed: 640,
			fx: 'fade',
			containerResize: 0,
			cleartype: 1,
			cleartypeNoBg: true
		});
	}

	formatEmailAddresses();

	$('#noproblem-form form').submit(function() {

		var form = $(this);

		var phone = $('#np_phone').val();

		if (phone.match(/^[0-9]{5,8}$/)) {
			$.colorbox({
				href: '/scripts/noproblem.php?action=create_session',
				overlayClose: false,
				width: '630px',
				opacity: 0.65,
				data: form.serializeArray(),
				onComplete: function() {
					$('#noproblem-status .np-window-close a').click(function() {
						$.colorbox.close();
						return false;
					});
					np_checkStatus();
				}
			});
		}

		return false;
	});

	$('#noproblem-status .supplier').live('mouseenter', function() {
		$(this).addClass('supplier-hover');
	});
	$('#noproblem-status .supplier').live('mouseleave', function() {
		$(this).removeClass('supplier-hover');
	});

	$('.map-directions-box form').live('submit', function() {

		var clientAddress = $(this).find('input[name="location"]').val();

		var companyCoords = $(this).find('input[name="company_coords"]').val()
		if (clientAddress && companyCoords) {
			var url = 'http://maps.google.com/maps?saddr=' + Url.encode(clientAddress) + '&daddr=' + companyCoords;
			window.open(url, '_blank');
		}

		return false;
	});


	$('#company-share-email form').live('submit', function() {
		
		var form = $(this);
		$('#send_to_email').removeClass('form-inputs-text-error');

		$.ajax({
			type: 'POST',
			cache: false,
			dataType: 'json',
			url: '/scripts/database.php?action=email_company_url',
			data: form.serializeArray(),
			success: function(data) {
				
				if (data.success == true) {
					if (data.response_text) {
						$('#company-share-email').html('<span class="ico">' + data.response_text + '</div>');
					}
				}
				else {
					$('#send_to_email').addClass('form-inputs-text-error');
				}

			}
		});

		return false;
	});

	$(".article table.contacts, .personal-search-results table").each(function(){

		$("tr:even", this).addClass("table-row-even");
		//$("tr:first", this).addClass("table-row-odd");

	});

	$('.accordion-group .group-title a').click(function() {
		var group = $(this).parent().parent();
		var group_title = group.find('.group-title');
		var group_content = group.find('.group-content');

		if (group_title.hasClass('active')) {
			group_title.removeClass('active');
			group_content.slideUp();
		}
		else {

			var active = $('.accordion-group .active').parent();

			group_content.slideDown();

			active.find('.group-title').removeClass('active');
			active.find('.group-content').slideUp();

			group_title.addClass('active');
		}

		return false;

	});

	/* Private Persons Search Form */

	$('#person-search-form').submit(function() {

		var form = $(this);

		$.ajax({
			type: 'POST',
			cache: false,
			dataType: 'json',
			url: '/scripts/persons.php?action=getSearchUrl',
			data: form.serializeArray(),
			success: function(data) {
				
				if (data.success == true) {
					if (data.url) {
						document.location = data.url;
					}
				}

			}
		});

		return false;
	});


	if ($('#map_canvas').length) {

		var latlng = new google.maps.LatLng(59.431152833342,24.721695256451);

		var myOptions = {
			zoom: 15,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};

		var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

		var loc = new google.maps.Marker({
			position: new google.maps.LatLng(59.431152833342,24.721695256451),
			icon: '/img/ico/1188-logo.png',
			map: map,
			animation: google.maps.Animation.DROP,
			title: 'AS Teabeliin'
		});

	}

	$('#basket-container .game').live('mouseenter', function() {
		if ($(this).hasClass('game-today')) {
			$(this).addClass('row-hover-today');
		}
		else {
			$(this).addClass('row-hover');
		}
	});
	$('#basket-container .game').live('mouseleave', function() {
		if ($(this).hasClass('game-today')) {
			$(this).removeClass('row-hover-today');
		}
		else {
			$(this).removeClass('row-hover');
		}
	});

	$('.shows-list .show').mouseenter(function() {
		$(this).addClass('show-hover');
	});

	$('.shows-list .show').mouseleave(function() {
		$(this).removeClass('show-hover');
	});

	$('.latest-news .news-row').mouseenter(function() {
		$(this).addClass('news-row-hover');
	});

	$('.latest-news .news-row').mouseleave(function() {
		$(this).removeClass('news-row-hover');
	});

	$('#search-period-start, #search-period-end').datepicker({
		dateFormat: 'dd.mm.yy'
	});

});

function startGallery() {

	var gallerySlider = new ImageFlow();
	gallerySlider.init({
		ImageFlowID: 'imageGallery',
		reflectPath: '/js/imageflow/',
		imagePath: '../../gallery/slider/',
		circular: true,
		imageCursor: 'pointer',
		aspectRatio: 3,
		imageScaling: true,
		imagesM: 0.8,
		startAnimation: false,
		opacityArray: [10,8,6,4,2],
		opacity: false,
		slider: false,
		captions: false,
		reflections: false,
		slideshowSpeed: 500,
		onClick: function() {

			var imgList = [];
			imgList.push($(this).attr('longdesc'));

			var firstImage = $(this).attr('longdesc');

			$('#imageGallery img').each(function() {
				if ($(this).attr('longdesc') != firstImage) {
					imgList.push($(this).attr('longdesc'));
				}
			});

			$.fancybox(imgList, {
				type: 'image',
				fixed: true,
				openEffect		: 'elastic',
				closeEffect		: 'elastic',
				'padding'		: 2,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				helpers: {
					overlay: false
				}
			});

		}
	});
}

function loadMoreGames(box_id, direction) {

	var regs, index;
	
	switch (direction) {
		case 'next':
			regs = $('#' + box_id + ' .game').last().attr('id').split('-');
			index = regs[regs.length - 1];
			break;
		case 'previous':
			regs = $('#' + box_id + ' .game').first().attr('id').split('-');
			index = regs[regs.length - 1];
			break;
	}

	$.ajax({
		type: 'POST',
		cache: false,
		dataType: 'json',
		url: '/scripts/basket.php?action=get_more_games',
		data: {
			index: index,
			direction: direction,
			box_id: box_id
		},
		success: function(data) {
		
			if (data.success == true) {
				$('#'+ box_id).html(data.response_html);
			}

		}
	});



	return false;


}

function highlightCompanyRow(row) {
	row.addClass('result-hover');
}

function unhighlightCompanyRow(row) {
	row.removeClass('result-hover');
}

function np_checkStatus() {

	var np_session_id = parseInt($('#np_session_id').val());
	if (!isNaN(np_session_id)) {

		$.ajax({
			type: 'POST',
			cache: false,
			dataType: 'json',
			url: '/scripts/noproblem.php?action=get_session_status',
			data: {
				id: np_session_id	
			},
			success: function(data) {

			
				if (data.success == true) {

					if (data.suppliers && data.suppliers.length) {

						for (var i in data.suppliers) {
							var supplierRow = $('#supplier-' + data.suppliers[i].SupplierNumber.toString());
							var className = 'status-' + data.suppliers[i].Status;
							supplierRow.find('.status div').html(data.suppliers[i].StatusName);

							if (!supplierRow.find('.status div').hasClass(className)) {
								supplierRow.find('.status div').removeClass();
								supplierRow.find('.status div').addClass(className);
							}

						}

					}

					if (data.session_is_complete == true) {
						if ($("#noproblem-status .np-window-close").css('visibility') == 'hidden') {
							$("#noproblem-status .np-window-close").hide().css({visibility: "visible"}).fadeIn("slow");
						}
					}
				
					var npRequestTimeout = setTimeout(function() {
						np_checkStatus();
					}, 1000);

				}

			}
		});
		
	}
}

function changeSearchboxTab(id, tab) {

	var switchToTabId = 'searchbox-tab-' + id;

	var activeTab = $('#searchbox .tabs').find('a.tab-active');
	if (activeTab && activeTab.attr('id') != switchToTabId) {
		$('#searchbox .tab').removeClass('tab-active');
		$('#' + switchToTabId).addClass('tab-active');

		$('#searchbox .tab-content').hide();
		$('#searchbox #searchbox-tabcontent-' + id).show();
		
	}


	return false;
}

function openCompanyWindow(company_id, my_address) {

	var url = '/scripts/database.php?action=openCompany&company_id=' + company_id; 
	if (my_address) {
		url = url + '&my_address=' + my_address;
	}

	$.ajax({
		type: 'GET',
		cache: false,
		dataType: 'json',
		url: url,
		success: function(data) {
			
			if (data.success == true) {
				$.colorbox({
					html: data.content,
					overlayClose: true,
					width: '950px',
					opacity: 0.65,
					onComplete: function() {
						if (data.show_map) {
							initCompanyMap();
						}
						if (data.show_images) {
							startGallery();
						}
						formatEmailAddresses();
					}
				});
			}
			else {
			}
		}
	});


	return false;
	
}

function fetchMoreCompanies() {
	var lastRowIndex;
	var lastRow = $('#results-rows .result-company').last();
	if (lastRow) {
		lastRowIndex = lastRow.attr('id');
	}

	$('#results-rows').append($('<div/>', {
		'class': 'more-rows-loading'
	}));

	$.ajax({
		type: 'POST',
		cache: false,
		dataType: 'json',
		url: '/scripts/database.php?action=loadCompaniesSearchResults',
		data: {
			'row_index': lastRowIndex, 
			'keywords': $('#search-query').val(), 
			'location': $('#search-location').val(),
			'region': $('#filter-region').find("option:selected").val(),
			'head_code_id': $('#search-head-code-id').val(),
			'get_count': 5
		},
		success: function(data) {
			
			if (data.success == true) {
				if (data.content) {
					$('#results-rows').append(data.content);
					formatEmailAddresses();
				}
			}

			$('#results-rows .more-rows-loading').remove();

		}
	});

}

function formatEmailAddresses() {
	$('span.c-email-unformatted').each(function() {
		var email = $(this).text();
		email = email.replace(/\[dooot\]/g, '.');
		email = email.replace(/\[aaat\]/g, '@');

		$(this).html('<a href="mailto:' + email + '">' + email + '</a>');

		var email = $(this);

		email.removeClass('c-email-unformatted');
	});
}

function setFieldDefaultValue(field_id, default_value) {
	$('#' + field_id).focus(function() {
		if ($(this).val() == default_value) {
			$(this).val('');
		}
	});
	$('#' + field_id).blur(function() {
		if (!$(this).val().length) {
			$(this).val(default_value);
		}
	});
}


function showNoProblemSearch(head_code, region_id) {

	if (head_code && region_id) {
		
		$.ajax({
			type: 'GET',
			cache: false,
			dataType: 'json',
			url: '/scripts/noproblem.php?action=getSupplierCountPerHeading&head_code=' + head_code + '&region_id=' + region_id,
			success: function(data) {
				
				if (data.success == true) {
					if (data.supplier_count > 0) {

						$('#noproblem-searchbox .box-close').click(function() {
							$('#noproblem-searchbox').slideUp();
						});

						$('#noproblem-searchbox .box-close').mouseenter(function() {
							$(this).find('img').attr('src', '/img/noproblem/box-close-over.png');
						});
						$('#noproblem-searchbox .box-close').mouseleave(function() {
							$(this).find('img').attr('src', '/img/noproblem/box-close.png');
						});

						//$('#noproblem-searchbox').effect("bounce", { times:3, distance:50 }, 400);
						$('#noproblem-searchbox').slideDown(400);
					}
				}
				else {

				}
			}
		});

	}

}

function submitNpPayment(id, payment_method) {

	if (!isNaN(parseInt(id)) && payment_method) {

		var error = false;

		$('.np-banklink .bank-list ul').hide();
		$('.np-banklink .bank-list').append('<div class="loading"></div>');

		$.ajax({
			type: 'POST',
			cache: false,
			dataType: 'json',
			url: '/scripts/noproblem.php?action=getPaymentForm',
			data: {'payment_method': payment_method, 'id': id},
			success: function(data) {
				
				if (data.success == true) {

					if (data.form) {
						$('#np_payment_form').html(data.form);
						$('#np_payment_form form').submit();
					}
					else {
						error = true;
					}
					
				}

				if (data.success == false || error) {
					$('.np-banklink .bank-list ul').show();
					$('.np-banklink .bank-list .loading').remove();
				}
			}
		});
	}

}

var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
};

(function( $ ){

	var settings = {
		'toggleDiv'			: '',
		'effect'			: 'fadeToggle',
		'effectSpeed'		: 'fast'
	};

	var effectRunning = false;

	var methods = {

		init : function(options) {

			return this.each(function() {

				if (options) { 
					$.extend(settings, options);
				}

				var targetDiv = $('#' + options['toggleDiv']);

				$(this).click(function() {
					
					if (!effectRunning) {
						effectRunning = true;

						var fn = settings['effect'];
				
						if (settings['effect'] == 'slideToggle') {
							targetDiv.slideToggle(settings['effectSpeed'], function() {
								effectRunning = false;
							});
						}
						else if (settings['effect'] == 'fadeToggle') {
							targetDiv.fadeToggle(settings['effectSpeed'], function() {
								effectRunning = false;
							});
						}
					}

					return false;

				});
				
			});

		}

	};

	$.fn.toggleDiv = function(method) {  

		if (methods[method]) {
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		} 
		else if (typeof method === 'object' || ! method) {
			return methods.init.apply(this, arguments);
		} 
		else {
			$.error('Method ' +  method + ' does not exist on jQuery.tooltip');
		}

	}; 

})( jQuery );
