$(document).ready(function () {
	//$(".posttime").html(getUTC($(this).html()));
	$("a.picset").hide();
	$("a.picset.1").show();
	$("div.question").hide();
	$("div.question.1").show();
	
	$(".profileForm input").value ='';
	
	if (window.location.querystring["tab"]=="comm") { switchTab('communityTab'); }
	
});


var qtaglist = new Array();

function qTag(tagid) {
	var tmp = (in_array(tagid,qtaglist)) ? removeTag(tagid) : addTag(tagid);
	if (qtaglist.length>=1 && $('#askquestion input.questionField').val()!="") {  $('#askquestion input.questionSubmit').show(); } else { $('#askquestion input.questionSubmit').hide(); }
}

function addTag(tagid) {
	qtaglist.push(tagid);
	$("#tag-"+tagid).addClass("on");
	$("#askquestion #tags").val(qtaglist.toString());
}
function removeTag(tagid) {
	tagPos = qtaglist.indexOf(tagid);
	//alert(tagPos);
	qtaglist.splice(tagPos,1);
	$("#tag-"+tagid).removeClass("on");
	$("#askquestion #tags").val(qtaglist);
}



var timer = null

function stop() { clearTimeout(timer); }

function getUTC(datetime) {
	if (datetime.length >=4) {
		var today = new Date();
		var time = new Date(datetime);
		var date = (time.getMonth()+1) + "/" + time.getDate();
		var diff = (time.getTimezoneOffset()/60);
		var hours = time.getHours()-diff; 
		var ampm = ((hours > 12) ? ("pm") : ("am")); 
		hours = ((hours > 12) ? hours-12 : hours); 
		var minutes = time.getMinutes(); 	minutes=((minutes < 10) ? "0" : "") + minutes;
		if ((today.getMonth()+1 + "/" + today.getDate()) == date) {
		document.write("Today at " +hours+":"+minutes+" "+ampm);
		} else {
		document.write(date + " " + hours+":"+minutes+" "+ampm);
		}
		//document.getElementById("theTime").innerHTML = date + " <b>" + hours+":"+minutes+"</b>";
		//timer = setTimeout("start()",200);
	}
}

function picset(s) {
	$("a.picset").hide();
	$("a.picset."+s).show();
}

function pageset(s) {
	$("div.question").hide();
	$("div.question."+s).show();
}


window.location.querystring = (function() {
    // by Chris O'Brien, prettycode.org
    var collection = {};
    // Gets the query string, starts with '?'
    var querystring = window.location.search;
    // Empty if no query string
    if (!querystring) {
        return { toString: function() { return ""; } };
    }
    // Decode query string and remove '?'
    querystring = decodeURI(querystring.substring(1));
   // Load the key/values of the return collection
    var pairs = querystring.split("&");
    for (var i = 0; i < pairs.length; i++) {
        // Empty pair (e.g. ?key=val&&key2=val2)
        if (!pairs[i]) {
            continue;
        }
        // Don't use split("=") in case value has "=" in it
        var seperatorPosition = pairs[i].indexOf("=");
        if (seperatorPosition == -1) {
            collection[pairs[i]] = "";
        }
        else {
            collection[pairs[i].substring(0, seperatorPosition)] 
                = pairs[i].substr(seperatorPosition + 1);
        }
    }
    // toString() returns the key/value pairs concatenated
    collection.toString = function() {
        return "?" + querystring;
    };
    return collection;
})();

if (!Array.indexOf) {
  Array.prototype.indexOf = function (obj, start) {
    for (var i = (start || 0); i < this.length; i++) {
      if (this[i] == obj) {
        return i;
      }
    }
  }
}

function in_array( what, where ){
	var a=false;
	for(var i=0;i<where.length;i++){
	  if(what == where[i]){
	    a=true;
        break;
	  }
	}
	return a;
}