// Twitter

(function($) {
 
	$.fn.tweet = function(o){
		var s = {
			username: [""],              			// [string]   required, unless you want to display our tweets. :) it can be an array, just do ["username1","username2","etc"]
			avatar_size: null,                      // [integer]  height and width of avatar if displayed (48px max)
			count: 3,                               // [integer]  how many tweets to display?
			loading_text: null,                     // [string]   optional loading text, displayed while tweets load
			query: null,                            // [string]   optional search query
			animate: false,							// [boolean]  static/fading
			speed: 3000,							// [integer]  Animation speed
			box: (" ul.tweet_list", $(this))
		};
		
		if(o) $.extend(s, o);
    
		$.fn.extend({
			linkUrl: function() {
				var returning = [];
				var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
				this.each(function() {
					returning.push(this.replace(regexp,"<a href=\"$1\">$1</a>"));
				});
				return $(returning);
			},
			linkUser: function() {
				var returning = [];
				var regexp = /[\@]+([A-Za-z0-9-_]+)/gi;
				this.each(function() {
					returning.push(this.replace(regexp,"<a href=\"http://twitter.com/$1\">@$1</a>"));
				});
				return $(returning);
			},
			linkHash: function() {
				var returning = [];
				var regexp = /(?:^| )[\#]+([A-Za-z0-9-_]+)/gi;
				this.each(function() {
					returning.push(this.replace(regexp, ' <a href="http://search.twitter.com/search?q=&tag=$1&lang=all&from='+s.username.join("%2BOR%2B")+'">#$1</a>'));
				});
				return $(returning);
			}
		});

		function parse_date(date_str) {
			return Date.parse(date_str.replace(/^([a-z]{3})( [a-z]{3} \d\d?)(.*)( \d{4})$/i, '$1,$2$4$3'));
		}

		function relative_time(time_value) {
			var parsed_date = parse_date(time_value);
			var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
			var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
			var r = '';
			if (delta < 60) {
				r = delta + ' seconds ago';
			} else if(delta < 120) {
				r = 'a minute ago';
			} else if(delta < (45*60)) {
				r = (parseInt(delta / 60, 10)).toString() + ' minutes ago';
			} else if(delta < (2*60*60)) {
				r = 'an hour ago';
			} else if(delta < (24*60*60)) {
				r = '' + (parseInt(delta / 3600, 10)).toString() + ' hours ago';
			} else if(delta < (48*60*60)) {
				r = 'a day ago';
			} else {
				r = (parseInt(delta / 86400, 10)).toString() + ' days ago';
			}
			return 'about ' + r;
		}

		function build_url() {
			var proto = ('https:' == document.location.protocol ? 'https:' : 'http:');
			 if (s.query == null && s.username.length == 1) {
				return proto+'//api.twitter.com/1/statuses/user_timeline.json?screen_name='+s.username[0]+'&count='+s.count+'&include_rts=1&callback=?';
			} else {
				var query = (s.query || 'from:'+s.username.join(' OR from:'));
				return proto+'//search.twitter.com/search.json?&q='+encodeURIComponent(query)+'&rpp='+s.count+'&callback=?';
			}
		}

		function start_animation() {
			$('li:first', s.box).animate({
				opacity: 0
			}, s.speed, function() {
				$('li:first', s.box).appendTo('#tweetContainer ul').css({'opacity':1});
				start_animation();
			});
		}
		
		return this.each(function(i, widget){
			var list = $('<ul class="tweet_list">').appendTo(widget);
			var loading = $('<p class="loading">'+s.loading_text+'</p>');
			if(typeof(s.username) == "string"){
				s.username = [s.username];
			}
			if (s.loading_text) $(widget).append(loading);
			$(widget).bind("load", function(){
				$.getJSON(build_url(), function(data){
					if (s.loading_text) loading.remove();
					list.empty();
					var tweets = (data.results || data);
					$.each(tweets, function(i,item){
						var from_user = item.from_user || item.user.screen_name;
						var profile_image_url = item.profile_image_url || item.user.profile_image_url;
						var avatar_template = '<a class="tweet_avatar" href="http://twitter.com/'+from_user+'"><img src="'+profile_image_url+'" height="'+s.avatar_size+'" width="'+s.avatar_size+'" alt="'+from_user+'\'s avatar" title="'+from_user+'\'s avatar" border="0"/></a>';
						var avatar = (s.avatar_size ? avatar_template : '');
						var date = '<span class="tweet_time"><a href="http://twitter.com/'+from_user+'/statuses/'+item.id+'" title="view tweet on twitter">'+relative_time(item.created_at)+'</a></span>';
						var text = '<span class="tweet_text">' +$([item.text]).linkUrl().linkUser().linkHash()[0]+ '</span>';
						list.append('<li>' + avatar + date + " " + text + '</li>');
						list.children('li:first').addClass('tweet_first');
						list.children('li:odd').addClass('tweet_even');
						list.children('li:even').addClass('tweet_odd');
					});
					$(widget).trigger("loaded").trigger((tweets.length == 0 ? "empty" : "full"));
					if (s.animate) start_animation();
				});
			}).trigger("load");
		});
	};
})(jQuery);

$(document).ready(function() {

	$('#container-right').append($('.twtr-widget'));

	// Twitter Call
    $("#tweetContainer").tweet({
        username: "corexconnect",
        avatar_size: 0,
        count: 2,
        loading_text: "loading tweets...",
        animate: false,
        speed: 0
    });

});

// UDMv4.5 //
///////////////////////////////////////////////////////////////////
var um={'menuClasses':[],'itemClasses':[],'menuCode':[]};
///////////////////////////////////////////////////////////////////
//                                                               //
//  ULTIMATE DROP DOWN MENU Version 4.5 by Brothercake          //
//  http://www.udm4.com/                                         //
//                                                               //
//  This script may not be used or distributed without license   //
//                                                               //
///////////////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////////////
// CORE CONFIGURATION                                            //
///////////////////////////////////////////////////////////////////


//path to images folder
um.baseSRC = "udm-resources/";


//initialization trigger element ["id"];
um.trigger = "";


//navbar orientation
um.orientation = [
	"horizontal",	// alignment ["vertical"|"horizontal"|"popup"|"expanding"]
	"left",		// h align ["left"|"right"]
	"top",		// v align ["top"|"bottom"]
	"absolute",	// positioning ["relative"|"absolute"|"fixed"|"allfixed"]
	"0",	// x position ["em"|"ex"|"px"|"0"]
	"0",	// y position ["em"|"ex"|"px"|"0"]
	"1000",		// z order ["0" to "10000"] (menu takes 20000 headroom)
	];


//navbar list output
um.list = [
	"flexible",	// horizontal overflow ["rigid"|"flexible"]
	"yes",		// -SPARE-
	"no", 		// -SPARE-
	];


//menu behaviors
um.behaviors = [
	"200",		// open timer ["milliseconds"|"0"]
	"500",		// close timer ["milliseconds"|"never"|"0"]
	"yes",		// reposition menus to stay inside the viewport ["yes"|"no"]
	"default",	// manage windowed controls for win/ie ["default","hide","iframe","none"]
	];


//reset behaviors
um.reset = [
	"yes",		// reset from document mouse click ["yes"|"no"]
	"yes",		// reset from window resize ["yes"|"no"]
	"yes",		// reset from text resize ["yes"|"no"]
	"no",		// reset after following link ["yes"|"no"]
	];


//horizontal continuation strip
um.hstrip = [
	"none",		// background ["color"|"#hex"|"rgb()"|"image.gif"|"none"]
	"yes",		// copy navbar item margin-right to margin-bottom ["yes"|"no"]
	];




///////////////////////////////////////////////////////////////////
// MODULE SETTINGS                                               //
///////////////////////////////////////////////////////////////////


//keyboard navigation [comment out or remove if not using]
um.keys = [
	"38",		// up ["n"] ("38" = up arrow key)
	"39",		// right ["n"] ("39" = right arrow key)
	"40",		// down ["n"] ("40" = down arrow key)
	"37",		// left ["n"] ("37" = left arrow key)
	"123",		// hotkey ["n"] ("38" = F12]
	"none",		// hotkey modifier ["none"|"shiftKey"|"ctrlKey"|"altKey"|"metaKey"]
	"27",		// escape ["n"|"none"] ("27" = escape key)
	"document.getElementsByTagName('a')[0]", // exit focus ["js-expression"]
	];




///////////////////////////////////////////////////////////////////
// NAVBAR DEFAULT STYLES                                         //
///////////////////////////////////////////////////////////////////


//styles which apply to the navbar
um.navbar = [
	"-7",		// nav -> menu x-offset (+-)["n" pixels]
	"-11",		// nav -> menu y-offset (+-)["n" pixels]
	"111px",	// width ["em"|"ex"|"px"] (vertical navbar only - horizontal navbar items have "auto" width) ("%" doesn't work right)
	];


//styles which apply to each navbar item
um.items = [
	"1",		// margin between items ["n" pixels]
	"0",		// border size ["n" pixels] (single value only)
	"",	// border collapse ["collapse"|"separate"] (only applies when margin = "0")
	"",// border colors ["color"|"#hex"|"rgb()"] (single, double or four values)
	"",	// border styles ["solid"|"double"|"dotted"|"dashed"|"groove"|"ridge"|"inset"|"outset"] (single, double or four values; be careful with using "none")
	"",// hover/focus border colors ["color"|"#hex"|"rgb()"] (single, double or four values)
	"",	// hover/focus border styles ["solid"|"double"|"dotted"|"dashed"|"groove"|"ridge"|"inset"|"outset"] (single, double or four values; be careful with using "none")
	"",// visited border colors ["color"|"#hex"|"rgb()"] (single, double or four values)
	"",// visited border styles ["solid"|"double"|"dotted"|"dashed"|"groove"|"ridge"|"inset"|"outset"] (single, double or four values; be careful with using "none")
	"0",		// left/right padding ["n" pixels] (single value only)
	"0",		// top/bottom padding ["n" pixels] (single value only)
	"",		// background ["color"|"#hex"|"rgb()"|"image.gif"]
	"",		// hover/focus background ["color"|"#hex"|"rgb()"|"image.gif"]
	"",		// visited background ["color"|"#hex"|"rgb()"|"image.gif"]
	"1EM",		// font size ["em"|"ex"|"%"|"px"|"pt"|"absolute-size"|"relative-size"]
	"arial, helvetica,sans-serif",// font family ["font1,font2,font3"] (always end with a generic family name)
	"normal",		// font weight ["normal"|"bold"|"bolder"|"lighter|"100" to "900"]
	"none",		// text decoration ["none"|"underline"|"overline"|"line-through"]
	"left",		// text-align ["left"|"right"|"center"]
	"#efbf20",	// color ["color"|"#hex"|"rgb()"]
	"#efbf20",	// hover/focus color ["color"|"#hex"|"rgb()"]
	"",	// visited color ["color"|"#hex"|"rgb()"]
	"normal",	// font-style ["normal"|"italic"|"oblique"]
	"normal",	// hover/focus font-style ["normal"|"italic"|"oblique"]
	"normal",	// visited font-style ["normal"|"italic"|"oblique"]
	"letter-spacing:0",// additional link CSS (careful!)
	"",		// additional hover/focus CSS (careful!)
	"",		// additional visited CSS (careful!)
	"",// menu indicator character/image ["text"|"image.gif"|"none"]
	"",// menu indicator rollover character/image ["text"|"image.gif"|"none"] (must be same type)
	"7",		// clipping width of indicator image ["n" pixels] (only when using image arrows)
	"..",		// alt text of indicator image ["text"] (only when using image arrows)
	];




///////////////////////////////////////////////////////////////////
// MENU DEFAULT STYLES                                           //
///////////////////////////////////////////////////////////////////


//styles which apply to each menu
um.menus = [
	"-7",		// menu -> menu x-offset (+-)["n" pixels]
	"-12",		// menu -> menu y-offset (+-)["n" pixels]
	"",		// border size ["n" pixels] (single value only)
	"",// border colors ["color"|"#hex"|"rgb()"] (single, double or four values)
	"",	// border styles ["solid"|"double"|"dotted"|"dashed"|"groove"|"ridge"|"inset"|"outset"] (single, double or four values; be careful with using "none")
	"9.8em",	// width ["em"|"ex"|"px"]
	"2",		// padding ["n" pixels] (single value only)
	"#8697B7",	// background ["color"|"#hex"|"rgb()"|"image.gif"]
	"",		// additional menu CSS (careful!) (you can use a transition here but *not* a static filter)
	"",// shadow background ["color"|"#hex"|"rgb()"|"image.gif"|"none"]
	"2px",		// shadow offset (+-) ["em"|"px"|"pt"|"%"|"0"]
	"filter:alpha(opacity=50);",// additional shadow layer CSS (if you use a Microsoft.Shadow filter here then Win/IE5.5+ will do that *instead* of default shadow)
	];


//styles which apply to each menu item
um.menuItems = [
	"0",		// margin around items ["n" pixels] (single value only; margins are like table cellspacing)
	"1",		// border size ["n" pixels] (single value only)
	"separate",	// border collapse ["collapse"|"separate"] (only applies when margin = "0")
	"#AAAFBB",	// border colors ["color"|"#hex"|"rgb()"] (single, double or four values)
	"solid",	// border styles ["solid"|"double"|"dotted"|"dashed"|"groove"|"ridge"|"inset"|"outset"] (single, double or four values; be careful with using "none")
	"#aca",		// hover/focus border colors ["color"|"#hex"|"rgb()"] (single, double or four values)
	"solid",	// hover/focus border styles ["solid"|"double"|"dotted"|"dashed"|"groove"|"ridge"|"inset"|"outset"] (single, double or four values; be careful with using "none")
	"#000",	// visited border colors ["color"|"#hex"|"rgb()"] (single, double or four values)
	"solid",	// visited border styles ["solid"|"double"|"dotted"|"dashed"|"groove"|"ridge"|"inset"|"outset"] (single, double or four values; be careful with using "none")
	"5",		// left/right padding ["n" pixels] (single value only)
	"2",		// top/bottom padding ["n" pixels] (single value only)
	"transparent",	// background ["color"|"#hex"|"rgb()"|"image.gif"]
	"#98B5D8",	// hover/focus background ["color"|"#hex"|"rgb()"|"image.gif"]
	"transparent",	// visited background ["color"|"#hex"|"rgb()"|"image.gif"]
	"1EM;",		// font size ["em"|"ex"|"%"|"px"|"pt"|"absolute-size"|"relative-size"]
	"arial, helvetica,sans-serif",// font family ["font1,font2,font3"] (always end with a generic family name)
	"normal",	// font weight ["normal"|"bold"|"bolder"|"lighter|"100" to "900"]
	"none",		// text decoration ["none"|"underline"|"overline"|"line-through"]
	"left",		// text-align ["left"|"right"|"center"]
	"#fff",		// color ["color"|"#hex"|"rgb()"]
	"#000",		// hover/focus color ["color"|"#hex"|"rgb()"]
	"",		// visited color ["color"|"#hex"|"rgb()"]
	"normal",	// font-style ["normal"|"italic"|"oblique"]
	"normal",	// hover/focus font-style ["normal"|"italic"|"oblique"]
	"normal",	// visited font-style ["normal"|"italic"|"oblique"]
	"",		// additional link CSS (careful!)
	"",		// additional hover/focus CSS (careful!)
	"",		// additional visited CSS (careful!)
	"right-green.gif",// submenu indicator character/image ["text"|"image.gif"|"none"]
	"right-black.gif",// submenu indicator rollover character/image ["text"|"image.gif"|"none"] (must be the same type)
	"3",		// clipping width of indicator image ["n" pixels] (only when using image arrows)
	"..",		// alt text of indicator image ["text"] (only when using image arrows)
	];



///////////////////////////////////////////////////////////////////
// DYNAMIC MENUS                                                 //
///////////////////////////////////////////////////////////////////





