﻿/* ///////////////////////////////////////////////////////////////////////// */
/* ON EACH PAGE LOAD THIS IS GOING TO CHECK WEATHER/NOT USER IS LOGGED IN   THAN POPULATE TWEETS !!!!!!!!!!!!! */
/* ///////////////////////////////////////////////////////////////////////// */

//$(document).ready(function () {
$(window).load(function () {
    var isloggedIn = false;
    function userLoggedIn() {
        $.ajax({
            type: "POST",
            url: "http://" + window.location.hostname + "/home/UserLoggedIn",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function loggedInReturn(loggedIn) {
                isloggedIn = (loggedIn.d);
                //alert("logged in = " + isloggedIn);
            }
        });
        return isloggedIn;
    }

    //Populates tweets on right colum
    function PopulateTweets() {

        $.ajax({
            type: "POST",
            url: "http://" + window.location.hostname + "/home/PopulateTweets",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function loggedInReturn(result) {
                $('#TwitterWidget').html(result.tweets);
            }
        });
    }

    //Populates the tweet in the banner
    function PopulateTwitterBannerStatus() {
        $.ajax({
            type: "POST",
            url: "http://" + window.location.hostname + "/home/PopulateTwitterBannerStatus",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function loggedInReturn(result) {
                $('.twitterContainer').html(result.tweet);
            }
        });
    }

    userLoggedIn();
    PopulateTwitterBannerStatus();  //Populates the tweet in the banner
    PopulateTweets();  //this will populate the Tweets on right colum

    /* ///////////////////////////////////////////////////////////////////////// */
    /* THIS ADDS SIGN IN/OUT functionallity to topof sight                         */
    /* ///////////////////////////////////////////////////////////////////////// 

    $('input[type="text"]').each(function () {

    this.value = $(this).attr('title');
    $(this).addClass('text-label');

    $(this).focus(function () {
    if (this.value == $(this).attr('title')) {
    this.value = '';
    $(this).removeClass('text-label');
    }
    });

    $(this).blur(function () {
    if (this.value == '') {
    this.value = $(this).attr('title');
    $(this).addClass('text-label');
    }
    });
    });
    */
    /*

    $('.navStore').click(function () {
    window.location.href = 'http://www.johnnyhollow.com/store.aspx';
    return false;
    });

    */

    /* /////////////////////////////////////////////////////////////////////////   */
    /* THIS ADDS SLIDE ANIMATION TO TWITTER FEED IN PAGE HEADER                    */
    /* /////////////////////////////////////////////////////////////////////////   */

    var tweetWidth = $(".slidingContent").width();

    $(".slidingContent").css("margin-left", tweetWidth + "px");
    $(".twitterContainer").css("width", tweetWidth + "px");

    startTwitterCycle();

    function startTwitterCycle() {
        $(".slidingContent").animate({ marginLeft: "-=" + tweetWidth * 2 + "px" }, { easing: "linear", duration: 30000,
            complete: function () {
                $(".slidingContent").css("margin-left", tweetWidth + "px");
                $(".twitterContainer").css("width", tweetWidth + "px");
                startTwitterCycle();
            }
        });
    }
});  //end (window).load
