// GLOBAL VARIABLES - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool_ajax_enabled = true;
bool_mobile = false;
int_min_window_width = 980;
int_min_window_height = 650;
int_barheight = 55;
bool_contain_layout = true;
int_beat = 750;
int_slide_delay = 10000;
int_loading_delay = 250;
str_path_home = "home";
str_backpanel_path = "assets/backpanels/";
str_section_current = "";
array_path = new Array();
str_transition_current = 'fade';
str_index_id_current = 'index-a';
str_index_id_standby = 'index-b';
str_siteurl = "http://www.planetpropaganda.com";

// INITIALIZE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$(document).ready(function(){
	proportion_index();
	show_loading_overlay();
	load_panel(location.hash);
	$(window).hashchange( function(){
		show_clicklock_overlay();
		show_loading_overlay();
		load_panel(location.hash);
	});
	str_userAgent = navigator.userAgent;
	regex_mobile = /android|ip(hone|od|ad)/i;
	if (str_userAgent.match(regex_mobile)){ bool_mobile = true; }
	
	if (bool_mobile){
		$(document).swipe( { swipeLeft:swipe_left_handler, swipeRight:swipe_right_handler, triggerOnTouchEnd:false, threshold:50 } );
	} else {
		$(document).jkey('left',function(){ key_left_handler(); });
		$(document).jkey('right',function(){ key_right_handler(); });
	}
});
$(window).resize(function(){ proportion_index(); });

// Special Interface Action Handlers
function action_left(){}
function action_right(){}
function key_left_handler(){ if (!$('#clicklock').is(':visible')){ action_left(); }}
function key_right_handler(){ if (!$('#clicklock').is(':visible')){ action_right(); }}
function swipe_left_handler(event){ if (!$('#clicklock').is(':visible')){ action_right(); }}
function swipe_right_handler(event){ if (!$('#clicklock').is(':visible')){ action_left(); }}

// INDEX APPARATUS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function proportion_index(){
	int_window_width = $(window).width();
	int_window_height = $(window).height();
	if (int_window_width <= int_min_window_width) { int_window_width = int_min_window_width; }
	if (int_window_height <= int_min_window_height) { int_window_height = int_min_window_height; }
	int_window_halfheight = (int_window_height / 2) + (int_barheight / 2);
	var int_overheight = 0;
	if (bool_contain_layout){
		$('#container').height(int_window_height);
		$('.panel').height(int_window_height);
		$('.subpanel').height(int_window_height);
		$('.backpanel').css('position', 'absolute');
		int_overheight = int_barheight;
	} else {
		var int_height_scroll;
		if ($('#' + str_index_id_current + ' #scrollpanel').height() > int_window_height){ int_height_scroll = $('#' + str_index_id_current + ' #scrollpanel').height(); } else { int_height_scroll = int_window_height; }
		$('#container').height(int_height_scroll);
		$('.panel').height(int_height_scroll);
		$('.subpanel').height(int_height_scroll);
		$('.backpanel').css('position', 'fixed');
		if (bool_mobile){ int_overheight = int_barheight + 340; }
		else { int_overheight = int_barheight; }
	}
	$('.overlay').height(int_window_height + int_overheight);
	if (int_window_width > (int_window_height + int_overheight)) {
		$('.backpanel img').css('width', int_window_width); $('.backpanel img').css('height', 'auto');
		$('.block.map').css('width', int_window_width); $('.block.map').css('height', int_window_width);
	} else { 
		$('.backpanel img').css('width', 'auto'); $('.backpanel img').css('height', (int_window_height + int_overheight));
		$('.block.map').css('width', (int_window_height + int_overheight)); $('.block.map').css('height', (int_window_height + int_overheight));
	}
	$('.hcenter').each(function(index){ $(this).css('left', ((int_window_width / 2) - ($(this).width() / 2))); });
	$('.vcenter').each(function(index){ $(this).css('top', (int_window_halfheight - ($(this).height() / 2))); });
	$('.sidebutton').each(function(index){ $(this).css('top', (int_window_halfheight - ($(this).height() / 2))); });
	switch(str_section_current) {
		case 'home':proportion_home(); break;
		case 'work':proportion_work(); break;
		case 'work-overview':proportion_workoverview(); break;
		case 'work-project':proportion_workproject(); break;
		case 'portfolio':proportion_workoverview(); break;
		case 'portfolio-project':proportion_workproject(); break; 
		case 'project':proportion_workproject(); break;
		case 'projects':proportion_workproject(); break; 
		case 'about':proportion_about(); break;
		case 'blog':proportion_blog(); break;
	}
}

// Panel Call
function call_panel(param_str_path, param_str_transition){
	if(window.location.hash != param_str_path){
		str_transition_current = param_str_transition;
		window.location = param_str_path;
		return true;
	} else {
		return false;
	}
}

// Panel Load
function load_panel(param_str_path){
	param_str_path = param_str_path.replace('#!/', '');
	proportion_index();
	bool_contain_layout = true;
	var panel_next = $('#' + str_index_id_standby)
	panel_next.css('left', 0);
	panel_next.css('top', 0);
	panel_next.show();
	switch(str_transition_current){
		case 'slideLeft': panel_next.css('left', -(int_window_width)); break;
		case 'slideRight': panel_next.css('left', int_window_width); break;
		case 'slideUp': panel_next.css('top', -(int_window_height)); break;
		case 'slideDown': panel_next.css('top', int_window_height); break;
		case 'fade': panel_next.fadeTo(0, 0); break;
		default: panel_next.fadeTo(0, 0); break;
	}
	if (param_str_path.length == 0) { param_str_path = str_path_home; }
	assign_sectioncurrent(param_str_path);
	panel_next.load(param_str_path, {}, function(response, status, xhr){
		if (status == 'success'){ initialize_panel(); transition_panel(); }
		else { location.hash = '!/404'; }
	});
}

