$(function(){
	
	// Height and Width Display
	var w = $(window).width();
	var h = $(window).height();
	
	// External Links JS
	$('a.outside_link').click( function() {
        window.open(this.href);
        return false;
        });
	
	// Menu Location Hand
	$('#menu-primary li.current-menu-item').prepend('<div class="pink_hand"></div>')



	// Sidebar JS - rollover function (being used?) << SIDEBAR
	$('#sidebar .item').hover(function(){
		$(this).children('div.container, div.container_bg').stop().animate({height:'145px'});
	}, function(){
		$(this).children('div.container, div.container_bg').stop().animate({height:'35px'});
	});
	// Twitter Sidebar
	$("#tweets").tweet({
    	query: "@perennialplate",
    	avatar_size: 32,
    	count: 15,
    	loading_text: "loading tweets..."
        });
	// Signup Form
	$('#sidebar #SignUp table').prepend('<tr><td colspan="2" style="text-align:center;padding:4px 0;"><h5>Join our Mailing List</h5></td></tr>');	
  	$('#kickstart').load('/wp-content/themes/perennialplate/kickstart.php .project-card-wrap', function(){
                $(this).prepend('<a href="http://www.kickstarter.com/projects/588580164/the-perennial-plate-sustainable-food-series-films" class="outside_link" target="_blank"><img src="http://www.theperennialplate.com/wp-content/themes/perennialplate/img/layout/sidebar/show-your-love.png"></a>');
        });

	// Set episodes listing sizes << EPISODES PAGE
	if (w < 1125) {
		var ep_img_h = w * .15;
		$('#episodes div.episode a.ep_image img').css('width','150px'); 
		$('#episodes div.episode div.info').css('height','84px');
	} else { 
		$('#episodes div.episode a.ep_image img').css('width','210px');
		$('#episodes div.episode div.info').css('height','118px');
	}
	// Spacing JS
	    $('#episodes div.episode:nth-child(even)').css('margin-right','5%');
	

	// iFrame Styling << GOOGLE FORMS
  	 $(window).bind("load", function() {
   	 var head = $("iframe.google_doc").contents().find("head");  
	    var url = 'http://pp.lyradesigns.com/wp-content/themes/perennialplate/form.css';
	    head.append($("<link/>", 
	        { rel: "stylesheet", href: url, type: "text/css" }
	    ));  
	});
	// Forms
	$('#form').find('br').remove();


// << WINDOW RESIZE

	window.onresize = function() {
		
		// Height and Width resize
		var w = $(window).width();
		var h = $(window).height();
		
		$('#top_hr').css('width', w); // Top HR width set
		
		// Resize Home Video Sizes
		var content_w = $('#content_wrap').width();
		var video_w = content_w;
		var video_h = video_w * .5617;
		$('#content_wrap #home_videos #video_accordion, #content_wrap #home_videos #video_accordion iframe').width(video_w).height(video_h);
		
		if (w < 1125) {
			var ep_img_h = w * .15;
			$('#episodes div.episode a.ep_image img').css('width','150px'); 
			$('#episodes div.episode div.info').css('height','84px');
		} else { 
			$('#episodes div.episode a.ep_image img').css('width','210px');
			$('#episodes div.episode div.info').css('height','118px');
		}

	}


	$('#map_dropdown_btn').click(function(){
		if ($('#map_dropdown').height() == '750') {
			$('#map_dropdown').animate({height:0, top: '32px'});
			$('#overlay').css('display','none');
			$('#map_dropdown_btn').html('see where we are');
			return false;
		} else {
			$('#map_dropdown').animate({height:750, top:'40px'});
			$('#overlay').css('display','block');
			$('#map_dropdown_btn').html('>> Close Map ');
			if ($('#dropdown_map_embed').html()) {} else {
				$('#dropdown_map_embed').html('<iframe width="925" height="855" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://trackmytour.com/4976" style="margin-top:-105px;margin-left:0">');
			}
			return false;
		}
	});
	$('#overlay').click(function(){
		$('#map_dropdown').animate({height:0, top: '32px'});
		$('#map_dropdown_btn').html('see where we are');
		$(this).css('display','none');
	});


});


