/* ========== FAQ Function ========== */
function toggleAnswer(nodeID)
{
	var answer = document.getElementById('sp' + nodeID);
	if(answer)
	{
		if(answer.className == "answer")
		{
			answer.className = "answerOpen";
		}
		else
		{
			answer.className = "answer";
		}
	}
	var li = document.getElementById('li' + nodeID)
	if(li)
	{
		if(li.className == "current")
		{
			li.className = "";
		}
		else
		{
			li.className = "current";
		}
	}

}
/* ========== END FAQ FUNCTION ========== */


/* ======== START INPUT DEFAULT TEXT ========= */
function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}
function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
}
}
/* ======== END INPUT DEFAULT TEXT ========= */



/* =========== START TWEETABLE ============ */

/*
 * tweetable 1.4 - jQuery twitter feed generator plugin
 *
 * Copyright (c) 2009 Philip Beel (http://www.theodin.co.uk/)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * With modifications from Philipp Robbel (http://www.robbel.com/) and Patrick DW (stackoverflow)
 * for IE compatibility.
 *
 * With modifications from The Lavidge Company (http://www.lavidge.com/) for date formating.
 *
 * Revision: $Id: jquery.tweetable.js 2010-12-15 $ 
 *
 */
(function ($) {
    $.fn.tweetable = function (options) {
        var defaults = {
            limit: 1,
            username: 'lavidgeco',
            time: true,
            replies: true,
            position: 'append'
        };
        var options = $.extend(defaults, options);
        return this.each(function (options) {
            var act = $(this);
            var $tweetList;
            var api = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=";
            var count = "&count=";
            $.getJSON(api + defaults.username + count + defaults.limit + "&callback=?", act, function (data) {
                $.each(data, function (i, item) {
                    if (i == 0) {
                        $tweetList = $('<ul class="tweetList">')[defaults.position.toLowerCase() + 'To'](act);
                    }
                    if (defaults.replies === false) {
                        if (item.in_reply_to_status_id === null) {
                            $tweetList.append('<li class="tweet_content_' + i + '"><span class="tweet_link_' + i + '">' + item.text.replace(/#(.*?)(\s|$)/g, '<span class="hash">#$1 </span>').replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, '<a href="$&">$&</a> ').replace(/@(.*?)(\s|\(|\)|$)/g, '<a href="http://twitter.com/$1">@$1 </a>$2') + '</span></li>');
                        }
                    } else {
                        $tweetList.append('<li class="tweet_content_'+i+'"><span class="tweet_link_'+i+'">' + item.text.replace(/#(.*?)(\s|$)/g, '<span class="hash">#$1 </span>').replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, '<a href="$&">$&</a> ').replace(/@(.*?)(\s|\(|\)|$)/g, '<a href="http://twitter.com/$1">@$1 </a>$2') + '</span></li>');
                    }
                    if (defaults.time == true) {

						var tweetDate = item.created_at.substr(4, 40);
						var tweetDateMon = item.created_at.substr(4, 3);
						var tweetDateDay = item.created_at.substr(8, 2);
						var tweetDateYr = item.created_at.substr(26, 4);
						var tweetTimeHour = item.created_at.substr(11, 2);
						var tweetTimeMin = item.created_at.substr(14, 2);
						var ampm = tweetTimeHour<12 ? ' a.m.' : ' p.m.';
						//Month Settings
						if (tweetDateMon == 'Jan') tweetDateMon='January';
						if (tweetDateMon == 'Feb') tweetDateMon='February';
						if (tweetDateMon == 'Mar') tweetDateMon='March';
						if (tweetDateMon == 'Apr') tweetDateMon='April';
						if (tweetDateMon == 'Jun') tweetDateMon='June';
						if (tweetDateMon == 'Jul') tweetDateMon='July';
						if (tweetDateMon == 'Aug') tweetDateMon='August';
						if (tweetDateMon == 'Sep') tweetDateMon='September';
						if (tweetDateMon == 'Oct') tweetDateMon='October';
						if (tweetDateMon == 'Nov') tweetDateMon='November';
						if (tweetDateMon == 'Dec') tweetDateMon='December';
						// Time-Zone Conversion
						if (tweetTimeHour>7)  tweetTimeHour-= 7;
						if (tweetTimeHour==0) tweetTimeHour = 17;
						if (tweetTimeHour==1) tweetTimeHour = 18;
						if (tweetTimeHour==2) tweetTimeHour = 19;
						if (tweetTimeHour==3) tweetTimeHour = 20;
						if (tweetTimeHour==4) tweetTimeHour = 21;
						if (tweetTimeHour==5) tweetTimeHour = 22;
						if (tweetTimeHour==6) tweetTimeHour = 23;
						// 12-Hour Conversion						
						if (tweetTimeHour>12) tweetTimeHour-= 12;
						if (tweetTimeHour==0) tweetTimeHour = 12;
						

                        $('.tweet_content_' + i).prepend('<span class="timestamp"><span class="time">'+tweetTimeHour+':'+tweetTimeMin+ampm+'</span><span class="date">'+tweetDateMon+' '+tweetDateDay+', '+tweetDateYr+'</span></span>').append('<span class="timestamp_sm"><span class="time_sm">'+tweetTimeHour+':'+tweetTimeMin+ampm.substr(0, 2)+ampm.substr(3, 1)+'</span> <span class="date_sm">'+tweetDateMon.substr(0, 3)+' '+tweetDateDay+'</span></span>');
                    }

                });
            });
        });
    }
})(jQuery);
/* ============ END TWEETABLE ============= */





/* ============ RANDOM CLASS GENERATOR ============= */
function get_random()
{
    var ranNum= Math.floor(Math.random()*5);
    return ranNum;
}

$(document).ready(function getaQuote()
{
	
   var twitterDiv = document.getElementById('tweet_photo');
   var randomClassGen=get_random();

	if ($(twitterDiv).length != 0)
		{
			$(twitterDiv).attr("class", 'bg_'+randomClassGen)
		}
	else
		{
			null;
		}

  }
);
/* ============ END RANDOM CLASS GENERATOR ============= */





/* ============ GENERATE COMMENTS COUNT ============= */
$(document).ready(function get_comment_count()
{
	var getCommentsDiv = document.getElementById('comment_count');
	
	if ($(getCommentsDiv).length != 0)
		{
			$('#blog_post_comments').html(getCommentsDiv.innerHTML);
		}
	else
		{
			null;
		}

  }
);
/* ============ GENERATE COMMENTS COUNT ============= */



/* ======== START QUOTE ROTATOR ========= */
//Fading fuctionality
jQuery(document).ready(function(){
  showing = jQuery('#rotating_items div.rotating_item:first'); // Initiate the 'showing' variable as the first rotating_item
  showing.siblings('div').hide(); // Hide all other rotating_items
  setInterval("show_next_rotating_item(showing)", 5000); // Set the rotate time to 5 seconds
});
// Below is the code that picks an item at random to display
jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"],
{
  random: function(a, i, m, r) {
    if (i == 0) {
      jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
    };
    return i == jQuery.jQueryRandom;
  }
});
// The below function repeatedly gets called, to do the rotating
function show_next_rotating_item(t){
  jQuery(t).fadeOut('slow');
  var next_rotating_item = jQuery(t).siblings('.rotating_item:random');
  if(!next_rotating_item.attr('class')){
    next_rotating_item = jQuery('#rotating_items div.rotating_item:first');
  }
  next_rotating_item.fadeIn('slow');
  showing = next_rotating_item;
}


/* ======== END QUOTE ROTATOR ========= */




/* ======== START CONTACT FORM ========= */
jQuery(document).ready(function(){
   if( $('table.inquiryNature').length > 0 ){
		setBusinessFormFields();
		$("table.inquiryNature input").click(setBusinessFormFields);
   }
   else {
	   return false;
   }
});

function setBusinessFormFields () {
	
	   if ($('table.inquiryNature input[value="Business Development"]').attr('checked') == true) {
		  $('#business_label').show();
		  $('#service_type_label').show();
		  $('.service_type').show();
		  $('#normal_label').hide();
	   }
	   else if( $('table.inquiryNature input').filter(":checked").length == 0 ){
		  $('table.inquiryNature input[value="Business Development"]').attr('checked', true);
		  $('#normal_label').hide();
	   }
	   else {
		  $('#business_label').hide();
		  $('#service_type_label').hide();
		  $('.service_type').hide();
		  $('#normal_label').show();
	   }
	};
/* ======== END CONTACT FORM ========= */



/* =========== START BOOKMARK SCROLL TO ============ */

//** Scrolling HTML Bookmarks script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
//** Available/ usage terms at http://www.dynamicdrive.com/ (April 11th, 09')
//** Updated Nov 10th, 09'- Fixed anchor jumping issue in IE7

var bookmarkscroll={
	setting: {duration:1000, yoffset:0}, //{duration_of_scroll_milliseconds, offset_from_target_element_to_rest}
	topkeyword: '#top', //keyword used in your anchors and scrollTo() to cause script to scroll page to very top

	scrollTo:function(dest, options, hash){
		var $=jQuery, options=options || {}
		var $dest=(typeof dest=="string" && dest.length>0)? (dest==this.topkeyword? 0 : $('#'+dest)) : (dest)? $(dest) : [] //get element based on id, topkeyword, or dom ref
		if ($dest===0 || $dest.length==1 && (!options.autorun || options.autorun && Math.abs($dest.offset().top+(options.yoffset||this.setting.yoffset)-$(window).scrollTop())>5)){
			this.$body.animate({scrollTop: ($dest===0)? 0 : $dest.offset().top+(options.yoffset||this.setting.yoffset)}, (options.duration||this.setting.duration), function(){
				if ($dest!==0 && hash)
					location.hash=hash
			})
		}
	},

	urlparamselect:function(){
		var param=window.location.search.match(/scrollto=[\w\-_,]+/i) //search for scrollto=divid
		return (param)? param[0].split('=')[1] : null
	},
	
	init:function(){
		jQuery(document).ready(function($){
			var mainobj=bookmarkscroll
			mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
			var urlselectid=mainobj.urlparamselect() //get div of page.htm?scrollto=divid
			if (urlselectid) //if id defined
				setTimeout(function(){mainobj.scrollTo(document.getElementById(urlselectid) || $('a[name='+urlselectid+']:eq(0)').get(0), {autorun:true})}, 100)
			$('a[href^="#"]').each(function(){ //loop through links with "#" prefix
				var hashvalue=this.getAttribute('href').match(/#\w+$/i) //filter links at least 1 character following "#" prefix
				hashvalue=(hashvalue)? hashvalue[0].substring(1) : null //strip "#" from hashvalue
				if (this.hash.length>1){ //if hash value is more than just "#"
					var $bookmark=$('a[name='+this.hash.substr(1)+']:eq(0)')
					if ($bookmark.length==1 || this.hash==mainobj.topkeyword){ //if HTML anchor with given ID exists or href==topkeyword
						if ($bookmark.length==1 && !document.all) //non IE, or IE7+
							$bookmark.html('.').css({position:'absolute', fontSize:1, visibility:'hidden'})
						$(this).click(function(e){
							mainobj.scrollTo((this.hash==mainobj.topkeyword)? mainobj.topkeyword : $bookmark.get(0), {}, this.hash)
							e.preventDefault()
						})
					}
				}
			})
		})
	}
}

bookmarkscroll.init()

/* ======== END BOOKMARK SCROLL TO ========= */



/* ======== BEG RESIZE WINDOW ========= */
function resizeClass() {
	    
		var $html = $("html");
		var $body = $("body");
		var masterClass = $("#master");
		var windowWidth = $(window).width();
		var siteWidth = ($.browser.msie ? 1220 : 1230)
		
		$body.addClass("bodyClass");
		
		if(windowWidth >= siteWidth){
			masterClass.removeClass("w_under").removeClass("w_min").addClass("w_plus");
			resizeVideos('.reg_w', '.reg_h');
		}
		else if (windowWidth <= 950){
			masterClass.removeClass("w_plus").addClass("w_min").addClass("w_under");
			resizeVideos('.sm_w', '.sm_h');
		} else {
			masterClass.removeClass("w_plus").removeClass("w_min").addClass("w_under");
			$body.addClass("bodyClass");
			resizeVideos('.sm_w', '.sm_h');
		}        
		
		$(document).trigger("resizeClass");
	}
	
jQuery(document).ready(function(){
	resizeClass();
});

$(window).resize(function() {
	resizeClass();
});

/* ======== END RESIZE WINDOW ========= */


/* ======== BEG RESIZE VIDEO ========= */
//$(window).load(function() {


function resizeVideos (wclass, hclass) {

$('div.video-js-box').each(function(index){

//variables
var container = $(this);
var videotag = $('video', this);
var poster = $('.vjs-poster', this);
var flash = $('object', this);
var w = $(wclass, this).html();
var h = $(hclass, this).html();


//functions
resizeCss(container, w, h);
resizeCss(videotag, w, h);
resizeCss(poster, w, h);
resizeCss(flash, w, h);

});


};



function resizeCss (elem, w, h) {
$(elem).css('width',w+'px').css('height',h+'px');
};




//});



/* ======== END RESIZE VIDEO ========= */