function assign_sectioncurrent(param_str_path){
	str_section_current = param_str_path;
	var int_slashpos = str_section_current.search('/');
	if (int_slashpos > 0) { str_section_current = str_section_current.slice(0,int_slashpos); }
	if (str_section_current.substr(-1) == '/'){ str_section_current = str_section_current.slice(0,-1); }
}

function initialize_panel(){
	$('#' + str_index_id_current + ' #scrollpanel').css('marginTop', -($(window).scrollTop()) + "px");
	$('#' + str_index_id_standby + ' #scrollpanel').css('marginTop', 0);
	$('#' + str_index_id_standby + ' .subpanel').show();
	action_left = function(){}
   	action_right = function(){}
	switch(str_section_current) {
		case 'home': initialize_panel_home(); break;
		case 'work': initialize_panel_work(); break;
		case 'work-overview': initialize_panel_workoverview(); break;
		case 'work-project': initialize_panel_workproject(); break;
		case 'portfolio': initialize_panel_workoverview(); break;
		case 'portfolio-project': initialize_panel_workproject(); break;
		case 'project': initialize_panel_workproject(); break;
		case 'projects': initialize_panel_workproject(); break;
		case 'about': initialize_panel_about(); break;
		case 'blog': initialize_panel_blog(); break;
		case 'post': initialize_panel_post(); break;
		case 'method': initialize_panel_method(); break;
		case 'jobs': initialize_panel_jobs(); break;
		case 'contact': initialize_panel_contact(); break;
	}
	proportion_index();
}

function transition_panel(){
	var panel_current = $('#' + str_index_id_current);
	var panel_next = $('#' + str_index_id_standby);
	panel_current.css('zIndex', 100);
	panel_next.css('zIndex', 200);
	
	switch(str_transition_current){
		case 'slideLeft': panel_current.animate({ left:int_window_width }, int_beat); panel_next.animate({ left:0 }, int_beat); break; 
		case 'slideRight': panel_current.animate({ left:-(int_window_width) }, int_beat); panel_next.animate({ left:0 }, int_beat); break; 
		case 'slideUp': panel_current.animate({ top:int_window_height }, int_beat); panel_next.animate({ top:0 }, int_beat); break; 
		case 'slideDown': panel_current.animate({ top:-(int_window_height) }, int_beat); panel_next.animate({ top:0 }, int_beat); break;
 		case 'fade': panel_next.fadeTo(int_beat, 1, 'linear'); break
		default: panel_current.hide(); panel_next.css('opacity', 1);
	}
	
	hide_loading_overlay();
	//$('#breadcrumb .item').hide();
	//$('#breadcrumb .item:first').show();
	$('#breadcrumb .menu').hide();
	$('#breadcrumb .title').removeClass('here');
		
	$('#' + str_index_id_standby + ' .backpanel img').css('opacity', 0);
	$('#' + str_index_id_standby + ' .backpanel img').load(function(){
		//$(this).css('opacity', 1);
		$(this).animate({opacity:1}, {duration:250, easing:'linear', queue:false });
		proportion_index();
	});
	setTimeout(onComplete, int_beat);
	
	function onComplete(){
		var str_index_nextcurrent_id = str_index_id_standby;
		str_index_id_standby = str_index_id_current;
		str_index_id_current = str_index_nextcurrent_id;
		complete_panel();
		$('#' + str_index_id_standby).hide();
		$('#' + str_index_id_standby).empty();
		str_transition_current = '';
		
		var str_title = $('#' + str_index_id_current + ' .indexmeta#metatitle').html();
		if (str_title != null){ document.title = ($('#' + str_index_id_current + ' .indexmeta#metatitle').html()) + ' | Planet Propaganda'; }
		else { document.title = 'Planet Propaganda - Design + Advertising + Digital - Madison, Wisconsin'; }
		initialize_breadcrumb();

		$('.transition').unbind();
		$('.transition').removeClass('selected');
		$('.transition').each(function(){ if ($(this).attr('href').indexOf("#!") == -1){ $(this).attr('href', ('#!' + $(this).attr('href').replace(str_siteurl, ''))) }});
		$('.transition').click(function(){
			if (call_panel($(this).attr('href'), $(this).attr('class').replace('transition ', ''))){ $(this).addClass('selected'); }
			return false;
		});
		
		hide_clicklock_overlay();
		proportion_index();
	}
}

function complete_panel(){
	switch(str_section_current) {
		case 'work': complete_work(); break;
		case 'work-overview': complete_workoverview(); break;
		case 'work-project': complete_workproject(); break;
		case 'portfolio': complete_workoverview(); break;
		case 'portfolio-project': complete_workproject(); break;
		case 'project': complete_workproject(); break;
		case 'projects': complete_workproject(); break;
		case 'about': complete_about(); break;
		case 'blog': complete_blog(); break;
		case 'post': complete_post(); break;
		case 'jobs': complete_jobs(); break;
		case 'contact': complete_contact(); break;
		case 'mailing-list': complete_mailinglist(); break;
	}
}

function initialize_breadcrumb(){
	$('#breadcrumb').html(($('#' + str_index_id_current + ' .indexmeta#metabreadcrumb').html()));

	$('#breadcrumb .item').each(function(){
		int_width_title = $(this).find('.title').innerWidth();
		int_maxwidth_col = 0;
		int_totalwidth_col = 0;
		$(this).find('.menu').show();
		$(this).find('.col').each(function(){ if ($(this).innerWidth() > int_maxwidth_col){ int_maxwidth_col = $(this).width(); } });
		$(this).find('.col').width(int_maxwidth_col);
		int_totalwidth_col = (int_maxwidth_col + 20) * $(this).find('.col').length;
		$(this).find('.menu').width(int_totalwidth_col);
		if (int_width_title > (int_totalwidth_col + 20)){
			$(this).find('.menu').width(int_width_title - 20);
			$(this).find('.col').width(int_width_title - 40);
		}

		$(this).find('.menu').hide();
	});
	//$('#breadcrumb .item').hide();
	//$('#breadcrumb .item:first').show();
	$('#breadcrumb .item').hover(
		function(){ $('#topnav').height('100%'); $('#breadcrumb .title').eq($(this).index()).addClass('here'); $('#breadcrumb .menu').eq($(this).index()).slideDown(100); },
		function(){
			if (!$('#clicklock').is(':visible')){ 
				$('#topnav').height('55px');
				$('#breadcrumb .title').eq($(this).index()).removeClass('here');
				$('#breadcrumb .menu').eq($(this).index()).slideUp(0);
			}
		}
	);		

	$('#breadcrumb .item .title').click(function(){
		$(this).parent().addClass('selected');
		call_panel($(this).attr('href'), '');
		return false;
	});
	if (!$('#utilitynav').is(':visible')){ $('#utilitynav').fadeIn(int_beat); }
}



