﻿
$(document).ready(function (e) {

    /*zone interactive*/
    var $TabZone0 = $("#zo0");
    var $TabZone1 = $("#zo1");
    var $TabZone2 = $("#zo2");
    var $TabZone3 = $("#zo3");
    var $TabZone4 = $("#zo4");
    var $TabZone5 = $("#zo5");

    var $TabZone0A = $TabZone0.children("a");
    var $TabZone1A = $TabZone1.children("a");
    var $TabZone2A = $TabZone2.children("a");
    var $TabZone3A = $TabZone3.children("a");
    var $TabZone4A = $TabZone4.children("a");
    var $TabZone5A = $TabZone5.children("a");

    var $zone0 = $("#zone0");
    var $zone1 = $("#zone1");
    var $zone2 = $("#zone2");
    var $zone3 = $("#zone3");
    var $zone4 = $("#zone4");
    var $zone5 = $("#zone5");
    
    var $TabLiZone0 = $("#Lizo0");
    var $TabLiZone1 = $("#Lizo1");
    var $TabLiZone2 = $("#Lizo2");
    var $TabLiZone3 = $("#Lizo3");
    var $TabLiZone4 = $("#Lizo4");
    var $TabLiZone5 = $("#Lizo5");

    //cacher le conteu de tous les onglet et rendre inactif les onglet
    function HideZoneInteractive() {
        $TabLiZone0.removeClass("actif");
        $TabLiZone1.removeClass("actif");
        $TabLiZone2.removeClass("actif");
        $TabLiZone3.removeClass("actif");
        $TabLiZone4.removeClass("actif");
        $TabLiZone5.removeClass("actif");

        $zone5.hide();
        $zone4.hide();
        $zone3.hide();
        $zone2.hide();
        $zone1.hide();
        $zone0.hide();    
    }

    $TabZone0.click(function (e) {
        e.preventDefault();
        HideZoneInteractive();
        $TabLiZone0.addClass("actif");
        $zone0.show();
    });

    $TabZone1.click(function (e) {
        e.preventDefault();
        HideZoneInteractive();
        $TabLiZone1.addClass("actif");
        $zone1.show();
    });


    //facebook
    $.get("/OngletFacebook.aspx", function (data) {
        $("#newsfeed").html(data);
    });
   // $TabLiZone2.addClass("actif");

    $TabZone2.click(function (e) {
        e.preventDefault();
        HideZoneInteractive()

        $TabLiZone2.addClass("actif");
        $zone2.show();
    });

    //youtube
    $TabZone3.click(function (e) {
        e.preventDefault();
        HideZoneInteractive();

        if (!$TabZone3.hasClass("isFeed")) {
            $TabZone3.addClass("isFeed");

            //ajouter les favoris du compte
            // insert the script:
            var s = document.createElement('script');
            s.src = "http://gdata.youtube.com/feeds/api/users/TourismeRimouski/favorites?alt=json&v=2&callback=showMyVideos";
            document.getElementsByTagName('head')[0].appendChild(s);
        }

        $TabLiZone3.addClass("actif");
        $zone3.show();
    });

    //flicker
    $TabZone4.click(function (e) {
        e.preventDefault();
        HideZoneInteractive();

        if (!$TabZone4.hasClass("isFeed")) {
            $TabZone4.addClass("isFeed");
            $.get("/OngletFlickr.aspx", function (data) {
                $("#FlickR").html(data);
            });

        }

        $TabLiZone4.addClass("actif");
        $zone4.show();
    });

    //twitter
    $TabZone5.click(function (e) {
        e.preventDefault();
        HideZoneInteractive();

        if (!$TabZone5.hasClass("isFeed")) {
            $TabZone5.addClass("isFeed");
            $("#twitter").getTwitter({
                userName: TwitteruserName,
                numTweets: 15,
                loaderText: "Loading tweets...",
                slideIn: true,
                slideDuration: 750,
                showHeading: false,
                headingText: "",
                showProfileLink: false,
                showTimestamp: true
            });
        }
        $TabLiZone5.addClass("actif");
        $zone5.show();

    });
});


