//
// Config
//
var start = true;
var canplay = true;
var container = {};
var date = 0;
container.days = {};
container.hours = {};
container.mins = {};
container.secs = {};

//
// Geocode Address
//1072.05


//
// Init
//
$(document).ready(function() {
	
	//
	// Set Current Event
	//
	checkEventTimeout();
	function checkEventTimeout(){
		var dateNow = new Date();
		var time = dateNow.getTime();
		var current = new Date($("#video.dashboard .speaker .end").text()+":00");
		var current = current.getTime();
		// Check to see if current time is empty or past the time now
		if(current <= time || current == '' || current == undefined || current == NaN || $("#video.dashboard .speaker .end").text() == ''){
			// Fadeout current speaker
			$("#video.dashboard .speaker").fadeOut(1000, function(){
				// Loop through all events
				$.each($('#schedule ul li:visible'), function(el, x){
					var el = $(this);
					var dateNow = new Date();
					var time = dateNow.getTime();
					var start = new Date(el.find(".event_start").text()+":00");		
					start = start.getTime();
					var end = new Date(el.find(".event_end").text()+":00");
					end = end.getTime();
					// If event time's starting time is less then now and end time greater then now
					if(start <= time && end >= time){
						// If there is a speaker for that event
						if($("#speaker_" + el.find(".id").text()).length >= 1){
							var speaker = $("#speaker_" + el.find(".id").text());
							if($('#video.dashboard .speaker .id').text() != el.find(".id").text() && el.find(".id").text() != ''){
								var current_speaker = $("#video.dashboard .speaker");
								current_speaker.find('.id').text(el.find('.id').text());
								current_speaker.find('.name').text(speaker.find('.name').text()).attr('href',el.find('.permalink').text());
								current_speaker.find('.title').text(el.find('.session strong').text());
								current_speaker.find('.avatar').attr('src',speaker.find('.image').text());
								current_speaker.find('.description').text('').html('');
								current_speaker.find('.description').html(speaker.find('.bio').text() + ' <a href="'+speaker.find('.permalink').text()+'" title="">Learn More</a>');
								// el.fadeOut(1000);
								if(!current_speaker.is(':visible')){
									current_speaker.fadeIn(1000);
								}
							}
						} else {
							// Non-Speaker Event At that's between time
							var current_speaker = $("#video.dashboard .speaker");
							current_speaker.find('.end').text(el.find('.event_end').text());
							current_speaker.fadeOut(1000);
						}
					}
					if(end <= time){
						el.fadeOut(1000);
					}
				});
			});
		}
		setTimeout(function(){checkEventTimeout()}, 15000);
	}
	
	//
	// Check Event Timeout
	//
	/*
	function checkEventTimeout(){
		var el = $('#current_event_end');
		if(el.length > 0){
			var date = new Date(), time = date.getUTCSeconds();
			if(parseInt(el.text()) >= time){
				window.location.reload(true);
			}
		}
		setTimeout(function(){checkEventTimeout();}, 25000);	
	}
	*/
	
	//
	// Dashboard Controls
	//
	$(".dash_controls .dash_play").live("click", function(){
		$(this).removeClass().addClass('dash_pause');
		player.startPlayback();	
	});
	$(".dash_controls .dash_pause").live("click", function(){
		$(this).removeClass().addClass('dash_play');
		player.stopPlayback();	
	});
	$(".dash_controls .dash_vol_up").live("click", function(){
		player.volumeUp();	
	});
	$(".dash_controls .dash_vol_down").live("click", function(){
		player.volumeDown();	
	});
	$(".dash_controls .dash_mute").live("click", function(){
		if(!player.isMute()){
			player.setMute(true);
		} else {
			player.setMute(false);	
		}
	});
	
	//
	// Twitter Feed
	//
	twitter_feed(0);
	function twitter_feed(date) {
		$.ajax({
			url: "http://search.twitter.com/search.json?q=tedxto+OR+tedxtoronto&callback=?",
			cache: false,
			dataType: "jsonp",
			success: function(data){
				
				if(countJSON(data.results) >= 1){
				
					var x = countJSON(data.results)-1;
					date = $(data.results).get(0).id;
					data.results.reverse();
					
					$.each((data.results || data), function(i,item){
						
						var today = new Date(),
						d = new Date(item.created_at),
						diff =  (d.getTime() - today.getTime())*-1,
						text = "",
						num = 0,
						el = "";
						
						if(d.getMinutes() < 10){
							var minutes	= "0" + d.getMinutes();
						} else {
							var minutes = d.getMinutes();	
						}
						
						if(d.getHours() > 11){
							if(d.getHours() > 12){
								var hours = d.getHours() - 12;	
							} else {
								var hours = d.getHours();	
							}
							var thetime =  hours + ':' + minutes + 'PM';
						} else {
							var thetime =  d.getHours() + ':' + minutes + 'AM';
						}
						
							el += '<li class="tweet" style="display:none;">';
							el += '<p class="text">';
							el += item.text;
							el += '</p>';
							el += '<p class="meta">';
							el += '<span class="time"><a href="http://twitter.com/' + item.from_user + '/status/' + item.id + '" target="_blank">' + thetime + '</a></span>';
							el += '<span class="author"> by <a href="http://twitter.com/' + item.from_user + '" target="_blank" title="" class="name">@' + item.from_user + '</a></span>';
							el += '</p>';
							el += '</li>';
						
						$("body").queue(function(next){
							
							var q = $(this);
								
							$("#sidebar .feed").prepend(el).find(".tweet:hidden").show(0, function(){
								if(parseFloat($(".tweet").length) >= 6){
									$("#sidebar .feed .tweet:last").remove();
									q.dequeue();
									next();	
								} else {
									q.dequeue();
									next();
								}
							});
							
							
						});
								
					});					
				}
				$(".tweet .text").each(function(){
					var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
					$(this).html($(this).html().replace(exp,"<a href='$1' target='_blank'>$1</a>")); 
				});
			}, error: function(e, xhr){
				//alert("Error: conection to twitter");
			}
		});
		
		setTimeout(function(){twitter_feed(date)}, 25000);	
	}
	
	//
	// Rypple 
	//
	$("#video.dashboard .speaker .more a").click(function(){
	
		if($("#video.dashboard .speaker .rypple").is(":visible")){
			$("#video.dashboard .speaker .rypple").hide(1000);
		} else {
			$("#video.dashboard .speaker .rypple").show(1000);
		}
		
	});
	
	//
	// Homepage Video
	//
	$(".video-image").click(function(){
		$("#slideshow").fadeOut(500, function(){
			$(".slideshow-video").fadeIn(500, function(){
				$(".slideshow-video .video-controls .play-pause").trigger("click");
			});
		});
	});	
	
	//
	// Homepage Video Close
	//
	$(".slideshow-video .close").click(function(){
		$(".slideshow-video").fadeOut(500, function(){
			$("#slideshow").fadeIn(500);
		});
	});
	
	//
	// Speakers Single Video
	//
	$(".speaker-info .speaker-info-meta .watch-speaker-video, #speakers-single .offset-bottom .play-video").click(function(){
		$("#speakers-single .offset-bottom .speaker-picture, #speakers-single .offset-bottom .play-video").animate({"opacity":"0"}, 500, function(){
			$("#speakers-single .offset-bottom .object .redbar ").animate({"width":"580px"}, 500, function(){
				$("#speakers-single .offset-bottom .object .inset").fadeIn(500, function(){
					$(".speaker-info .video-controls .play-pause").trigger("click");
				});
			});
		});
	});
	
	$("#speakers-single .offset-bottom .object .inset .close").click(function(){
		$("#speakers-single .offset-bottom .object .inset").fadeOut(500, function(){
			$("#speakers-single .offset-bottom .object .redbar ").animate({"width":"0px"}, 500, function(){
				$("#speakers-single .offset-bottom .speaker-picture, #speakers-single .offset-bottom .play-video").animate({"opacity":"1"}, 500);
			});
		});
	});
	
	//
	// Load Video If Specified
	//
	var url = getUrlVars();
	if(url['video'] != "" && url['video'] != undefined){
		
		$("body").delay(200).queue(function(){
			$("#video").fadeIn(200, function(){
				$("body").delay(400).queue(function(){
					var ytplayer = document.getElementById("ytplayer0");
					ytplayer.loadVideoByUrl(url['video']);
					$("#video h5").text(url['title']);
					$(this).dequeue();
				});
			});
			$(this).dequeue();
		});
	}
	
	//
	// Add Video Controls for Theater Videos
	//
	$("body").delay(200).queue(function(){
		
		$(".video-player").prepend('<a href="#" class="share_twitter">Share via Twitter</a>' + '<a href="#" class="share_facebook">Share via Facebook</a>' + '<a href="#" class="share_email">Share via Email</a>');
		
		if(url['video'] == "" || url['video'] == undefined){
			var video = "http://www.youtube.com/watch?v=yd53yY_3dX4";
			var title = "TEDx Toronto Intro";
		} else {
			var video = url['video'];
			var title = url['title']; 
		}
		
		$(".video-player a.share_twitter").attr("href","http://twitter.com/home?status=" + video);
		$(".video-player a.share_facebook").attr("href","http://facebook.com/sharer.php?u=" + video);
		$(".video-player a.share_email").attr("href","mailto:?subject=" + title + "&body=" + video);
		
		$(this).dequeue();
	});

	
	//
	// Load Theater Videos
	//
	$(".queue-video").click(function(e){
		var el = $(this);
		window.location = "#video";
		e.preventDefault();
		if($("#video").height() == 0){
			console.log('not visible. elem: '+$('#ytplayer0'));
			$("#video").css({'padding-top':'20px', 'border-top': '1px solid #e1e1e2','margin-bottom':'20px'}).animate({height: 364},1000);
			var ytplayer = document.getElementById("ytplayer0");
			ytplayer.loadVideoByUrl(el.attr("title"));
			$("#video h5").text(el.text());
			$(".video-player a.share_twitter").attr("href","http://twitter.com/home?status=" + el.attr("title"));
			$(".video-player a.share_facebook").attr("href","http://facebook.com/sharer.php?u=" + el.attr("title"));
			$(".video-player a.share_email").attr("href","mailto:?subject=" + el.text() + "&body=" + el.attr("title"));
			window.location.hash = "#video=" + el.attr("title") + "&title=" + el.text();

		} else {
			window.location.hash = "#video";
			var ytplayer = document.getElementById("ytplayer0");
			ytplayer.loadVideoByUrl(el.attr("title"));
			$("#video h5").text(el.text());
			$(".video-player a.share_twitter").attr("href","http://twitter.com/home?status=" + el.attr("title"));
			$(".video-player a.share_facebook").attr("href","http://facebook.com/sharer.php?u=" + el.attr("title"));
			$(".video-player a.share_email").attr("href","mailto:?subject=" + el.text() + "&body=" + el.attr("title"));
			window.location.hash = "#video=" + el.attr("title") + "&title=" + el.text(); 
		}
	});
	
	//
	// CForms Fixes
	//
	$('#sendbutton2, #sendbutton, #sendbutton5').click(function(){
		$("body").animate({scrollTop:0}, 'slow');	
	});
	
	$('#cf2_field_15, #cf2_field_16, #cf2_field_17, #cf5_field_11, #cf5_field_12, #cf5_field_13, #question_one, #question_two, #question_three').keyup(function(e){
		var words = $(this).val().split(' ');
		var count = words.length;
		if(count > 100){
			var temp = '';
			for(var i=0;i < 100;i++){
				temp = temp + words[i] + " "; 
			}
			$(this).val(temp);
		}	
	}).keydown(function(e){
		var words = $(this).val().split(' ');
		var count = words.length;
		if(count > 100){
			if(e.keyCode != 8 && e.keyCode != 46 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40){
				e.preventDefault();
			}
		}
	}).live("input paste", function(e){
		$(this).trigger("keyup");
	});
	
	$('#cf2_field_14, #cf5_field_10').keyup(function(e){
		var words = $(this).val().split(' ');
		var count = words.length;
		if(count > 150){
			var temp = '';
			for(var i=0;i < 150;i++){
				temp = temp + words[i] + " "; 
			}
			$(this).val(temp);
		}	
	}).keydown(function(e){
		var words = $(this).val().split(' ');
		var count = words.length;
		if(count > 150){
			if(e.keyCode != 8 && e.keyCode != 46 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40){
				e.preventDefault();
			}
		}
	}).live("input paste", function(e){
		$(this).trigger("keyup");
	});
	
	//
	// Limit Words
	//
	$('#question_four').keyup(function(e){
		var words = $(this).val().split(' ');
		var count = words.length;
		if(count >= 50){
			var temp = '';
			for(var i=0;i < 50;i++){
				temp = temp + words[i] + " "; 
			}
			$(this).val(temp);
		}	
	}).live("input paste", function(e){
		$(this).trigger("keyup");
	});
	
	//
	// Satelitte Events Location Address
	//
	$(".capture_location").focus(function(){
		if($(this).val() == "250 Front St W, Toronto, ON M5V 3G5"){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ""){
			$(this).val('250 Front St W, Toronto, ON M5V 3G5');
		}
	});
	
	//
	// Satelitte Events Location Name
	//
	$(".capture_location_name").focus(function(){
		if($(this).val() == "Enter Your Location Name"){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ""){
			$(this).val('Enter Your Location Name');
		}
	});
	
	//
	// Validate Satellite Event Form
	//
	$("#event-form #submit-event").click(function(e){
		
		e.preventDefault();
		var errors = [], ids = [], html = "";
		
		if($("#name").val() == ''){
			errors.push("Name is required");
			ids.push("#name");
		}
		
		if($("#address").val() == ''){
			errors.push("Address is required");
			ids.push("#address");
		}
		
		if($("#postal_code").val() == ''){
			errors.push("Postal Code is required");
			ids.push("#postal_code");
		}
		
		if($("#province").val() == '' || $("#province").val() == 'Select Province'){
			errors.push("Province is required");
			ids.push("#province");
		}
		
		if($("#city").val() == '' || $("#city").val() == 'Select City'){
			errors.push("City is required");
			ids.push("#city");
		}
		
		if(errors.length >= 1){
			
			for(var i=0;i < errors.length;i++){
				html += "<p>" + errors[i] + "</p>";
			}
			
			for(var x=0;x < ids.length;x++){
				$(ids[x]).addClass("new_error");
			}
			
			$("body").animate({scrollTop:0}, 'slow');
			
			$("#error").fadeIn(1000);
			
		} else {
			
			getAddress($("#address").val() + " " + $("#city").val() + " " + $("#province").val());
			
			$("#event-form input[type=text]").removeClass("new_error");
			$("#event-form input[type=select]").removeClass("new_error");
			$("#error").fadeOut(200);
			$("#event-form #submit-event").hide();
			$("#loader").fadeIn(1000, function(){
			
				$.post(app_url + "ajax.php?event=true&" + $("#event-form").serialize(), function(data){
					$("body").animate({scrollTop:0}, 'slow');
					if(data != false && data != undefined && data != null){
						$("#success").fadeIn(200);
						$("#event-form input[type=text]").val('');
						$("#event-form #submit-event").fadeIn(200);
						$("#loader").fadeOut(200);
					} else {
						$("#event-form #submit-event").fadeIn(200);
						$("#loader").fadeOut(200);
						$("#error").fadeIn(200);
					}
					
				});
								
			});
			
		}	
	});
	
	//
	// Dynamically Generate Video
	//
	$("#attend-form #video")
		.focus(function(){
			if($(this).val() == 'eg. http://www.youtube.com/watch?v=vTCgJo4phso'){
				$(this).val('');
			}
		})
		.blur(function(){
			if($(this).val() == ''){
				$(this).val('eg. http://www.youtube.com/watch?v=vTCgJo4phso');
				$("#attend-form #video-embed").fadeOut(1000);
				$("#attend-form #video-embed").fadeOut(1000);
			} else {
				var url = $(this).val(), video = '', host = get_host(url);
				if(host == 'vimeo.com'){
					video = get_directory(url);
					if(video != '' && is_numeric(video) == true){
						$("#attend-form #video-embed").html(' ' + 
														'<object width="648" height="393"> ' +
						                                '<param name="allowfullscreen" value="true" />  ' +
						                                '<param name="allowscriptaccess" value="always" />  ' +
						                                '<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' + video + '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" />  ' +
						                                '<embed wmode="transparent" src="http://vimeo.com/moogaloop.swf?clip_id=' + video + '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="648" height="393"></embed>  ' +
						                                '</object>').fadeIn(1000);
					} else {
						$("#attend-form #video-embed").fadeOut(1000);
					}
				} else if(host == 'youtube.com') {
					video = get_param(url, 'v');
					if(video != '' && video != null){
						$("#attend-form #video-embed").html(' '+
															'<object width="648" height="393"> ' +
							                                '<param name="movie" value="http://www.youtube.com/v/' + video + '?f=videos&app=youtube_gdata"></param>  ' +
							                                '<param name="allowFullScreen" value="true"></param>  ' +
							                                '<param name="allowscriptaccess" value="always"></param>  ' +
							                                '<embed src="http://www.youtube.com/v/' + video + '?f=videos&app=youtube_gdata" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="648" height="393"></embed>  ' +
							                                '</object>').stop().fadeIn(1000);
					} else {
						$("#attend-form #video-embed").fadeOut(1000);
					}
				} else {
				
					$("#attend-form #video-embed").fadeOut(1000);
					
				}
			}
		});
		
	//
	// Validate Application Form
	//
	$("#attend-form #submit-application").click(function(e){
		
		e.preventDefault();
		var errors = [], ids = [], html = "";
		
		if($("#attend-form #fname").val() == ''){
			errors.push("First Name is required");
			ids.push("#fname");
		}
		
		if($("#attend-form #lname").val() == ''){
			errors.push("Last Name is required");
			ids.push("#lname");
		}
		
		if($("#attend-form #email").val() == ''){
			errors.push("Email is required");
			ids.push("#email");
		}
		
		if($("#attend-form #organization").val() == ''){
			errors.push("Organization is required");
			ids.push("#organization");
		}
		
		if($("#attend-form #role").val() == ''){
			errors.push("Role is required");
			ids.push("#role");
		}
		
		if($("#attend-form #phone_number").val() == ''){
			errors.push("Phone Number is required");
			ids.push("#phone_number");
		}
		
		if($("#attend-form #question_one").val() == ''){
			errors.push("Facts about yourself is required");
			ids.push("#question_one");
		}
		
		if($("#attend-form #question_two").val() == ''){
			errors.push("A community call to action is required");
			ids.push("#question_two");
		}
		
		if($("#attend-form #question_three").val() == ''){
			errors.push("Your achievements is required");
			ids.push("#question_three");
		}
		
		if($("#attend-form #question_four").val() == ''){
			errors.push("What you'll gain is required");
			ids.push("#question_four");
		}
		
		if(errors.length >= 1){
			
			for(var i=0;i < errors.length;i++){
				html += "<p>" + errors[i] + "</p>";
			}
			
			for(var x=0;x < ids.length;x++){
				$(ids[x]).addClass("new_error");
			}
			
			$("body").animate({scrollTop:0}, 'slow');
			
			$("#error").fadeIn(1000);
			
		} else {
			
			$("#attend-form input[type=text]").removeClass("new_error");
			$("#attend-form textarea").removeClass("new_error");
			$("#error").hide();
			$("#attend-form #submit-application").hide();
			$("#loader").show(1000);
			
			$.post(app_url + "ajax.php?apply=true&" + $("#attend-form").serialize(), function(data){
			
				$("body").animate({scrollTop:0}, 'slow');
				
				if(data != false && data != undefined && data != null){
					$("#success").fadeIn(1000);
					$("#attend-form #video-embed").hide();
					$("#attend-form input[type=text]").val('');
					$("#attend-form textarea").val('');
					$("#attend-form #submit-application").show(1000);
					$("#loader").hide(1000);
			
				} else {
					$("#attend-form #submit-application").show(1000);
					$("#loader").hide(1000);
					$("#error").fadeIn(1000);
				}
			});
			
		}	
	});
	
	//
	// Start Countdown
	//
	Countdown();
			
	// 
	// Slideshow
	//
	$('#slides').cycle({fx: 'scrollLeft', 
						speed: 1000, 
						timeout: 7000, 
						after: function(currSlideElement, nextSlideElement, options, forwardFlag){ 
							$("#slideshow .caption h1").text($(nextSlideElement).find(".description").text()); 
							$("#slideshow .caption strong").text($(nextSlideElement).find(".speaker-name").text()); 
							$("#slideshow .caption p").text($(nextSlideElement).find(".title").text());
							$("#slideshow .caption, #slideshow .learn-more").attr('href',$(nextSlideElement).find(".link").text()).fadeIn(500);
							$("#slideshow .learn-more").fadeIn(500); 
						}, 	
						before: function(currSlideElement, nextSlideElement, options, forwardFlag){ 
							$("#slideshow .caption,#slideshow .learn-more").fadeOut(500); 
						} });
	
	
	$('a.video-linked').ytchromeless();
	
	$('#slides, .video-linked, .caption').hover(function(){
		$('#slides').cycle('pause');
		
	}, function(){
		if(canplay){
			$('#slides').cycle('resume');
		}
	});	
	
	//
	// Twitter @Anywhere
	//
	twttr.anywhere(function (T) {
		T("#follow_us").hovercards({
	    	username: function(node) {
	        	return node.title;
	    	}
		});
	});

});