// HOME SECTION - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initialize_panel_home(){
	int_slide_current = 0;
	bool_slide_advance = true;
	timeout_slide = null;
	change_slidenav(int_slide_current);

	$('.sa-on').css('opacity', 0);

	$('#slidenav .feature').hover(
		function(){ change_slidenav($(this).index(), 0); bool_slide_advance = false; },
		function(){ bool_slide_advance = true; }
	);
	
	function change_slidenav(int_slide, int_duration){
		if (int_slide > ($("#slides .backpanel").length - 1)) { int_slide = 0; }
		var slide_current = $("#slides .backpanel").eq(int_slide_current);
		var slide_next = $("#slides .backpanel").eq(int_slide);
		$("#slides .backpanel").css('opacity', 0);
		slide_current.css('opacity', 1);
		slide_current.css('zIndex', 10);
		slide_current.animate({opacity:0}, {duration:(int_duration), easing:'linear', queue:false});
		//slide_current.animate({opacity:0}, {duration:(int_beat / 2), easing:'linear', queue:false});
		slide_next.css('zIndex', 20);
		slide_next.animate({opacity:1}, {duration:(int_duration), easing:'linear', queue:false});
		//({opacity:1}, {duration:(int_beat / 2), easing:'linear', queue:false});

		$("#slidenav a").eq(int_slide_current).removeClass('here');
		$("#slidenav a").eq(int_slide).addClass('here');
	
		int_slide_current = int_slide;
		if (bool_slide_advance){ clearTimeout(timeout_slide); timeout_slide = setTimeout(function(){ if (bool_slide_advance){ change_slidenav(int_slide_current + 1, 500); }}, int_slide_delay); }
	}
}

function proportion_home(){
	var int_max_featureheight = 0;	
	$('#footer .nav a').each(function(){
		var int_textheight = $(this).find('.title').innerHeight() + $(this).find('.description').innerHeight();
		if (int_textheight > int_max_featureheight) { int_max_featureheight = int_textheight; }
	});
	$('#footer .nav a').height(int_max_featureheight);
}

function sa_dir_on(param_dir){
	$('#sa-' + param_dir + '-on').animate({opacity:1}, {duration:(int_beat / 2), easing:'linear', queue:false});
	$('#sa-' + param_dir).animate({opacity:0}, {duration:(int_beat / 2), easing:'linear', queue:false});
}
function sa_dir_off(param_dir){
	$('#sa-' + param_dir + '-on').animate({opacity:0}, {duration:(int_beat / 2), easing:'linear', queue:false});
	$('#sa-' + param_dir).animate({opacity:1}, {duration:(int_beat / 2), easing:'linear', queue:false});
}

// WORK - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initialize_panel_work(){ 	
	$('.item img.back').css('opacity', 0);
	$('#portfoliolist .item').each(function(){ if ($(this).attr('href').indexOf("#!") == -1){ $(this).attr('href', ('#!' + $(this).attr('href').replace(str_siteurl, ''))) }});
	$('#portfoliolist .item').click(function(){
		$(this).addClass('selected');
		call_panel($(this).attr('href'), 'fade');
		return false;
	});

	$('.item').hover(
		function(){ $(this).find('img.back').animate({opacity:1},{duration:int_beat, easing:'easeOutQuint', queue:false}); $(this).find('.border').animate({backgroundColor:'rgba(268, 60, 35, 1.0)'},{duration:int_beat, easing:'easeOutQuint', queue:false}); },
		function(){ if (!$(this).hasClass('selected')){ $(this).find('img.back').animate({opacity:0},{duration:int_beat, easing:'easeInQuint', queue:false}); $(this).find('.border').animate({backgroundColor:'rgba(35, 32, 31, 0.75)'},{duration:int_beat, easing:'linear', queue:false}); }}
	);

	action_left = function(){ if ($('#button-portfoliolist-left a').is(':visible')){ $('#button-portfoliolist-left a').trigger('click'); }  }
	action_right = function(){ if ($('#button-portfoliolist-right a').is(':visible')){ $('#button-portfoliolist-right a').trigger('click'); } }

	int_list_itemwidth = 234;
	int_list_padding = 40;
	initialize_portfoliolist();
}

function complete_work(){}
function proportion_work(){ proportion_portfoliolist(); }

