/*
 * added by bmw748@gmail.com
 */
var $j = jQuery.noConflict();
var share = {
	message: null,
	open: function (dialog) {
		// add padding to the buttons in firefox/mozilla
		if ($j.browser.mozilla) {
			$j('#share-container .contact-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($j.browser.safari) {
			$j('#share-container .contact-input').css({
				'font-size': '.9em'
			});
		}
		var share_title = $j('#share-container .contact-title').html();
		$j('#share-container .contact-title').html('Opening');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$j('#share-container .contact-content').animate({
						height: 500
					}, function () {
						$j('#share-container .contact-title').html(share_title);
						$j('#share-container form').fadeIn(200, function () {
                            $j('#share-container #post_to_field').fadeIn(200);
                            $j('#share-container #copy_paste_field').fadeIn(200);
                            $j('#share-container #send_email_field').fadeIn(200);
							
							var url = '';
							if (share_type == 'loc') {
								url = document.getElementById("loc_url").value + "&mt=" + document.getElementById("maptype").value + "&z=" + document.getElementById("zoomlevel").value;
								$j('#share-container #copy_paste_url').val(url);
								document.getElementById("facebook_link").href = "http://www.facebook.com/sharer.php?u=" + url + "&t=" + document.getElementById("loc_title").value;
								document.getElementById("digg_link").href = "http://digg.com/submit?phase=2&url=" + url + "&title=" + document.getElementById("loc_title").value + "&bodytext=" + document.getElementById("loc_content").value;
								document.getElementById("myspace_link").href = "http://www.myspace.com/Modules/PostTo/Pages/?t=" + document.getElementById("loc_title").value + "&c=" + document.getElementById("loc_content").value + "&u=" + url + "&l=1";
								document.getElementById("delicious_link").href = "http://del.icio.us/post?v=4&noui&jump=close&url=" + url + "&title=" + document.getElementById("loc_title").value;
								document.getElementById("stumbleupon_link").href = "http://www.stumbleupon.com/submit?url=" + url + "&title=" + document.getElementById("loc_title").value;
								document.getElementById("mail_link").href = "mailto:?subject=" + document.getElementById("loc_title").value + "&body=" + url;
							} else if (share_type == 'art') {
								url = document.getElementById("art_url").value + "&mt=" + document.getElementById("maptype").value + "&z=" + document.getElementById("zoomlevel").value;
								$j('#share-container #copy_paste_url').val(url);
								document.getElementById("facebook_link").href = "http://www.facebook.com/sharer.php?u=" + url + "&t=" + document.getElementById("art_title").value;
								document.getElementById("digg_link").href = "http://digg.com/submit?phase=2&url=" + url + "&title=" + document.getElementById("art_title").value + "&bodytext=" + document.getElementById("art_content").innerHTML;
								document.getElementById("myspace_link").href = "http://www.myspace.com/Modules/PostTo/Pages/?t=" + document.getElementById("art_title").value + "&c=" + document.getElementById("art_content").innerHTML + "&u=" + url + "&l=1";
								document.getElementById("delicious_link").href = "http://del.icio.us/post?v=4&noui&jump=close&url=" + url + "&title=" + document.getElementById("art_title").value;
								document.getElementById("stumbleupon_link").href = "http://www.stumbleupon.com/submit?url=" + url + "&title=" + document.getElementById("art_title").value;
								document.getElementById("mail_link").href = "mailto:?subject="+document.getElementById("art_title").value+"&body="+url;
							}

							// fix png's for IE 6
							if ($j.browser.msie && $j.browser.version < 7) {
								$j('#share-container .contact-button').each(function () {
									if ($j(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
										var src = RegExp.$1;
										$j(this).css({
											backgroundImage: 'none',
											filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'                       
										});
									}
								});
							}
						});
					});
				});
			});
		});
	},
	show: function (dialog) {
		$j('#share-container .contact-send').click(function (e) {
			e.preventDefault();
			// validate form
				$j('#share-container .contact-message').fadeOut(function () {
					$j('#share-container .contact-message').removeClass('contact-error').empty();
				});
				$j('#share-container .contact-title').html('Seending');
				$j('#share-container form').fadeOut(200);
				$j('#share-container .contact-content').animate({
					height: '80px'
				}, function () {});
		});
	},
	close: function (dialog) {
        $j('#share-container #cancel_div').fadeOut();
		$j('#share-container .contact-message').fadeOut();
		$j('#share-container .contact-title').html('Closing...');
		$j('#share-container #login_accordin').fadeOut(200);
		$j('#share-container #login_admin_accordin').fadeOut(200);
		$j('#share-container form').fadeOut(200);
		$j('#share-container .contact-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$j.modal.close();
                        $j('#map-container').css({"visibility":"visible"});
					});
				});
			});
		});
	},
	
	showError: function () {
		$j('#share-container .contact-message')
			.html($j('<div class="contact-error">').append(contact.message))
			.fadeIn(200);
	}
};

var newlocation = {
	message: null,
	open: function (dialog) {
		// add padding to the buttons in firefox/mozilla
		if ($j.browser.mozilla) {
			$j('#newlocation-container .contact-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($j.browser.safari) {
			$j('#newlocation-container .contact-input').css({
				'font-size': '.9em'
			});
		}
		var newlocation_title = $j('#newlocation-container .contact-title').html();
		$j('#newlocation-container .contact-title').html('Opening');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$j('#newlocation-container .contact-content').animate({
						height: 500
					}, function () {
						$j('#newlocation-container .contact-title').html(newlocation_title);
						$j('#newlocation-container form').fadeIn(200, function () {
                            $j('#newlocation-container #add_new').fadeIn(200);
						});
					});
				});
			});
		});
	},
	show: function (dialog) {
		$j('#newlocation-container .contact-send').click(function (e) {
			e.preventDefault();
			// validate form
				$j('#newlocation-container .contact-message').fadeOut(function () {
					$j('#newlocation-container .contact-message').removeClass('contact-error').empty();
				});
				$j('#newlocation-container .contact-title').html('Sending');
				$j('#newlocation-container form').fadeOut(200);
				$j('#newlocation-container .contact-content').animate({
					height: '80px'
				}, function () {});
		});
	},
	close: function (dialog) {
        $j('#newlocation-container #cancel_div').fadeOut();
		$j('#newlocation-container .contact-message').fadeOut();
		$j('#newlocation-container .contact-title').html('Closing...');
		$j('#newlocation-container #login_accordin').fadeOut(200);
		$j('#newlocation-container #login_admin_accordin').fadeOut(200);
		$j('#newlocation-container form').fadeOut(200);
		$j('#newlocation-container .contact-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$j.modal.close();
                        $j('#map-container').css({"visibility":"visible"});
					});
				});
			});
		});
	},
	
	showError: function () {
		$j('#newlocation-container .contact-message')
			.html($j('<div class="contact-error">').append(contact.message))
			.fadeIn(200);
	}
};