jQuery(document).ready(function($) {
    //alert('sdfsdf');

	// Print function
	// Possible to grab link, open it as new window and strip the content so only certain content are displayed
	$('.post_print').click(function() {
		$('.post_content').show();
		$('#map').show();
		$(this).parent().parent().html();
		myWindow=window.open('','MyNewWindow','scrollbars=yes,width=600,height=500,left=200,top=100');
		myWindow.document.write($(this).parent().parent().html());
		myWindow.document.close();
		$('.post_meta', myWindow.document).hide();
		myWindow.print();
		myWindow.focus();
	})
	
	if ($('#map').is('#map')) {
		if ($('#map_directions').is('#map_directions')) {
			$('<span></span>').attr({'id': 'maps_tab'})
				.append('<span class="post_show">Post</span><span class="map_show">Map</span><span class="directions_show">Directions</span>')
				.insertAfter('.post_date');
		}
		else {
			$('<span></span>').attr({'id': 'maps_tab'})
				.append('<span class="post_show">Post</span><span class="map_show">Map</span>')
				.insertAfter('.post_date');
		}
		$('.map_show').addClass('maps_highlighted');
			
		/* 
		$('<div></div>').attr({'class': 'clear'})
			.insertAfter('#maps_tab');
		*/
			
		$('#map').hide();
		$('#map_directions').hide();
		
		$('.directions_show').click(function() {
			$('#map_directions').html();
			myWindow=window.open('','DirectionsWindow','scrollbars=yes,width=600,height=500,left=200,top=100');
			myWindow.document.write($('#map_directions').html());
			myWindow.document.close();
			$('.post_meta', myWindow.document).hide();
			myWindow.focus();
		});
		
		$('.post_show').click(function() {
			$('#map').hide();
			$('.post_content').show();
			$('.map_show').addClass('maps_highlighted');
			$(this).removeClass('maps_highlighted');
		});
		
		$('.map_show').click(function() {
			$('#map').show();
			$('.post_content').hide();
			$('.post_show').addClass('maps_highlighted');
			$(this).removeClass('maps_highlighted');
		});
	}
	
});

var timeout    = 0;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
	jQuery(this).addClass('page_nav_hover');
   ddmenuitem = jQuery(this).find('ul').css('visibility', 'visible'); }

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  
	jQuery(this).removeClass('page_nav_hover');
	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

jQuery(document).ready(function($) {
	$('#page_nav > li').bind('mouseover', jsddm_open);
   	$('#page_nav > li').bind('mouseout',  jsddm_timer);
});

jQuery(document).onclick = jsddm_close;

jQuery(document).ready(function($) {
	$('.post_meta > .post_read_more').each(function(i) {
		// alert('found one');
		if ($(this).parent().parent().find('.more-link').is('.more-link')) {
			// Do nothing
		}
		else {
			$(this).hide();
		}
	});
});

jQuery(document).ready(function($) {
	$('<li><form></form></li>').attr({'id': 'tag_pulldown'})
		.append('<select size="1"><option value="">By City</option><option value="daegu">Daegu</option><option value="pusan">Busan</option><option value="seoul">Seoul</option><option value="other">Other</option></select>')
		.insertAfter('#page_nav > li:last-child');
	/*
	$('<li><form></form></li>').attr({'id': 'tag_pulldown'})
		.append('<select size="1"><option value="">By City</option><option value="daegu">Daegu</option><option value="pusan">Pusan</option><option value="seoul">Seoul</option></select>')
		.insertAfter('#top_nav > ul > li:last-child');
	*/
		
	$('#tag_pulldown > select').change(function() {
		var str = "";
		
	    $("select option:selected").each(function () {
			str = $(this).val();
			if (str == 'other') {
				open('http://www.theoneonefour.com/other/','_self')
			}
			else {
				open('http://www.theoneonefour.com/tag/'+str,'_self')
			}
			//alert(str);
		});
		
	});

});

/*
jQuery(document).ready(function($) {
	$('.post_meta > .post_read_more').each(function(i) {
		// alert('found one');
		if (jQuery(this).parent('.more-link')) {
			// Do nothing
			alert('ergo')
		}
		else {
			alert('got it');
		}
	});
});
*/