// Portfolio List
function initialize_portfoliolist(){
	int_now = 0;
	int_list_width = Math.ceil($('#portfoliolist .item').length / 2)  * int_list_itemwidth;
	$('#portfoliolist').css('marginLeft', int_list_padding);
	hide_portfoliolist_sidebutton('left', 0);
	hide_portfoliolist_sidebutton('right', 0);
	show_portfoliolist_sidebutton('right', int_beat);

	$('#button-portfoliolist-left a').click(function(){
		show_portfoliolist_sidebutton('right', int_beat);
		proportion_index();
		var int_list_dest = parseInt($('#portfoliolist').css('marginLeft')) + (int_list_itemsperscreen * int_list_itemwidth);
		if (int_list_dest >= int_list_padding){ int_list_dest = int_list_padding; hide_portfoliolist_sidebutton('left', int_beat); }
		$('#portfoliolist').stop();
		$('#portfoliolist').css('marginLeft', int_now);
		$('#portfoliolist').animate({marginLeft:int_list_dest},{duration:int_beat, easing:'swing', step: function(now, fx) { int_now = now; }});
		return false;
	});
	$('#button-portfoliolist-right a').click(function(){
		show_portfoliolist_sidebutton('left', int_beat);
		proportion_index();
		var int_list_dest = parseInt($('#portfoliolist').css('marginLeft')) - (int_list_itemsperscreen * int_list_itemwidth);			
		if (int_list_dest <= int_list_limit) { int_list_dest = int_list_limit; hide_portfoliolist_sidebutton('right', int_beat); }
		$('#portfoliolist').stop();
		$('#portfoliolist').css('marginLeft', int_now);
		$('#portfoliolist').animate({marginLeft:int_list_dest},{duration:int_beat, easing:'swing', step: function(now, fx) { int_now = now; }});
		return false;
	});
}

function proportion_portfoliolist(){
	int_list_itemsperscreen = Math.floor(int_window_width/int_list_itemwidth);
	int_list_limit = -(int_list_width - (int_window_width - int_list_padding));
	if (int_list_width < int_window_width) {
		$('#button-portfoliolist-left a').hide();
		$('#button-portfoliolist-right a').hide();
		$('#portfoliolist').css('marginLeft', ((int_window_width / 2) - (int_list_width / 2)));
	}	
	if (!$('#button-portfoliolist-right a').is(":visible") && $('#button-portfoliolist-left a').is(":visible")){
		if (int_list_limit != parseInt($('#portfoliolist').css('marginLeft'))){
			$('#portfoliolist').css('marginLeft', int_list_limit);
		}
	}
}

function show_portfoliolist_sidebutton(param_side, param_transition_time){
	if (param_side == 'left') { $('#button-portfoliolist-left a').show(); $('#button-portfoliolist-left').animate({left:0},{duration:param_transition_time, easing:'easeOutQuint', queue:true }); }
	else { $('#button-portfoliolist-right a').show(); $('#button-portfoliolist-right').animate({right:0},{duration:param_transition_time, easing:'easeOutQuint', queue:true }); }
}

function hide_portfoliolist_sidebutton(param_side, param_transition_time){
	if (param_side == 'left') { $('#button-portfoliolist-left').animate({left:-$(this).width()},{duration:param_transition_time, easing:'easeInQuint', queue:false, complete:function(){ if ($(this).css('left') == -$(this).width()){ $(this).find('a').hide(); }} }); }
	else { $('#button-portfoliolist-right').animate({right:-$(this).width()},{duration:param_transition_time, easing:'easeInQuint', queue:false, complete:function(){ if ($(this).css('right') == -$(this).width()){ $(this).find('a').hide(); }} }); }
}



// WORK OVERVIEW - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initialize_panel_workoverview(){ 
	$('#' + str_index_id_standby + ' #worklist .item').each(function(){ if ($(this).attr('href').indexOf("#!") == -1){ $(this).attr('href', ('#!' + $(this).attr('href').replace(str_siteurl, ''))) }});
	$('#' + str_index_id_standby + ' #worklist .item').click(function(){
		$(this).addClass('selected');
		call_panel($(this).attr('href'), '');
		return false;
	});
	if ($('#' + str_index_id_standby + ' .overview').height() < 250){ $('#' + str_index_id_standby + ' .overview').css('marginTop', (125 - ($('#' + str_index_id_standby + ' .overview').height() / 2))); }
	$('#' + str_index_id_standby + ' #worklist .subtitle').each(function(index){ $(this).css('marginTop', (17 - ($(this).height() / 2))); });
	
	action_right = function(){ $('#button-viewwork').trigger('click'); }
	
	//alert($(window).width() + " / 2 = " + ($(window).width() / 2));
}
function complete_workoverview(){}
function proportion_workoverview(){}
	
	
// WORK PROJECT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var bool_proportion_projectlist;
function initialize_panel_workproject(){ 
	bool_proportion_projectlist = false;
	initialize_projectlist();
	
	action_left = function(){ if ($('#button-projectlist-left a').is(':visible')){ $('#button-projectlist-left a').trigger('click'); } else if ($('#button-worklist-left a').is(':visible')){ $('#button-worklist-left a').trigger('click'); }  }
	action_right = function(){ if ($('#button-projectlist-right a').is(':visible')){ $('#button-projectlist-right a').trigger('click'); } else if ($('#button-worklist-right a').is(':visible')){ $('#button-worklist-right a').trigger('click'); } }
}

function complete_workproject(){ bool_proportion_projectlist = true; }
function proportion_workproject(){ proportion_projectlist(); }

// Project List
function initialize_projectlist(){	
	int_now = 0;
	$('#' + str_index_id_standby + ' #projectlist .item').css('opacity', .4);
	
	// Item Array
	array_projectlist_item = new Array();
	int_projectlist_itemcount = 0;
	int_projectlist_currentitem = 0;
	int_projectlist_width = 0;
	$('#' + str_index_id_standby + ' #projectlist .item').each(function(){
		array_projectlist_item[int_projectlist_itemcount] = new Array();
		array_projectlist_item[int_projectlist_itemcount]['index'] = $(this).index();
		array_projectlist_item[int_projectlist_itemcount]['width'] = $(this).width() + (parseInt($(this).css('paddingLeft')) * 2);
		array_projectlist_item[int_projectlist_itemcount]['x'] = int_projectlist_width;
		int_projectlist_width += array_projectlist_item[int_projectlist_itemcount]['width'];
		if ($(this).height() < 520){ $(this).css('marginTop', ((520 / 2) - ($(this).height() / 2))); }
		int_projectlist_itemcount++;
	});

	//$('#' + str_index_id_standby + ' #projectlist .item img').load(function(){ alert($(this).parent().height()); if ($(this).parent().height() < 520){ $(this).parent().css('marginTop', ((520 / 2) - ($(this).parent().height() / 2))); } });
	$('#' + str_index_id_standby + ' #projectlist .item.flash object').hide();
	
	// Scroll Buttons
	$('#' + str_index_id_standby + ' #button-projectlist-left a').click(function(){ change_projectlist_item(int_projectlist_currentitem - 1, int_beat, str_index_id_current); return false; });
	$('#' + str_index_id_standby + ' #button-projectlist-right a').click(function(){ change_projectlist_item(int_projectlist_currentitem + 1, int_beat, str_index_id_current); return false; });

	change_projectlist_item(0, 0, str_index_id_standby);
}

