/* actions.js starts */
//    @Author:    Jannis Gundermann
//    @Job:       Ogilvy: Doggie Wonderland
//    @Date:      26/04/2010
//    @By:      Supply Ltd.
//    @Web:       http://www.supply.net.nz/
// 
var dm;
$(document).ready(function() {
  
  var $site = 'http://www.beneful.co.nz/doggiewonderland/'; //'http://localhost/~jannis/3781_doggie_wonderland/www/preview/';

// ===========
// = CLASSES =
// ===========
  // Initial hasJS class to the body.
  $('body').addClass('hasjs');
  // first & last
  $('li,h3, #footer a,tr,.col,.rating_widget label,.trip_list .item').firstnlast();
  // End of row (grid)
  $.fn.endofrow = function (count) {
    return this.each(function() {

      var $count = count;

      $(this).find('.grid li:nth-child('+$count+'n)').addClass('end-of-row');
      
    });
  };
  // $('.results').endofrow(4);
  // $('.albums').endofrow(3);
  // input type as class
  $('input').each(function(index) {
    $(this).addClass($(this).attr('type'));
  });
	
	if ($('form#update_profile #newsletter').length) {
		$('form#update_profile #newsletter').next('label[for="newsletter"]').addClass('profile_newsletter');
	}
  // left/right
  // $('form#signup div:not(".wide")').filter(':odd').addClass('right').end().filter(':even').addClass('left');
  
  // Textarea .expand
  // $('textarea').addClass('expand');
  // active states
  $('#tabs li.active a').addClass('active');
  
	// ========
	// = HACK =
	// ========
	// if ( $('div.bar').length ) {
	// 	$('div.bar').each(function(i) {
	// 
	// 		if ($('div.bar > .section_title').length) {
	// 			$(this).css('height', 'auto'); // makes sure the content can regain height
	// 			$(this).css('height', $(this).height()); // then measure content of container and set as static height
	// 		};
	// 	
	// 	});
	// }
	// if ($('form button[type="submit"]').length = 0) { // if form has no submit button
	// 	$('form').find('button').last().attr('type', 'submit'); // make last button a submit button
	// };


  // =================
// = REVIEW VALIDATION =
// =================
	function setupReviewValidation(){
	
		var form = $('form#add_review');
		var form_mode = $('#form_type').val();
		var but = form.find('button[type="submit"]');
                if(form_mode != 'edit') {
                    but.fadeTo(0,0.5, function(){
                            $(this).addClass('disabled');
                    });
                }
		
		form.find(':radio').click(function(){
			but.fadeTo('fast',1).removeClass('disabled');
		});
	
		form.submit(function(e){
			if(but.hasClass('disabled') || form.find('textarea').attr('value')==''){
				e.preventDefault();
			}
			
		});

	}
	
	setupReviewValidation();

  
// =================
// = INTERACTIVITY =
// =================

	function hoverTooltip() {
		$("body").append("<div class='tooltip'></div>");
		var caption = $('.tooltip');
			$('.secondary li').mouseenter( function(){ 

				$(caption).css('display','block').html($(this).text());
				$(caption).css('top' , $(this).offset().top - 18);
				$(caption).css('left' , $(this).offset().left + 3);

			});

			$('ul.secondary').mouseleave( function(){
				$(caption).css('display','none');
			})
			
			
		$("body").append("<div class='category_tooltip'></div>");
  	
  		var cat_tool = $('.category_tooltip');
			$('.checkbox_group .cat').mouseenter( function(){ 
				
				var label = $(this).children()[1];
				
				$(cat_tool).css('display','block').html($(label).attr('value'));
				if($('#place_data .checkbox_group').length )
				{	
					$(cat_tool).css('top' , $(this).offset().top + 42);
				}else
				{
					$(cat_tool).css('top' , $(this).offset().top + 25);
				}
				
				$(cat_tool).css('left' , $(this).offset().left -5);
				
			});
			$('.checkbox_group').mouseleave( function(){
				$(cat_tool).css('display','none');
			})
	};
	hoverTooltip();

	function checkboxes() {
		
		// when reloading and checkboxes remain checked from previous site, then this reapplies the blue logo
		if ( $('.checkbox_group :checkbox:checked').length ) {
			$('.checkbox_group :checkbox:checked').each(function(index) {
				$(this).prev('label').toggleClass('active');
			});
		};
		
		// on click of label/checkbox activates label to show green icon
		$('.checkbox_group label,.checkbox_group input').each(function(i) {
			$(this).click(function() {
				if (this.nodeName.toLowerCase() == 'input') {
					$(this).prev('label').toggleClass('active');
				};
			});
		});

	}; // close function
	
	if ( $('.checkbox_group').length ) {
		checkboxes(); // run
	}

  	// Profile Image Uploader slide up / down animation
	function profileUploader() {

	  $('.overlay').hide(); // hide the section on page load

	  var $overlay = $('div.profile_image').find('.overlay');
  
	  // hide & show
	  $('div.profile_image').hover(function() {
	    $overlay.fadeIn('fast');
	  }, function() {
	    $overlay.stop(true,true).delay(200).fadeOut('slow');
	  });
  
	    // submit form on change
	    // $('#profile_image').change(function(e){
	    //   $(this).closest('form').submit();
	    // });

	  // on click move to save button.
	$('#profile_image').change(function(e) {
	  $overlay.find('label,#profile_image').css('position','absolute').animate({
	      'left':'-200px'
	    }, 300, function() { // callback
	      $overlay.find('._submit').fadeIn('fast',function() {
			$(this).closest('form').submit();
		});
      });
	});

	};
	profileUploader();
  
  // ======================
  // = STAR RATING WIDGET =
  // ======================

  function ratings() {
    
    var $container = $('.rating_widget'),
      $labels = $container.find('label');
    
      $container.hover(function() { // in
        
        $labels.hover(function() {

            $(this).prevAll().andSelf().addClass('active');
            $(this).nextAll().removeClass('active');

            // var $name = $(this).attr('for'),
            //   $inputMatch = $(this).closest('div').find('#'+$name+'');
            // 
            // $inputMatch.attr('checked', 'checked')
            
          }, function() {
            // out on label
        }); // close label hover event

      }, function() { // out on container

        if ( $(this).find('input:checked').length ) { // if something has been checked/label clicked
          // do nothing
        } else {
          // remove active states
          $labels.removeClass('active');
        }
    });
  };
  ratings(); // run
    
// =====================
// = DOM MANIPULATIONS =
// =====================

	// height check for the #secondary
	function sectionHeights() {
	  if ( $('section#secondary').length ) {
	    var $hS = $('section#secondary').outerHeight(),
	    	$hP = $('section#primary').outerHeight()-40,
			$absolute = false,
			$hasRun = false;

		// console.log('primary height: '+$('section#primary').outerHeight());
		// console.log('secondary height: '+$('section#secondary').outerHeight());
		// alert('primary height: '+$('section#primary').outerHeight()+', secondary height: '+$('section#secondary').outerHeight());	
		

	    if ( $hS >= $hP ) {   
	      	$('section#primary').css({'height':$hS+100});
			$hasRun = true;

			if ($absolute === false) {
				$('section#primary').find('footer').css({'position':'absolute'});
				$absolute = true;
			}
	    }
	  }
		// if profile data is shown then set container to overflow: hidden
		if ( $('.profile_data').length ) {
			$('.profile_data').closest('article').css('overflow', 'hidden');
		}
	};
	sectionHeights();
  
	


	// ===========================
	// = UPLOAD FIELD DUPLICATOR =
	// ===========================
	if ( $('form.upload').length ) { // make sure this only runs if the upload form is present
		
		function uploadDupe() {
		
			var	$wrap  = $('div.upload_wrapper'),
			 	$field = $('input', $wrap),
				$addBtn = $('#add_another'),
				$field_data = $field.attr('id').split('_'), // create an array of properties consisting of the string & number (counter)
				i = 0; // counter
			
				// console.log($field_data);
		
			$addBtn.click(function() {

				$field.each(function(index) {
					i++; // increase counter on click
					
					// console.log(i);
					// console.log($(this));
					
					$(this).clone() // duplicate
						.attr({
							value : '', // make sure the value/src of image from the previous field is reset
							name : $field_data[0]+'_'+i, // create unique name attribute
							id :   $field_data[0]+'_'+i  // create unique id attribute
	 					})
						.appendTo($wrap); // add to the container
						
				});

					$('#upload_number').attr('value', 1+i); // increase total field counter, required for PHP's upload action
					sectionHeights(); // measure heights of containers and adjust if necessary
					$(this).blur(); // deactivate the :active state of the <a>
			});
		
		};
		uploadDupe(); // run
	};

  // SHARE POPUP
  function shareButton() {
  // $('.share_popup').hide();
  
  var $button = $('.small_button_share'),
    $popup  = $button.parent().find('.share_popup');

	function position() {
		var $btnTop = parseInt($button.position().top),
			$btnLeft = parseInt($button.position().left);
			
			$('.share_popup').css({
				'position':'absolute',
				'top':$btnTop+33,
				'left':$btnLeft-60
			});
	};
  
    $button.hover(function() {
      $popup.addClass('hover');
		position();
    }, function() {
      $popup.removeClass('hover');
    });
    $popup.hover(function() {
      $button.addClass('hover');
    }, function() {
      $button.removeClass('hover');     
    });
    
  };
  shareButton();
  
	function requiredFields() {
	
	  // add * to required fields label
	  $('form .required').each(function(index) {
		// console.log(this.nodeName);
		if (this.nodeName.toLowerCase() == 'input') { // activate on input fields
		    $(this).prev('label').append('<span>*</span>');
		} else { // activate on labels (T&Cs)
			$(this).append('<span>*</span>');
		}
	  });

	};
	if ($('form').length) {
		requiredFields(); // run if form present on page
	}
	
	// ===================================
	// = FORM VALIDATION ON THE UPLOADER =
	// ===================================
		function validater(form) {
			
			var $form = $(form),
				$saveBtn = $form.find('button[type="submit"]'),
				$optin = $('input:checkbox'),
				$w = $optin.parent('div').width()-15; // get width -15 to account for padding animation


			if ( $form.selector == 'form#signup' ) {
				$optin = $('input:checkbox:not("#newsletter")');
			}

			// var $form = $('form.upload'),
			// 	$saveBtn = $form.find('button[type="submit"]'),
			// 	$optin = $('input:checkbox');
				
			if (! $form.find('input:checkbox:checked').length ) { // if unchecked on load then disable the button
				// disable the button
				$saveBtn.fadeTo(0, 0.5, function() {
					$(this).addClass('disabled');
				});
			};
			
			// create a stable div for the highlighters position:absolute
			$optin.parent('div').css('position', 'relative').contents().css({'zIndex':'5','position':'relative'});
			
			$optin.click(function(e) {
				if ($('input:checkbox:checked').length) {
					// if ticked
					$saveBtn.removeClass('disabled').fadeTo('fast', 1);
					
				} else {
					// if not ticked
					if ($saveBtn.hasClass('disabled')) {
						// nothing
					} else {
						$saveBtn.fadeTo('fast', 0.5).addClass('disabled');
					};
				};
			});
			// click on save
			$saveBtn.click(function(e) {
				if ( $(this).hasClass('disabled') ) { // only if not checkbox not checked
					
					e.preventDefault(); // stop click
					
					// $('<div/>', { // create highlighter
					// 	'class':'red',
					// 	css: {
					// 		'height': $optin.closest('div').height()+10,
					// 		'width': $optin.closest('div').width()+10,
					// 		'position':'absolute',
					// 		'top':'-5px',
					// 		'left':'-5px',
					// 		'bottom':'-5px',
					// 		'right':'-5px',
					// 		'z-index':'1'
					// 	}
					// }).appendTo($optin.parent('div')) // put it into the container that holds the checkbox
					// 	.animate({'backgroundColor': 'white'}, 200, function() { // fade it in
					// 	  	$(this).fadeOut(200, function() { // when there fade out immediately
					// 		  	$(this).remove(); // then remove entirely, this stops a repeated click from stacking elements
					// 	  	});
					// 	});

					$optin.parent('div').animate({'padding':'5px','backgroundColor':'white','border':'1px solid red','width':$w},200);
					$optin.parent('div').find('label,a').animate({'color':'red'},200,function() {
						$saveBtn.blur(); // remove focus from button
						$optin.focus(); // goto optin field
					});
				} // end if
			});
			
		};

		if ( $('form.upload').length ) {
			validater('form.upload');
		}
		if ( $('form#signup').length ) {
			validater('form#signup');
		}
	
  // =============================
  // = Close button (slide away) =
  // =============================
  function closeButton () {
    $('a.slide_button').click(function() {
		$('section#primary article a.active').removeClass('active');
        $(this).closest('section#secondary').animate({'width':'0'}, 3000, function() {
	            $(this).remove();
	          });
        });
  };
  closeButton();
  // $('a.slide_button').click(function() {
  //  $(this).closest('section#secondary').children('*').fadeOut('slow', function() {
  //    $('section#secondary').animate({'width':'0'}, 3000);
  //  });
  // });
  
function ajaxLoader() {

	// console.log('ajaxloader');
	var $modal = '#modal_window',
		$holder = '#popup';
	

	function position() {
		// $($holder).css('display', 'block');
		// $($holder).css('display', 'none');

	    var $h = $($holder).outerHeight(),
	     	$w = $($holder).outerWidth();

		if ($($modal).hasClass('warning') || $($modal).hasClass('message')) {
			// console.log('warning or message');
			// $h = '300';
			// $w = '200';
			$($holder).css({
					top: '50%',
					marginTop: -($h/2),
					left: '50%',
					marginLeft: -($w/2)
	       	});
			
		} else if ($($modal).hasClass('reporter') && $('body:not(".logged_in")').length == 1) {
			$h = '10px';
			$w = '260px';
			$($holder).css({
					top: '50%',
					marginTop: -(parseInt($h)/2)-20,
					left: '50%',
					marginLeft: -(parseInt($w)/2)-20,
					width: $w,
					height: $h,
					overflow: 'hidden'
	       	});
			
		} else if ($($modal).hasClass('reporter') && $('body').hasClass('logged_in')) {
			$h = '160px',
			$w = '450px';
			$($holder).css({
					top: '50%',
					marginTop: -(parseInt($h)/2)-20,
					left: '50%',
					marginLeft: -(parseInt($w)/2)-20,
					width: $w,
					height: $h,
					overflow: 'hidden'
	       	});

		} else {
			 
			$h = '80%';
			$w = '800';
			$($holder).css({
					top: '6%',
					// marginTop: -($h/2),
					left: '50%',
					marginLeft: -($w/2)
	       	});
	        
		};
		// console.log('got height');
		// console.log($h);
		// console.log($w);
		
		// position
		// console.log('positioned');
   	}; // position



	$('a.popup,a._report').click(function(e) {
		var $link = $(this);

		// console.log('popping up');
		// console.log('clicked');

	    e.preventDefault(); // stop submit (debug only)
	    var $href = $(this).attr('href'); // get currently clicked a's link
	    var $post = $(this).attr('href'); // get currently clicked a's link
	
		if ($(this).hasClass('_report')) { // if logged out show the please login message
			var $href = 'footer/please_login.php';
		};
		if ($(this).hasClass('_report') && $('body').hasClass('logged_in')) { // if logged in show report window
			var $href = 'footer/report.php';
		};
		// console.log($site+$href);

	    if ( $($modal).length ) { // check if there is already a modal window in the dom.
	      // if yes, do nothing
	    } else {
	      // do the popup

				$('<div/>',{
					'id':'modal_window'
				}).prependTo('body').hide(0, function() {
					$('<div/>',{
						'id':'popup'
					}).appendTo($(this)); // create popup shell
					// console.log('popup created');
					
					// console.log($(this));
					// console.log($link);
					if ($link.hasClass('_report')) {
						// console.log('applied');
						$($modal).addClass('reporter');
					};
					
					
				}); // create shell, hidden

				
	      		$($holder).load($site+$href, function() {
					position();
					$($modal).fadeIn('slow',function() {
						if ($link.hasClass('_report')) {
							$('#report').attr('action', $post);							
							insideClick(); // make sure that internal links do not cause page refresh.
							closeLink(); // recheck for close buttons in new content
							$('._submit').click(function(e) {
								$('form#report').submit();
							});
						}
						if ($('button._close').length) {
							
							var $bl = $('#popup').width()/2+20,
								$bt = $('#popup').position().top-10;

							// $('#popup').css('overflow', 'auto');
							$('button._close').prependTo('body').css({
								'top':$bt,
								'left':'50%',
								'marginLeft':$bl
							});
							
							$('button._close').click(function() {
								$('#modal_window,button._close').fadeOut('fast', function() {
									$(this).remove();
								});
								
							});
							
						};
					});
					// $($holder).fadeIn('slow');
				}); // ajax load the href of the link into the article of the popup

				function insideClick() {
					$($modal).find('._link').click(function(event) {
						event.preventDefault();

						var $href = $(this).attr('href');
						
						$('<div/>',{
							id: 'overlay',
							css: {
								top: '0',
								left: '0',
								width: '100%',
								height: '100%',
								overflow: 'hidden',
								zIndex: '50000',
								'position': 'absolute'
							}
						}).prependTo('body').append('<div id="popup_2" />').find('#popup_2').load($site+$href,
						 function(){
						
						   $('#popup_2').css({
								width: '800px',
								height: '80%',
								left: '50%',
								top: '6%',
								marginLeft: '-400px',
								position: 'absolute',
								padding: '20px',
								background: '#fff',
								zIndex: '60000',
								overflow: 'auto'
							}).fadeIn('slow', function() {
								$(this).find('._close').click(function(e) {
									e.preventDefault();
									$(this).closest('#overlay').fadeOut('fast',function() {$(this).remove();});
								});
								$('body').find('#overlay').click(function(e) {
									e.preventDefault();
									$('#overlay').fadeOut('fast',function() {$(this).remove();});
								});
							}); 
						});
						
						
					});
				};


			      // stop a click into the article from closing the popup
			      $('#modal_window #popup').click(function(e) {
				        // enable click of buttons
				        if (e.target.type != 'submit') {
				          e.stopImmediatePropagation(); // stop clicks inside the article from closing the popup.
				        }
			      });

				function closeLink() {
			      // trigger closing animation when clicking close button or outside of popup area.
			      $('#modal_window #popup button[type!="submit"],#modal_window #popup a._close, #modal_window').click(function(e) {
				        // Close PopUp
				        $('#modal_window,._close').fadeOut('fast', function() {
					          $(this).remove(); // remove element from dom.
				        });
			      });
				};
				closeLink();
	    };// close if:else statement

	}); // close click on .popup
	
	// the animation
    if ($($modal).length) {
      // console.log('modal detected');
      // if only a message then fade in & out after 1 sec
      if ($($modal).hasClass('message')) {
		// console.log('message');
        $($modal)
          .fadeIn('fast',function() {
            position();
          })
          .delay(2000)
          .fadeOut(400, function() {
            $(this).remove();
          }); // end fadeOut
      } // close .message specifics
      
      // if warning then leave open until user clicks screen.
      if ($($modal).hasClass('warning')) {
		// console.log('warning');
        $($modal)
          .fadeIn('fast',function() {
            position();
          });
        $($holder).css({'border':'6px solid red','color':'red'});
        $($modal).click(function() {
          $(this).fadeOut(400, function() {
            $(this).remove();
          }); // close fadeOut
        }); //end click
      } // close if .warning

	
      // stop a click into the article from closing the popup
      $($holder).click(function(e) {
	        // enable click of buttons
	        if (e.target.type != 'submit') {
	          e.stopImmediatePropagation(); // stop clicks inside the article from closing the popup.
	        }
      }); // close click

      // trigger closing animation when clicking close button or outside of popup area.
      $('#modal_window, #popup button[type!="submit"]').click(function(e) {
	        // Close PopUp
	        $($modal).fadeOut('fast', function() {
		          $(this).remove(); // remove element from dom.
	        }); //  close fadeOut
      }); // end click

    } // end if $($modal) present check
	
};// closing ajaxLoader
ajaxLoader();
  
  // =========
  // = FORMS =
  // =========
  
	if ($('form#new_place').length) {

	  function fieldsetReveal() {
  
	  var $form = $('form#new_place'),
	    $fieldset = $form.find('fieldset#place_data:not(".open")'),
		$send = $('button[type="submit"]'),
	    $confirm = $('._confirm'),
		$mapit = $('#find_location'),
		$address = $('fieldset#address_data input'),
		$mapped = false,
		$ok = false;
		
		function validate() {
			$address.each(function(index) {
				// console.log($('#address_data input[value!=""]').length);
				if ( $('#address_data input[value!=""]').length >= 2 ) {
					$ok = true;
				} else {
					$ok = false;
				};
			});
		};
		
	    $fieldset.hide(); // hide on load
	
		// Checkbox check
		if ( $('.checkbox_group :checkbox:checked').length ) {
			$send.fadeTo('fast', 1);
		};
		
		$('.checkbox_group label,.checkbox_group input').click(function(e) {

			// console.log($(':checkbox:checked').length);

			// Checkbox check
			if ( $('.checkbox_group :checkbox:checked').length > 0 ) {
				$send.fadeTo('fast', 1);
			} else {
				$send.fadeTo('fast', 0.5);
			};
		});

		$form.submit(function(e) {
			// console.log($step2);
			// console.log($fieldset.length);
			if ($('fieldset#place_data.open').length == 1 && $('.checkbox_group :checkbox:checked').length ) {
				// fire form
			} else {
				e.preventDefault();
			};
		});
		
		// check confirm button state on load
		( $fieldset.length == 0 ? $confirm.fadeTo(0, 1) : $confirm.fadeTo(0, 0.5) )

		// 'disable' on  mapit button load
		validate();
		if ($ok === true) {
			$mapped = true; 
			$ok = false;
		};
		( $mapped === true ? $mapit.fadeTo(0, 1) : $mapit.fadeTo(0, 0.5) )
		
		// check if mapit should be enabled
		$address.live('keyup change click blur', function(e) { 
			validate();
			if ($ok === true) {
				$mapped = true; 
				$ok = false;
			}else{
				$mapped = false;
				$ok = false;
			}
			( $mapped === true ? $mapit.fadeTo(0, 1) : $mapit.fadeTo(0, 0.5) );
			// console.log($mapped);
			
		});
	    
		$mapit.click(function(e) {
			validate();
			( $ok === true ? $confirm.fadeTo('fast', 1, function() {$ok = false}) : e.preventDefault() );
		});


		$confirm.click(function(e) {
				
			validate();
			// console.log($ok);
			if ($ok === false) {
		      	e.preventDefault(); // stop submit
				// console.log('stopped');
			} else if ( $ok === true ) {
				$fieldset.fadeIn(400).addClass('open').find('button[type="submit"]').fadeTo(0, 0.5);
				// $step2 = true;
				// console.log('submitted');
				// console.log($step2);
			};
		// console.log('number of filled out fields:'+$('#address_data input[value!=""]').length);
		// console.log('total number of fields:'+$address.length);
	    });
	
    
	  };
	
	  fieldsetReveal(); // run
	};

	if ( $('.item a.overlay').length ) {
		function overlay () {
			var $overlay = $('.item a.overlay'),
				$wrap = $overlay.parent('.wrap');
			
			$wrap.hover(function() {
				// $(this).find('.overlay').slideDown(200); //show
				$(this).find('.overlay').fadeIn(200); //show
			}, function() {
				// $(this).find('.overlay').stop(true,true).slideUp(350); //hide
				$(this).find('.overlay').stop(true,true).fadeOut(350); //hide
			});
				
		};
		overlay();
	};
// ==============
// = GOOGLE MAP =
// ==============
  
	if ( $('#gmap').length ) {
	  // DoggieMaps obj available to page
	  var can = document.getElementById('gmap');
	  dm = new DoggieMaps();
	  dm.init(can);
	};      
  
  // ====================
  // = GOOGLE MAP HOOKS =
  // ====================

  // ****************************************************************************************************
  // Timeout needs to be fixed, the following does not fire because the gmap is not loaded when they run.
  // ****************************************************************************************************
  
  // control slider
	function gmapReady() { // called externally
	  $('#gmap').find('div[controlwidth]').first().addClass('gmap_controls');
	  $('#gmap').find('a[title="Click to see this area on Google Maps"]').closest('div').addClass('gmap-logo');
	  $('#gmap').find('span:contains("MapData Sciences Pty Ltd")').closest('div').parent('div').addClass('gmap-copyright'); 
	};
// ===========
// = PLUGINS =
// ===========
  // Textarea expander
  $('textarea.expand').TextAreaExpander();
  // EqualHeights
  $('.albums .item,.col .top,.my_friends .item').equalHeights();
  
}); // close .ready

$(window).load(function() {
	// Let's Go!
	// height check for the #secondary
	function sectionHeights() {
	  if ( $('section#secondary').length ) {
	    var $hS = $('section#secondary').outerHeight(),
	    	$hP = $('section#primary').outerHeight()-40,
			$absolute = false,
			$hasRun = false;

		// console.log('primary height: '+$('section#primary').outerHeight());
		// console.log('secondary height: '+$('section#secondary').outerHeight());
		// alert('primary height: '+$('section#primary').outerHeight()+', secondary height: '+$('section#secondary').outerHeight());	
		

	    if ( $hS >= $hP ) {   
	      	$('section#primary').css({'height':$hS+100});
			$hasRun = true;

			if ($absolute === false) {
				$('section#primary').find('footer').css({'position':'absolute'});
				$absolute = true;
			}
	    }
	  }
		// if profile data is shown then set container to overflow: hidden
		if ( $('.profile_data').length ) {
			$('.profile_data').closest('article').css('overflow', 'hidden');
		}
	};
	sectionHeights();
	
});

// end of file

