window.addEvent('domready', function() {
    AddHooksToContent();
    var array = $$('.TwitterStatus');

    array.each(function(el, i, a) {
        el.addEvents({
            'mouseenter': function() {
                el.setStyle('background-position', '0px -55px');
                el.setStyle('color', '#ffffff');
            }
        ,
            'mouseleave': function() {

                el.setStyle('background-position', '0px 0px');
                el.setStyle('color', '#CFD1D2');
            }
        });
    });

    $$(".twitTxt").each(function(e, i, a) {
        e.set("html", linkify_plain(e.get("html")));
        e.set("html", e.get("html").linkify_tweet());

    });

    $("joinNowFreeNormal").addEvent("click", function() {
        $('DropdownLoginMenu').setStyle("display", "");
        $('DropdownLoginMenu').morph({ "opacity": "1" });
        $("RUName").focus();
    });

});
function AddHooksToContent() {

    //setup
    if ($("searchbutton")) {
        $("searchbutton").addEvent("click", function() {

            var txtboxval = "";
            if ($('SearchInputHome')) {
                var txtboxval = $('SearchInputHome').getProperty("value").toUpperCase();
            }

            //alert(txtboxval);

            SetWidgetpositionForSearch(txtboxval);
            //alert("done");
            // 
        });
    }

    $('buyNormal').set('morph', { duration: '1000', transition: 'expo:out' });
    $('questionNormal').set('morph', { duration: '1000', transition: 'expo:out' });
    $('greenStarNormal').set('morph', { duration: '1000', transition: 'expo:out' });
    $('joinNowFreeNormal').set('morph', { duration: '1000', transition: 'expo:out' });

    //Add Events
    var el = $('col1');
    var el1 = $('col2');
    var el2 = $('col3');
    var el3 = $('joinNowFreeNormal');

    el.addEvents({
        'mouseenter': function() {
            $('buyNormal').morph({ opacity: 0 });
        },
        'mouseleave': function() {
            $('buyNormal').morph({ opacity: 1 });
        }
    });
    el1.addEvents({
        'mouseenter': function() {
            $('questionNormal').morph({ opacity: 0 });
        },
        'mouseleave': function() {
            $('questionNormal').morph({ opacity: 1 });
        }
    });
    el2.addEvents({
        'mouseenter': function() {
            $('greenStarNormal').morph({ opacity: 0 });
        },
        'mouseleave': function() {
            $('greenStarNormal').morph({ opacity: 1 });
        }
    });

    el3.addEvents({
        'mouseenter': function() {
            $('joinNowFreeNormal').morph({ opacity: 0.1 });
        },
        'mouseleave': function() {
            $('joinNowFreeNormal').morph({ opacity: 1 });
        }
    });

}




//function GetWidgetPosition() {
//    var WidgetPositionCookie = Cookie.read('WidgetPosition');

//    if (WidgetPositionCookie == null) {
//        return 1;
//    }

//    return WidgetPositionCookie;

//}

function linkify_plain(text) {
    if (!text) return text;

    text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi, function(url) {
        nice = url;
        if (url.match('^https?:\/\/')) {
            nice = nice.replace(/^https?:\/\//i, '')
        }
        else
            url = 'http://' + url;
        return '<a target="_blank" rel="nofollow" href="' + url + '">' + nice.replace(/^www./i, '') + '</a>';
    });

    return text;
}

String.prototype.linkify_tweet = function() {
    var tweet = this.replace(/(^|\s)@(\w+)/g, "<a target=\"_blank\" rel=\"nofollow\" href=\"http://www.twitter.com/$2\">$1@$2</a>");
    return tweet.replace(/(^|\s)#(\w+)/g, "<a target=\"_blank\" rel=\"nofollow\" href=\"http://search.twitter.com/search?q=%23$2\">$1#$2</a>");
};

