﻿var twitterQuery = "%40hardrock OR %23hrctt OR %23hrc2011";
var twitterNumResults = 25;

$(function () {
   

    $('input').keypress(function (e) {
        var code = null;
        code = (e.keyCode ? e.keyCode : e.which);

        if (code == 13) {

            if ($(this).hasClass("txtLocationSearch")) {
                //$(".locationSubmitButton").click();
                return false;
            }


            if ($(this).hasClass("searchText")) {
                $(".searchButton").click();
                return true;
            }

            if ($(this).hasClass("txtEmail")) {
                $(".emailSubmitButton").click();
                return true;
            }

        }
        return (code == 13) ? false : true;
    });

    $(".twitterScroller .tweet").each(function () {
        var text = $(this).html();
        $(this).html(makeLink(text));
    });

});



function makeLink(text) // this REGEX converts http(s) links that are embedded in the tweet text into real hyperlinks.
{
    var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
    return text.replace(exp, "<a href=\"$1\" target=\"_blank\">$1</a>");
} 




//NOTE: common telerik control functions moved to master.js

function itemClicked_handler(sender, args) {
    //var oRotator2 = $find(rotatorMainID);
    //oRotator2.set_currentItemIndex(args.get_item().get_index());
    MainFindImg(sender, args);
}

function Main_OnClientItemShowing(oRotator1, args) {
    var oRotator2 = $find(rotatorThumbsID);
    var dir = Telerik.Web.UI.RotatorScrollDirection.Right;

    if (oRotator1.isScrollingLeft()) {
        var dir = Telerik.Web.UI.RotatorScrollDirection.Left;
    }

    oRotator2.showNext(dir);

    oRotator1.get_currentItem().removeCssClass("currentItem");
    fadeGlowOut();
}

var glowLoaded = false;

function Main_OnClientItemShown(oRotator1, args) { 
    //if (!glowLoaded) {
        //var curIndex = oRotator1.get_currentItem().get_index();
    //    loadGlow(curIndex, oRotator1);
    //}
    
    //$("li").removeClass("currentItem");
    oRotator1.get_currentItem().addCssClass("currentItem");

    loadGlow();
    glowLoaded = false;
    fadeGlowIn();    
}

function fadeGlowOut() {
    //$("#glowLeft").fadeOut();
    //$("#glowRight").fadeOut();
    $(".slideShowGlow").fadeOut();
}

function fadeGlowIn() {
    //$("#glowLeft").stop(true, true).fadeIn(700);
    // $("#glowRight").stop(true, true).fadeIn(700);
    $(".slideShowGlow").stop(true, true).fadeIn(700);
}

function loadGlow(curIndex, rotator) {
    //var glowColor = $(".mainImage:last").attr("glow");    
    var glowColor = $(".currentItem img").attr("glow");   
    //$("#glowLeft").fadeOut();
   // $("#glowRight").fadeOut(function () {
    $(".slideShowGlow").fadeOut(function () {
        $("#glowLeft img").attr("src", "images/features/homepage/glow_left_" + glowColor + ".jpg");
        $("#glowRight img").attr("src", "images/features/homepage/glow_right_" + glowColor + ".jpg");
    });
}

function MainFindImg(sender, args) {
    
    var mainRotator = $find(rotatorMainID);
    initRotator(mainRotator);
    var mainImg = mainRotator.get_currentItem().get_index();
    var thumbImg = args.get_item().get_index();
    var orgScrollDur = mainRotator.get_scrollDuration
    mainRotator.set_scrollDuration = 200;

    if (thumbImg > mainImg) {
        while (mainImg < thumbImg) {
            mainRotator.showNext(Telerik.Web.UI.RotatorScrollDirection.Left);
            mainImg++;
        }
    }
    else {
        while (mainImg > thumbImg) {
            mainRotator.showNext(Telerik.Web.UI.RotatorScrollDirection.Right);
            mainImg--;
        }
    }
    
    mainRotator.set_scrollDuration = orgScrollDur;
}