function change_projectlist_item(param_int_item, param_transition_time, param_id){
	if (param_int_item == 0){
		$('#' + param_id + ' #button-projectlist-left a').hide();
		$('#' + param_id + ' #button-worklist-left a').show();
	} else {
		$('#' + param_id + ' #button-projectlist-left a').show();
		$('#' + param_id + ' #button-worklist-left a').hide();
	}
	if (param_int_item == (int_projectlist_itemcount - 1)){
		$('#' + param_id + ' #button-projectlist-right a').hide();
		$('#' + param_id + ' #button-worklist-right a').show();
	} else {
		$('#' + param_id + ' #button-projectlist-right a').show();
		$('#' + param_id + ' #button-worklist-right a').hide();
	}
	
	if ($('#' + param_id + ' #projectlist .item').eq(int_projectlist_currentitem).hasClass('flash')){
		$('#' + param_id + ' #projectlist .item').eq(int_projectlist_currentitem).find('object').hide();
		$('#' + param_id + ' #projectlist .item').eq(int_projectlist_currentitem).find('object').empty();
	}
	if ($('#' + param_id + ' #projectlist .item').eq(param_int_item).hasClass('flash')){
		setTimeout(function(){
			$('#' + param_id + ' #projectlist .item').eq(param_int_item).find('object').show();
			flashvars = {},
			params = {wmode:"opaque"},
			attributes = {};
			swfobject.embedSWF(array_project_flash[(param_int_item + 1)]['swf'], "swf-" + (param_int_item + 1), array_project_flash[(param_int_item + 1)]['width'], array_project_flash[(param_int_item + 1)]['height'], "9.0.0", "/images/swf/expressInstall.swf", flashvars, params, attributes);
		}, param_transition_time);
	}

	$('#' + param_id + ' #projectlist .item').eq(int_projectlist_currentitem).animate({opacity:.4},{duration:param_transition_time, easing:'linear', queue:false});
	int_projectlist_currentitem = param_int_item;
	$('#' + param_id + ' #projectlist .item').eq(int_projectlist_currentitem).animate({opacity:1},{duration:param_transition_time, easing:'linear', queue:false});
	var int_list_dest = -(array_projectlist_item[int_projectlist_currentitem]['x']) + (int_window_width / 2) - (array_projectlist_item[int_projectlist_currentitem]['width'] / 2);
	$('#' + param_id + ' #projectlist').stop();
	$('#' + param_id + ' #projectlist').css('marginLeft', int_now);
	$('#' + param_id + ' #projectlist').animate({marginLeft:int_list_dest},{duration:param_transition_time, easing:'swing', step:function(now, fx) { int_now = now; }});
}

function proportion_projectlist(){
	if (bool_proportion_projectlist){
		var int_list_dest = -(array_projectlist_item[int_projectlist_currentitem]['x']) + (int_window_width / 2) - (array_projectlist_item[int_projectlist_currentitem]['width'] / 2);
		$('#' + str_index_id_current + ' #projectlist').css('marginLeft', int_list_dest);
	}
}



// ABOUT SECTION - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initialize_panel_about(){
	$('#' + str_index_id_standby + ' #history-more-link').click(function(){
		$('#history-more-link').slideUp(0);
		$('#history-more-content').slideDown(0, function(){ proportion_index(); });
		return false;
	});
	$('#' + str_index_id_standby + ' #history-less-link').click(function(){
		$('#history-more-link').slideDown(0);
		$('#history-more-content').slideUp(0, function(){ proportion_index(); });
		return false;
	});
	
	/*$('#' + str_index_id_standby + ' #history').resize(function(){ proportion_index(); });*/
	
}

function complete_about(){ bool_contain_layout = false; }

function proportion_about(){}



// JOB SECTION - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initialize_panel_jobs(){
	layout_contentcol(str_index_id_standby);
}

function complete_jobs(){
	bool_contain_layout = false;
	layout_contentcol(str_index_id_current);	
}

function proportion_jobs(){}



// BLOG SECTION - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initialize_panel_blog(){
	layout_contentcol(str_index_id_standby);
	
	$('#' + str_index_id_standby + ' #categories').click(function(){
		if ($(this).find('.menu').is(":visible")){ $(this).removeClass('open'); $('#categories .menu').slideUp(); }
		else{ $(this).addClass('open'); $('#categories .menu').slideDown(); }
	});
}

function complete_blog(){
	bool_contain_layout = false;
	$(document).ready(function() {
    	$(".tweet").tweet({
	        username: "plntprpgnda",
	        join_text: "auto",
	        avatar_size: 32,
	        count:1,
			fetch: 10,
	        filter: function(t){ return ! /^@\w+/.test(t["tweet_raw_text"]); },
	        loading_text: "Refreshing Tweet...",
			template: function(i){return i["text"]}
	    });
    });
	layout_contentcol(str_index_id_current);
}

function proportion_blog(){}