//
// Countdown
//

dateFuture = new Date("September 30, 2010 09:00:00");
	
function Countdown(){
	
	dateNow = new Date();							
	amount = dateFuture.getTime() - dateNow.getTime();
	delete dateNow;

	if(amount < 0){
	
		// alert('Date Past');
	
	} else{
		
		days=0;hours=0;mins=0;secs=0;out="";
		amount = Math.floor(amount/1000);
		
		//
		// Days
		//
		daysOrig=Math.floor(amount/86400);
		days=Math.floor(amount/86400);
		if(days < 10
		   ){
			days="0"+days.toString();
		}
		days=days.toString().split("");
		amount=amount%86400;

		//
		// Hours
		//
		hoursOrig=Math.floor(amount/3600);
		hours=Math.floor(amount/3600);
		if(hours < 10){
			hours="0"+hours.toString();
		}
		hours=hours.toString().split("");
		amount=amount%3600;

		//
		// Minutes
		//
		minsOrig=Math.floor(amount/60);
		mins=Math.floor(amount/60);
		if(mins < 10){
			mins="0"+mins.toString();
		}
		mins=mins.toString().split("");
		amount=amount%60;

		//
		// Seconds
		//
		secsOrig=Math.floor(amount);
		secs=Math.floor(amount);
		if(secs < 10){
			secs="0"+secs.toString();
		}
		secs=secs.toString().split("");
				
		//
		// Setup
		//
		$('.days-01 .number').text(days[0]);
		$('.days-02 .number').text(days[1]);
		$('.hrs-01 .number').text(hours[0]);
		$('.hrs-02 .number').text(hours[1]);
		$('.mins-01 .number').text(mins[0]);
		$('.mins-02 .number').text(mins[1]);
		$('.secs-01 .number').text(secs[0]);
		$('.secs-02 .number').text(secs[1]);
		
		//
		// Reset
		//
		setTimeout("Countdown()", 1000);
	}
}

//
// Get URL Paremeter
//
function get_param(url, name){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( url );
  if( results == null )
    return "";
  else
    return results[1];
}

//
// Get URL Host
//
function get_host(url) {
	return (url.match(/:\/\/(.[^/]+)/)[1]).replace('www.','');
}

//
// Get Directory
//
function get_directory(url) {
	var result = unescape(url.substring(0,(url.lastIndexOf("/")) + 1));
    return url.replace(result, '');
}

//
// Is Numeric
//
function is_numeric(string){
	var ValidChars = "0123456789.";
	var IsNumber = true;
	var Char;
	for (i = 0; i < string.length && IsNumber == true; i++){ 
		Char = string.charAt(i); 
		if(ValidChars.indexOf(Char) == -1){
		 	IsNumber = false;
		}
	}
	return IsNumber;
}

//
// Get URL Hash Vars
//

function getUrlVars(){
	
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('&');
 
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
 
    return vars;
}

//
// Count JSON Array
//
function countJSON(obj) {
	var prop;
	var propCount = 0;	
	for (prop in obj) {
		propCount++;
	}
	return propCount;
}


