//===========================================
// Name: Change the World for Ten Bucks
// Description: 
// Version: 1.0
// Author: Jeremy Anderson [ Object Adjective ]
// Author URI: http://www.objectadjective.com
//===========================================

//Set ready state
$(document).ready(function(){

// Generated Markup and Styling

$('.actioncounter').append('<div class="bottom"></div>');
$('#main').after('<div class="main-bottom"></div>');
$('#submit').after('<div class="clear"></div>');
$('.liftout').append('<div class="bottom"></div>').prepend('<div class="top"></div>');
$('.feature:odd').addClass('feature-odd').after('<div class="clear"></div>');
$('.col:odd').css('float', 'right');
$('.badge:odd').css('margin', '20px 50px');
$('.avatar[src$=blank.gif], .avatar[src$=blank.gif&r=PG], img[src$=q_silhouette.gif]').attr('src', '/wp-content/themes/default/img/mystery-man.jpg');
$('.col img').before('<div class="clear"></div>');
$('.thecomment').append('<span class="stem"></span>');
if($.browser.msie) {
	$('.fbconnect_profiletexts').after('<div class="clear"></div');
	$('.icon-text-middle').parent().addClass('facebook-icon');
}

//Safari ICC Profile Work Around
if($.browser.safari) {
	$('html').css('background', '#369511 url(/wp-content/themes/default/img/body-bg.jpg) 0 0 repeat-x;');
	$('.innerwrap').css('background', 'transparent url(/wp-content/themes/default/img/rightcloud-safari.png) right 130px no-repeat');
}

//Deactive current state on Facebook pages
if($('#content').hasClass('fb-layout')){
	$('#nav').find('.current').removeClass('current');
}


//Checkbox form Elements
$('.checkbox label').click( function (){
	$(this).toggleClass('checked').next('input[type=checkbox]').click();
});

//Form Field focus
$("input, textarea, select").focus(function() {
	$(this).addClass("focus");
 });
$("input, textarea, select").blur(function() {
	$(this).removeClass("focus")
 });

//Clear Email Newsletter Field
$("#newsletter").focus(function() {
	if(this.value == "Your Email Address"){
		this.value = "";
		}
});
$("#newsletter").blur(function() {
	if(this.value == ""){
		this.value = "Your Email Address";
		}
});

$('#sendbutton2').click( function(){
	$('.mainform form, .mainform .intro').slideUp('slow');
	$('#tellafriend').slideDown('slow');
});

$('#sendbutton3').click( function(){
	$('#tellafriend, .thank-you').slideUp('slow');
	$('.share').slideDown('slow');
});


//Smooth fadin of Actions Count
$('.loader').animate({opacity: "1.00"}, 1000).animate({opacity: "1.00"}, 500).fadeOut('slow');
$('.thecount').animate({opacity: "1.00"}, 1300).animate({opacity: "1.00"}, 1300).fadeIn('slow');


//Lightbox Triggers
$('.fadein').click(function(event) {
	var el_show = $(this).attr("href");
	$(el_show).fadeIn('slow');
	event.preventDefault();
	lightbox();
	$('object').css('display', 'none');
});
$(".close").click(function(event){
	closeLightbox();
	event.preventDefault();
	$('object').css('display', 'block');
});

//Easy In-page Scrolling
	$(function(){
    $('.target').click(function() {
	var highlight = $(this).attr("href");
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
    && location.hostname == this.hostname) {
    var $target = $(this.hash);
    $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
    if ($target.length) {
    var targetOffset = $target.offset().top;
    $('html,body').animate({scrollTop: targetOffset}, 1000);
    return false;
    }
    }
    });
    });

}); // End Ready State


// Lightbox

function lightbox() {
		getHeight();
		if($.browser.msie) {
		$(".lightbox").css("top", document.documentElement.scrollTop+100+'px');
		}
		if($.browser.opera) {
		$('.lightbox').css('top', document.body.scrollTop+100+'px');
		}
		else {
		$(".lightbox").css("top", window.pageYOffset+100+'px');
		}
}

function closeLightbox(){
	$(".lightbox").fadeOut('slow');
	$("#overlay").hide();
	return false;
}


// Dim Layer for POPUP DIVS

function getHeight(){
	$('#overlay').fadeIn('slow');
	if (parseInt(navigator.appVersion)>3) {
 		if($.browser.msie) {
  		wind = document.body.offsetWidth;
  		wind = document.body.offsetHeight +250;
 		}
		else {
  		wind = window.innerWidth;
  		wind = window.innerHeight;
 		}
	}
	var divh = document.getElementsByTagName('body')[0].offsetHeight;
	var lock = document.getElementById('overlay');
	if (divh >= wind){
	lock.style.height = divh +"px";
	}
	else {lock.style.height =wind +"px";}
}