function layout_contentcol(str_id){
	var px_leftcol = 0;
	var px_rightcol = 368;
	var px_bottommargin = 28;
	var int_col1_height = 0;
	var int_col2_height = 0;
	array_blog = new Array();
	$('#' + str_id + ' .contentcol .contentbox').each(function(){
		var int_post_height = $(this).height();
		if ((int_col1_height + int_post_height) <= (int_col2_height + int_post_height)) {
			$(this).css('margin', (int_col1_height + 'px 0 0 0'));
			int_col1_height += int_post_height + px_bottommargin;
		} else {
			$(this).css('margin', (int_col2_height + 'px 0 0 ' + px_rightcol + 'px'));
			int_col2_height += int_post_height + px_bottommargin;
		}
	});
	if (int_col1_height >= int_col2_height) { $('#' + str_id + ' .contentcol').height(int_col1_height); }
	else { $('#' + str_id + ' .contentcol').height(int_col2_height); }   
}

// BLOG POST - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initialize_panel_post(){
	if ($('#' + str_index_id_standby + ' #slideshow').length){ initialize_slideshow(); }

	if ($('#' + str_index_id_standby + ' #slideshow .item').length < 3){	
		action_left = function(){ if ($('#button-post-left a').is(':visible')){ $('#button-post-left a').trigger('click'); } }
		action_right = function(){ if ($('#button-post-right a').is(':visible')){ $('#button-post-right a').trigger('click'); } }
	} else {
		action_left = function(){ if ($('#slideshow .prev.browse.left').is(':visible')){ $('#slideshow .prev.browse.left').trigger('click'); }  }
		action_right = function(){ if ($('#slideshow .next.browse.right').is(':visible')){ $('#slideshow .next.browse.right').trigger('click'); }  }
	}

	$('#' + str_index_id_standby + ' #comments').resize(function(){ proportion_index(); });
}

function complete_post(){
	bool_contain_layout = false;

    var disqus_shortname = 'planetpropaganda';
	var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
	dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
	document.getElementById(str_index_id_current).appendChild(dsq);
}

function proportion_post(){}



// METHOD SECTION - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initialize_panel_method(){
	int_slide_method_current = 0;
	int_slide_max = 7;
	int_slide_width = $('#captions .list div').innerWidth();

	$('.method-on').css('opacity', 0);
	
	$('#arrow-left').hide();
	$('#arrow-left').click(function(){		
		change_method_slide(int_slide_method_current - 1);
		return false;
	});
	
	$('#arrow-right').click(function(){
		change_method_slide(int_slide_method_current + 1);
		return false;
	});	

	action_left = function(){ if ($('#arrow-left').is(':visible')){ $('#arrow-left').trigger('click'); } }
	action_right = function(){ if ($('#arrow-right').is(':visible')){ $('#arrow-right').trigger('click'); } }
	
	change_method_slide(0);
}

function proportion_method(){}

function change_method_slide(param_int){
	//console.log('PRE int_slide_method_current = ' + int_slide_method_current);
	$('.method-on').animate({opacity:0}, {duration:(int_beat / 2), easing:'linear', queue:false });
	$('#method-' + param_int).animate({opacity:1}, {duration:(int_beat / 2), easing:'linear', queue:false });
	int_slide_method_current = param_int;
	if (int_slide_method_current == 0){ $('#arrow-left').hide(); } else { $('#arrow-left').show(); }
	if (int_slide_method_current == int_slide_max){ $('#arrow-right').hide(); } else { $('#arrow-right').show(); }
	$('#captions #scrollwindow .list').animate({marginLeft:-(int_slide_method_current * int_slide_width)},{duration:(int_beat / 2), easing:'linear', queue:false});
	//console.log('POST int_slide_method_current = ' + int_slide_method_current);
}

function sa_method_over(param_int){
	if (param_int != int_slide_method_current){ $('#method-' + param_int).animate({opacity:.5}, {duration:(int_beat / 2), easing:'linear', queue:false });	}
}

function sa_method_out(param_int){
	if (param_int != int_slide_method_current){ $('#method-' + param_int).animate({opacity:0}, {duration:(int_beat / 2), easing:'linear', queue:false }); }
}