//afficher les video youtube (obliger car etjson pas suporter par api)
function showMyVideos(data) {
    var $UlListVideo = $("ul.demo2");
    $UlListVideo.html("");

    var feed = data.feed;
    var entries = feed.entry || [];
    for (var i = 0; i < entries.length; i++) {
        var entry = entries[i];
        var title = entry.title.$t;
        var Url = entry.link[0].href;
        if(i <2)
        {
        var $aLink = $("<a/>").attr("href", Url).text(title);
        var $li = $("<li/>");
        $aLink.appendTo($li);
        $li.appendTo($UlListVideo);
        }

    }

    $UlListVideo.ytplaylist(
                    {
                        addThumbs: true,
                        autoPlay: false,
                        allowFullScreen: true,
                        holderId: 'ytvideo2',
                        playerHeight: 240,
                        playerWidth: 310
                    });

    $("div.yt_holder").show();
}

(function ($) {
    /*
    jquery.twitter.js v1.5
    Last updated: 08 July 2009

    Created by Damien du Toit
    http://coda.co.za/blog/2008/10/26/jquery-plugin-for-twitter

    Licensed under a Creative Commons Attribution-Non-Commercial 3.0 Unported License
    http://creativecommons.org/licenses/by-nc/3.0/
    */

    $.fn.getTwitter = function (options) {

        $.fn.getTwitter.defaults = {
            userName: null,
            numTweets: 15,
            loaderText: "Loading tweets...",
            slideIn: true,
            slideDuration: 750,
            showHeading: true,
            headingText: "Latest Tweets",
            showProfileLink: false,
            showTimestamp: true
        };

        var o = $.extend({}, $.fn.getTwitter.defaults, options);

        return this.each(function () {
            var c = $(this);

            // hide container element, remove alternative content, and add class
            c.hide().empty().addClass("twitted");

            // add heading to container element
            if (o.showHeading) {
                c.append("<h2>" + o.headingText + "</h2>");
            }

            // add twitter list to container element
            var twitterListHTML = "<ul id=\"twitter_update_list\"><li></li></ul>";
            c.append(twitterListHTML);

            var tl = $("#twitter_update_list");

            // hide twitter list
            tl.hide();

            // add preLoader to container element
            var preLoaderHTML = $("<p class=\"preLoader\">" + o.loaderText + "</p>");
            c.append(preLoaderHTML);

            // add Twitter profile link to container element
            if (o.showProfileLink) {
                var profileLinkHTML = "<p class=\"profileLink\"><a target=\"_blank\" href=\"http://twitter.com/" + o.userName + "\">http://twitter.com/" + o.userName + "</a></p>";
                c.append(profileLinkHTML);
            }

            // show container element
            c.show();

            $.getScript("http://twitter.com/javascripts/blogger.js");
            $.getScript("http://twitter.com/statuses/user_timeline/" + o.userName + ".json?callback=twitterCallback2&count=" + o.numTweets, function () {
                // remove preLoader from container element
                $(preLoaderHTML).remove();

                // remove timestamp and move to title of list item
                if (!o.showTimestamp) {
                    tl.find("li").each(function () {
                        var timestampHTML = $(this).children("a");
                        var timestamp = timestampHTML.html();
                        timestampHTML.remove();
                        $(this).attr("title", timestamp);
                    });
                }

                // show twitter list
                if (o.slideIn) {
                    // a fix for the jQuery slide effect
                    // Hat-tip: http://blog.pengoworks.com/index.cfm/2009/4/21/Fixing-jQuerys-slideDown-effect-ie-Jumpy-Animation
                    var tlHeight = tl.data("originalHeight");

                    // get the original height
                    if (!tlHeight) {
                        tlHeight = tl.show().height();
                        tl.data("originalHeight", tlHeight);
                        tl.hide().css({ height: 0 });
                    }

                    tl.show().animate({ height: tlHeight }, o.slideDuration);
                }
                else {
                    tl.show();
                }

                // add unique class to first list item
                tl.find("li:first").addClass("firstTweet");

                // add unique class to last list item
                tl.find("li:last").addClass("lastTweet");
            });
        });
    };
})(jQuery);
