﻿function initTabs() {
    var tabContainers = $('div.tabs > div');

    $('div.tabs ul.tabNavigation a').click(function () {
        tabContainers.hide().filter(this.hash).show();

        $('div.tabs ul.tabNavigation a').removeClass('selected');
        $(this).addClass('selected');

        return false;
    }).filter(':first').click();

}



function initFeeds() {
    //*twitterFeed();
}

function formatTwitterDate(date) {
    splitDate = date.split(":");

    d = splitDate[0] + ":" + splitDate[1];

    return (d);
}


function linkify(text) {
    if (text) {
        var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
        return text.replace(exp, "<a href='$1'>$1</a>");
    }
}

function twitterFeed() {
    var feedLink = "http://twitter.com/iyusCMS";
    var twitterCount = 0;
    $.ajax({
        type: "GET",
        url: "async/twitterfeed",
        success: function (theResponse) {
            var object = theResponse;
            var json = eval(object);
            var jsonLen = json.length;
            if (jsonLen > 0) {
                for (var i = 0; i < jsonLen; i++) {
                    if (twitterCount < 5) {
                        if (json[i].user.name == "Rodda's Cream") {
                            $("#twitter").append("<p><strong><a href=\"" + feedLink + "\">" + json[i].user.name + "</a></strong> <span class=\"date\">" + formatTwitterDate(json[i].created_at) + "</span><br>" + linkify(json[i].text) + "</p>");
                            twitterCount++;
                        }
                    }
                }
            }
        }
    });
}



(function ($) {

    $.fn.hint = function (blurClass) {
        if (!blurClass) {
            blurClass = 'blur';
        }

        return this.each(function () {
            // get jQuery version of 'this'
            var $input = $(this),

            // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = $(this.form),
      $win = $(window);

            function remove() {
                if ($input.val() === title && $input.hasClass(blurClass)) {
                    $input.val('').removeClass(blurClass);
                }
            }

            // only apply logic if the element has the attribute
            if (title) {
                // on blur, set value to title attr if text is blank
                $input.blur(function () {
                    if (this.value === '') {
                        $input.val(title).addClass(blurClass);
                    }
                }).focus(remove).blur(); // now change all inputs to title

                // clear the pre-defined text when form is submitted
                $form.submit(remove);
                $win.unload(remove); // handles Firefox's autocomplete
            }
        });
    };

})(jQuery);


			$(function(){ 
			    // find all the input elements with title attributes
				$('input[title!=""]').hint();
			});