// CONTACT SECTION - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initialize_panel_contact(){
	var haunts = [
		{title: 'The Mason Lounge', address: '416 South Park Street, Madison, WI', tele: '(608) 255-7777', description: 'Craft beer bar focused on Hoppy American Ales. Get a pizza from Falbo Bros. next door and bring it in. Tell Bryan we say hi.'},
		{title: 'High Noon Saloon', address: '701 E Washington Ave, Madison, WI', tele: '(608) 268-1122)', description: 'The High Noon is a phoenix that rose from the ashes of O’Cayz Corral, which burned down in 2000. It’s a perfect mix of live music and cold beer.'},
		{title: 'Nostrano', address: '111 S Hamilton St, Madison, WI', tele: '(608) 395-3295', description: 'Two expats from Chicago’s Blackbird, Nostrano is a beacon for foodies seeking haute, yet casual, cuisine. Local. Organic. Lunch, Dinner, Craft Cocktails.'},
		{title: 'Weary Traveler', address: '1201 Williamson St, Madison, WI', tele: '608.442.6207', description: ' Perfect Madison bar for drinkin’/perfect Madison bar for eatin’. Locally sourced food. Gets busy though so groups might be tight. Brunch, Lunch, Dinner, Drinks, Late.v'},
		{title: 'Jolly Bob’s Jerk Joint', address: '1210 Williamson St, Madison, WI', tele: '', description: 'Across the street from the Weary. Jerk food, reggae, rum. If that works for you, then Jolly Bob works for you. Dinner only, I believe. Casual.'},
		{title: 'Sardine', address: '617 Williamson St., Madison, WI', tele: '608.441.1600', description: 'Classy/cool joint. Excellent food. Nice bar as well (and my favorite bartenders in town). In a loft space right on Lake Mendota (next to Planet HQ!). Definitely leaning more upscale, but casual is ok. It’s Madison afterall. Brunch, dinner, drinks, late.'},
		{title: 'Lao Laan Xang', address: '2098 Atwood Avenue, Madison, WI', tele: '608.819.0140', description: 'Laotian. Wicked good. Strong vegetarian selection. Lunch, dinner.'},
		{title: 'Natt Spil', address: '211 King St, Madison, WI', tele: '608.258.8787', description: 'Cozy, groovy place. No sign outside, don’t accept plastic, must have just recently gotten a phone. Great wood fired pizzas and apps and ambiance. It’s the small maroon-ish colored building between Muramoto and the Great Dane. Gets crowded so probably not ideal for larger groups. Dinner, drinks, late.'},
		{title: 'Restaurant Muramoto', address: '225 King St, Madison, WI', tele: '608.259.1040', description: 'Really good sushi. In Madison. I know! Roomy restaurant, but with a good vibe. Yummy in my tummy. Lunch, dinner.'},
		{title: 'The Great Dane Brew Pub', address: '123 E. Doty, Madison, WI', tele: '608.284.0000', description: 'These guys brew really solid beer. Food is lots of brew pub type options. Larger space is good for groups. Also, shuffleboard, darts, pool tables. Downstairs bar is a little cozier. Lunch, dinner, drinks, late.'},
		//{title: 'The Haze', address: '106 King St, Madison, WI ', tele: '608.260.2680', description: 'Same owner as Muramoto, smaller more casual place. Asian and American bar-b-que. Lunch, dinner.'},
		
		{title: 'Brocach', address: '7 West Main St, Madison, WI', tele: '608.255.2015', description: 'Irish pub right on the capital square. Cool decor, room for groups. Great place for a black & tan. Lunch, dinner, drinks, late.'},
		{title: 'Himal Chuli', address: '318 State Street, Madison, WI', tele: '608.251.9225', description: 'Nepalese. Small but very popular. Strong vegetarian selection. Lunch and dinner.'},
		{title: 'Chautara', address: '334 State Street, Madison, WI', tele: '608.251.3626', description: 'Indian/Tibetan/Nepalese. Also very popular. Strong vegetarian. Lunch and Dinner.'},
		{title: 'The Old Fashioned', address: '23 North Pinckney St., Madison, WI', tele: '608.310.4545', description: 'Wisconsin-tavern inspired place on the capital square. If you want some of that old Sconnie flavor, with a current twist, this would be the place. Huge servings. Lunch, dinner, drinks, late.'},
		{title: 'Tornado Steak House', address: '116 South Hamilton, Madison, WI', tele: '608.256.3570', description: 'Great place for steak. Supper club vibe. Right off the capital square. Dinner from 5 – 10pm, and great late night food til 1 am.'},
		{title: 'The Plaza', address: '319 North Henry Street, Madison, WI', tele: '608.255.6592', description: 'A Madison institution bar. A touch divey, in the best way. Try a Plazaburger, a kind of sad looking burger drenched in secret plaza sauce that will rock your world. Located just off State Street. Also pool, bubble hockey, etc. Lunch, dinner, late.'},
		{title: 'Silver Dollar Tavern', address: '117 West Mifflin St., Madison, WI', tele: '608.255.7548', description: 'Good dive bar with shuffleboard and pool table. Just for drinkin’.'},
		{title: 'Gennas Lounge', address: '105 W. Main Street, Madison, WI', tele: '608.255.4770', description: 'Good bar right on the square. Good juke box. Just for drinkin’.'},
		{title: 'Willy Street Co-op', address: '1221 Williamson St, Madison, WI', tele: '608.251.6776', description: 'Local co-op for groceries or deli. Vegan, whole food, bulk, etc.'},
		{title: 'Bandung Restaurant', address: '600 Williamson St, Madison, WI', tele: '(608)255-6910', description: 'Planet\'s goto for Indonesian cuisine. Cozy atmosphere and a wide assortment of dishes with plenty of vegetarian options, if you\'re into that. Otherwise, get the Krakatau Chicken. Lunch, dinner, drinks.'}
	]
	$('#map-canvas').tjsmap('clear');
	function customCallback(geocode, status) {
		var currelement = haunts.pop();
		if (status == "OK" && geocode.length > 0) {
			// Place a marker at our geocoded location			
			$('#map-canvas').tjsmap('icon', {icon: 'default'}).tjsmap('marker', {latlng: geocode[0].geometry.location}).tjsmap('overlay', {content: '<h3 class="dark">' + currelement.title + '</h3><br /><p class="dark left">' + currelement.address + '<br />' + currelement.tele + '<br /><br />' + currelement.description + '</p>'})
 		}
		
		if(haunts.length >= 1) {
			
			var element = haunts[haunts.length-1];
			setTimeout(function(){$('#map-canvas').tjsmap('geocode', {address: element.address, callback: customCallback})}, 500);
		}
	}
	
	$("body").bind("dispatch-richoverlay-close", function(event){
		// alert(event.field_id); // Thats how to access event vars
		if(haunts.length >= 1) {
			var element = haunts[haunts.length-1];
			$('#map-canvas').tjsmap('geocode', {address: element.address, callback: customCallback});
		}
		return false;
	})
}

function complete_contact(){
    
		$('#map-canvas').tjsmap({lat: 43.092782,lng: -89.37674,mapTypeControl:false, autoPan:false, scrollwheel: false, streetViewControl: false, scaleControl:true, rotateControl: false, panControl: false, zoomControl: true, zoom: 14, zoomControlOptions: {position: google.maps.ControlPosition.LEFT_CENTER}}).tjsmap('icon', {icon: new google.maps.MarkerImage("/images/layout/icon-map-sprite.png", new google.maps.Size(20, 34), null, new google.maps.Point(11, 30) ), shadow: new google.maps.MarkerImage("/images/layout/icon-map-sprite.png", new google.maps.Size(35, 34), new google.maps.Point(20, 0), new google.maps.Point(11, 30) ) }).tjsmap('marker', {lat:43.0762258, lng:-89.37477720000004, zIndex:9999999});
		// MarkerImage(url:string, size?:Size, origin?:Point, anchor?:Point, scaledSize?:Size)
		setTimeout('delay_overlay()', 500);
	
}

function delay_overlay() {
	$('#map-canvas').tjsmap('overlay', {rich_overlay: true, 
										open_onload: true, 
										content_selector: '#copyme', 
										id: 'contact-planet', 
										width: 820, 
										height: 495 });
}

//  MAILING LIST - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function complete_mailinglist(){ bool_contain_layout = false; }


// SCROLLABLE SLIDESHOW - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initialize_slideshow(){	
	int_slide_current = 0;
	int_slide_rowmax = 4;

	$('#' + str_index_id_standby + ' #slideshow .scrollable').scrollable({circular: false, keyboard: false});
	$('#' + str_index_id_standby + ' #slidenav .scrollable').scrollable({circular: false, keyboard: false});

	api_slideshow = $('#' + str_index_id_standby + ' #slideshow .scrollable').scrollable({circular:false, speed:int_beat });
	api_slideshow_navigation = $('#' + str_index_id_standby + ' #slidenav .scrollable').scrollable({circular:false, speed:int_beat });
	
	api_slideshow.onBeforeSeek(function(event, int_index_target){ navigationSeek(int_index_target); });
	if (api_slideshow.getSize() == 1){ $('#' + str_index_id_standby + ' #slidenav').hide(); }
	else if (api_slideshow.getSize() <= 5) { $('#slidenav .browse').hide(); $('#slidenav .scrollable').width(600); int_slide_rowmax = 5; }

	$('#' + str_index_id_standby + ' #slidenav .itemlist .item a').click(function() {
		var int_index_next = ($(this).parent().index() * int_slide_rowmax) + $(this).index();
		slideshowSeek(int_index_next);
		return false;
	});

	api_slideshow.seekTo(0, 0);

	// Spacing/height determination
	if ($('#' + str_index_id_standby + ' #slideshow .item').length > 1){
		$('#' + str_index_id_standby + ' #slideshow').css('paddingTop', 20);
		$('#' + str_index_id_standby + ' #slideshow').css('paddingBottom', 20);
	} else if ($('#' + str_index_id_standby + ' #slideshow .caption').length == 1){
		$('#' + str_index_id_standby + ' #slideshow').css('paddingBottom', 10);
	}
	
	var int_max_captionheight = 0;
	$('#' + str_index_id_standby + ' #slideshow .caption').each(function(index) { if (int_max_captionheight < $(this).height()){ int_max_captionheight = $(this).height() + 10;}});
	$('#' + str_index_id_standby + ' #slideshow .caption').height(int_max_captionheight);

	var int_max_photoheight = 0;
	$('#' + str_index_id_standby + ' #slideshow .photo').each(function(index) { if (int_max_photoheight < $(this).height()){ int_max_photoheight = $(this).height(); }});
	$('#' + str_index_id_standby + ' #slideshow iframe').each(function(index) { if (int_max_photoheight < $(this).height()){ int_max_photoheight = $(this).height(); }});
	$('#' + str_index_id_standby + ' #slideshow .scrollable').height(int_max_photoheight + int_max_captionheight);
	$('#' + str_index_id_standby + ' #slideshow .browse').height($('#' + str_index_id_standby + ' #slideshow .scrollable').height());
	$('#' + str_index_id_standby + ' #slideshow .item').each(function(index) { 
		$(this).css('marginTop', (($('#' + str_index_id_standby + ' #slideshow .scrollable').height() / 2) - ($(this).height() / 2)));
		$(this).css('marginLeft', (($('#' + str_index_id_standby + ' #slideshow .scrollable').width() / 2) - ($(this).width() / 2)));
	});
	$('#' + str_index_id_standby + ' #slideshow .photo').each(function(index) { $(this).css('marginLeft', (($('#' + str_index_id_standby + ' #slideshow .item').width() / 2) - ($(this).width() / 2))); });
	$('#' + str_index_id_standby + ' #slideshow iframe').each(function(index) { $(this).css('marginLeft', (($('#' + str_index_id_standby + ' #slideshow .item').width() / 2) - ($(this).width() / 2))); });

	function slideshowSeek(int_index) {
		api_slideshow.seekTo(int_index, int_beat);
	}

	function navigationSeek(int_index) {
		if (int_index < api_slideshow.getSize()) {
			$('#slidecaption div').eq(int_slide_current).removeClass('here');	
		   	$('#slidecaption div').eq(int_index).addClass('here');

			$('#slidenav .itemlist .item a').eq(int_slide_current).removeClass('here');
			$('#slidenav .itemlist .item a').eq(int_index).addClass('here');

			var int_index_target = Math.floor(int_index / int_slide_rowmax);
			if (api_slideshow_navigation.getIndex() != int_index_target) { api_slideshow_navigation.seekTo(int_index_target); }

			int_slide_current = int_index;
		}
	}
}





// UTILITIES - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function show_clicklock_overlay(){
	$('#clicklock').show();
}

function hide_clicklock_overlay(){
	$('#clicklock').hide();
}

function show_loading_overlay(){
	//$('#loading .box').css('opacity', 0);
	$('#loading').css('opacity', 1);
	$('#loading').show();
	$('#loading .box').show();
	//$('#loading .box').css('opacity', 1);
	//setTimeout(function(){$('#loading .box').animate({opacity:1},{duration:int_beat, easing:'linear', queue:false});}, int_loading_delay);
}

function hide_loading_overlay(){
	//$('#loading').hide();
	$('#loading .box').hide();
	$('#loading').animate({opacity:0},{duration:int_beat, easing:'linear', queue:false, complete:function(){ $('#loading').hide(); } });
	//$('#loading .box').animate({opacity:0},{duration:250, easing:'linear', queue:false, complete:function(){ $('#loading').hide(); } });
	$('#topnav').height('55px');
}

function popupShare(str_url){
	window.open(str_url,'planetpropagandashare','width=525,height=400,left='+(screen.availWidth/2-225)+',top='+(screen.availHeight/2-150)+'');
}
