// WORK PROJECT MODAL //
var scrollPos;
$(function () {

    // Work pages
    swap();
    loadfacybox();

    //Load function for the individual Accordion items

    var tab = $(location).attr('href').split('#')[1];
    LoadTab(tab);

    $(".dwwork").find('a').click(function () {
        scrollPos = ($(this).offset().top);

        $('html, body').animate({ scrollTop: 0 }, 1);
        //alert(scrollPos);
    });
    //  $('html, body').animate({
    //     scrollTop: $(".sitefinitylogo").offset().top
    /// }, 2000);

    $('a.button').click(function (e) {


        var icurrent = $(this).attr('class');
        resetall();
        if (icurrent == 'button') {
            $(this).addClass('deselect');
            $(this).attr('href', $(this).attr('href').replace('GetWorkGroupAll.ashx', 'GetWorkGroup.ashx'));
        } else {
            $(this).attr('href', $(this).attr('href').replace('GetWorkGroup.ashx', 'GetWorkGroupAll.ashx'));
        }
        $.get($(this).attr('href'), function (data) {
            $('.dwwork').quicksand($(data).find('li'), { adjustHeight: 'auto' });
        });
        $("a.button").live("hover click", function () {
            swap();

        });
        $(".dwwork").live("hover", function () {
            swap();

        });
        $("a.button").bind("hover click", function () {
            swap();

        });
        e.preventDefault();
    });

    $(".toggle_container").hide();
    $(".trigger").click(function () {
        $(this).toggleClass("active").next().slideToggle("slow");
    });

    /* new changes --------------- */

    //work page  auto load
    var currentURL = '';
    var pageName = window.location.href;
    var autoURL = window.location.href.split("=")[1]; //'/work/2010-10-06/paypal-instructional-videos.aspx';
    //alert(window.location.href);


    //    //inject URL
    //    $(".dwwork li").find('a').click(function () {
    //        if (pageName.split('=')[1] == null) {
    //            window.location.href += '?url=' + $(this).attr('href');

    //        } else {
    //           // window.location.href = pageName.split('=')[0] + "=" + $(this).attr('href');
    //        }
    //    });

    $(".dwwork li").each(function (i) {
        currentURL = $(this).find('a').attr('href');
        if (autoURL == currentURL) {
            $(this).find('a').fancybox().trigger('click');
        }
    });

  
    // hide the hover layer

    $(".content-block").find('.fadeWrapper').stop().animate({ "opacity": "0" }, "fast");

    /* now implemented in ContentBlock.ascx inline
    $(".content-block").hover(
        function () {
            var selectedSlide = $('.content-images ul li').data('nivo:vars').currentSlide;
            var oLink = $(".content-images ul li a:eq(" + selectedSlide + ")").attr('href');
            $('.singleB').attr('href', oLink);
            $(this).find('.fadeWrapper').stop().animate({ "opacity": "1" }, "fast");
            $('.content-images ul li').data('nivoslider').stop();
        },
        function () {
            $('.singleB').attr('href', "javascript:void(0)");
            $(this).find('.fadeWrapper').stop().animate({ "opacity": "0" }, "fast");
            $('.content-images ul li').data('nivoslider').start();
        });
    */
});


function scrollBottom() {
    $('html, body').animate({ scrollTop: 60000 }, 'slow');
}


function resetall(ele) {
    $('.dwworklinks').find('a.deselect').removeClass('deselect');
}
// END WORK PROJECT MODAL //

// WORK HOVER //
function swap() {
    $(".swipe").hover(function () {
        $("img", this).fadeOut(400);
    }, function () {
        $("img", this).fadeIn(400);
    });
}

// END WORK HOVER //

jQuery(document).ready(function () {

    $(".content").find('.fadeWrapper_latestnav').stop().animate({ "opacity": "0" }, "fast");
    $(".content").find('.fadeWrapper_rightnav').stop().animate({ "opacity": "0" }, "fast");
//  $(".content").find('.rightHandColImg').stop().animate({ "opacity": "1" }, "fast");

    $(".content").mouseover(function () { $(this).find('.fadeWrapper_latestnav').stop().animate({ "opacity": "0.8" }, "fast"); });
    $(".content").mouseout(function () { $(this).find('.fadeWrapper_latestnav').stop().animate({ "opacity": "0" }, "fast"); });

    $(".content").mouseover(function () { $(this).find('.fadeWrapper_rightnav').stop().animate({ "opacity": "0.8" }, "fast"); });
    $(".content").mouseout(function () { $(this).find('.fadeWrapper_rightnav').stop().animate({ "opacity": "0" }, "fast"); });

   // $(".content").mouseover(function () { $(this).find('.rightHandColImg').stop().animate({ "opacity": "0.8" }, "fast"); });
   // $(".content").mouseout(function () { $(this).find('.rightHandColImg').stop().animate({ "opacity": "1" }, "fast"); });

    jQuery.extend
        ({
            'QueryString': window.location.search.length <= 1 ? new Array() :
                function (a) {
                    var b = new Array();
                    for (var i = 0; i < a.length; ++i) {
                        var p = a[i].split('=');
                        b[p[0]] = unescape(p[1]);
                    }
                    return b;
                } (window.location.search.substr(1).split('&'))
        });

    var urlLink = $.QueryString["url"];




    if (urlLink > "") {

        //alert('urlLink=' + urlLink);

        // urlLink = "/work/2010-10-06/paypal-mythbusters-microsite-and-digital-camp.aspx"

        $('a[href="' + urlLink + '"]').trigger('click');
    }
});


//menu animations
$(function () {


    // SUBSCRIBE
    $("li.subscribe").mouseover(function () {
        closeall();
        $(this).find('.sub').stop().animate({ height: '110px', opacity: '1' }, { queue: false, duration: 200, easing: 'jswing' })
    });

    $("li.subscribe").mouseout(function () {
        closeblock('li.subscribe');
    });

    $("li ul.subnav").mouseout(function () {
        closeblock('li.subscribe');
    });

    function closeblock(element) {
        $(element).find('.subnav').stop().animate({ height: '0px', opacity: '0' }, { queue: false, duration: 200, easing: 'jswing' })
    }

    // menu itembackground color animation			
    $("li.data").hover(function () {
        $(this).stop().animate({ backgroundColor: "#f2f2f2" }, 600);
    },
    function () {
        $(this).stop().animate({ backgroundColor: "#fff" }, 600);
    });

    // END SUBSCRIBE






    // SEARCH

    $("li.search").mouseover(function () {
        //closeall();
        $("li.subscribe").find('.subnav').stop().animate({ height: '0px', opacity: '0' }, { queue: false, duration: 200, easing: 'jswing' })
        $(this).find('.srch').stop().animate({ height: '30px', opacity: '1' }, { queue: false, duration: 200, easing: 'jswing' })
    });

    $("li ul.subnav").mouseout(function () {

        //closeblock('li.search');
    });

    // END SEARCH




    // Follow Us and Share menu animation
    $("ul.followeasing li.main").mouseover(function () {
        $(this).find('.followUs').stop().animate({ height: '110px', opacity: '1' }, { queue: false, duration: 200, easing: 'jswing' })

        $(this).find('.shareLinks').stop().animate({ height: '110px', opacity: '1' }, { queue: false, duration: 200, easing: 'jswing' })
    });


    // Filter jump to menu animation
    $("ul.filtereasing li.main").mouseover(function () {
        $(this).find('.jump2').stop().animate({ height: '200px', opacity: '1' }, { queue: false, duration: 200, easing: 'jswing' })

    });

    $("ul.filtereasing li.main").mouseout(function () {
        closeall();
    });

    // Archive jump to menu animation

    $("ul.archiveeasing li.main").ready(function () {
        $(this).find('.archive').hide();
    });



    $("ul.archiveeasing li.main").mouseover(function () {
        $(this).find('.archive').show();
        $(this).find('.jump2').stop().animate({ height: '88px', opacity: '1' }, { queue: false, duration: 200, easing: 'jswing' })

    });

    $("ul.archiveeasing li.main").mouseout(function () {
        $(this).find('.archive').hide();
        closeall();
    });







    $("li.linkfollow").mouseout(function () {
        closeall();
    });
    $("li.linkshare").mouseout(function () {
        closeall();
    });


});


// SEARCH DEFAULT VALUES //
function clickclear(thisfield, defaulttext) {
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
    }
}

function clickrecall(thisfield, defaulttext) {
    if (thisfield.value == "") {
        thisfield.value = defaulttext;
    }
}

// END SEARCH DEFAULT VALUES //

function closeall() {
    $("li.main").find('.subnav').stop().animate({ height: '0px', opacity: '0' }, { queue: false, duration: 200, easing: 'jswing' })
}

/* end menu animations */

// start of carousel //

$(function () {
    $('a').focus(function () { this.blur(); });
    SI.Files.stylizeAll();
    ////slider.init(); -- needs to run once all loaded

    $('input.text-default').each(function () {
        $(this).attr('default', $(this).val());
    }).focus(function () {
        if ($(this).val() == $(this).attr('default'))
            $(this).val('');
    }).blur(function () {
        if ($(this).val() == '')
            $(this).val($(this).attr('default'));
    });

    $('div.sc-large div.img:has(div.tml)').each(function () {
        $('div.tml', this).hide();
        $(this).append('<a href="#" class="tml_open">&nbsp;</a>').find('a').css({
            left: parseInt($(this).offset().left) + 864, top: parseInt($(this).offset().top) + 1
        }).click(function () {
            $(this).siblings('div.tml').slideToggle();
            return false;
        }).focus(function () { this.blur(); });
    });
});
var slider = {
    num: -1,
    cur: 0,
    cr: [],
    al: null,
    at: 10 * 1000,
    ar: true,
    init: function () {
        if (!slider.data || !slider.data.length)
            return false;

        var d = slider.data;
        slider.num = d.length;
        var pos = Math.floor(Math.random() * 1); //slider.num);
        for (var i = 0; i < slider.num; i++) {
            $('#' + d[i].id).css({ left: ((i - pos) * 1000) });
            $('#slide-nav').append('<a id="slide-link-' + i + '" href="#" onclick="slider.slide(' + i + ');return false;" onfocus="this.blur();"></a>');
        }

        $('img,div#slide-controls', $('div#slide-holder')).fadeIn();
        slider.text(d[pos]);
        slider.on(pos);
        slider.cur = pos;
        window.setTimeout('slider.auto();', slider.at);
    },
    auto: function () {
        if (!slider.ar)
            return false;

        var next = slider.cur + 1;
        if (next >= slider.num) next = 0;
        slider.slide(next);
    },
    slide: function (pos) {
        if (pos < 0 || pos >= slider.num || pos == slider.cur)
            return;

        window.clearTimeout(slider.al);
        slider.al = window.setTimeout('slider.auto();', slider.at);

        var d = slider.data;
        for (var i = 0; i < slider.num; i++)
            $('#' + d[i].id).stop().animate({ left: ((i - pos) * 1000) }, 1000, 'swing');

        slider.on(pos);
        slider.text(d[pos]);
        slider.cur = pos;
    },
    on: function (pos) {
        $('#slide-nav a').removeClass('on');
        $('#slide-nav a#slide-link-' + pos).addClass('on');
    },
    text: function (di) {
        slider.cr['a'] = di.client;
        slider.cr['b'] = di.desc;
        slider.ticker('#slide-client span', di.client, 0, 'a');
        slider.ticker('#slide-desc', di.desc, 0, 'b');
    },
    ticker: function (el, text, pos, unique) {
        if (slider.cr[unique] != text)
            return false;

        ctext = text.substring(0, pos) + (pos % 2 ? '-' : '_');
        $(el).html(ctext);

        if (pos == text.length)
            $(el).html(text);
        else
            window.setTimeout('slider.ticker("' + el + '","' + text + '",' + (pos + 1) + ',"' + unique + '");', 30);
    }
};
// STYLING FILE INPUTS 1.0 | Shaun Inman <http://www.shauninman.com/> | 2007-09-07
if (!window.SI) { var SI = {}; };
SI.Files = {
    htmlClass: 'SI-FILES-STYLIZED',
    fileClass: 'file',
    wrapClass: 'cabinet',

    fini: false,
    able: false,
    init: function () {
        this.fini = true;
    },
    stylize: function (elem) {
        if (!this.fini) { this.init(); };
        if (!this.able) { return; };

        elem.parentNode.file = elem;
        elem.parentNode.onmousemove = function (e) {
            if (typeof e == 'undefined') e = window.event;
            if (typeof e.pageY == 'undefined' && typeof e.clientX == 'number' && document.documentElement) {
                e.pageX = e.clientX + document.documentElement.scrollLeft;
                e.pageY = e.clientY + document.documentElement.scrollTop;
            };
            var ox = oy = 0;
            var elem = this;
            if (elem.offsetParent) {
                ox = elem.offsetLeft;
                oy = elem.offsetTop;
                while (elem = elem.offsetParent) {
                    ox += elem.offsetLeft;
                    oy += elem.offsetTop;
                };
            };
        };
    },
    stylizeAll: function () {
        if (!this.fini) { this.init(); };
        if (!this.able) { return; };
    }
};

// End of carousel //

//newsletter requests
$(function () {
    $("#lnkSend").click(function () {
        //alert('fff');

        if ($("#txtEmail").val() == '' && validate($("#txtEmail").val())) {
            //TODO : message box
            $("#subsribeMessage").fadeIn();
            $("#subsribeMessage").html("Please enter email");
            return false;
        }

        if ($("#txtName").val() == '') {
            //TODO : message box
            $("#subsribeMessage").fadeIn();
            $("#subsribeMessage").html("Please enter name");
            return false;
        }
        if ($("#txtName").val() != '' && $("#txtEmail").val() != '') {
            $.ajax({
                type: "POST",
                url: "/Services/Newsletter/RegisterNewsletter.asmx/SubscribeToNewsletter",
                data: "{'email': '" + $("#txtEmail").val() + "', 'fname': '" + $("#txtName").val() + "','lname': '" + $("#txtName").val() + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    //TODO: Completed message
                    $("#subsribeMessage").fadeIn();
                    //   $("#subsribeMessage").html("Thank you for your submission.");

                },
                error: ajaxFailed
            });
        }
    });

});
function validate(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = email;
    if (reg.test(address) == false) {
        $("#subsribeMessage").html("Please enter valid email");
        return false;
    }
}

function ajaxFailed() {
    //TODO: Error message
    $("#subsribeMessage").fadeIn();
    $("#subsribeMessage").html("Error occurred");
    return false;
}
// Work section
/*

Quicksand 1.2.1

Reorder and filter items with a nice shuffling animation.

Copyright (c) 2010 Jacek Galanciak (razorjack.net) and agilope.com
Big thanks for Piotr Petrus (riddle.pl) for deep code review and wonderful docs & demos.

Dual licensed under the MIT and GPL version 2 licenses.
http://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt
http://github.com/jquery/jquery/blob/master/GPL-LICENSE.txt

Project site: http://razorjack.net/quicksand
Github site: http://github.com/razorjack/quicksand

*/

(function ($) {
    $.fn.quicksand = function (collection, customOptions) {
        var options = {
            duration: 750,
            easing: 'swing',
            attribute: 'data-id', // attribute to recognize same items within source and dest
            adjustHeight: 'false', // 'dynamic' animates height during shuffling (slow), 'auto' adjusts it before or after the animation, false leaves height constant
            useScaling: false, // disable it if you're not using scaling effect or want to improve performance
            enhancement: function (c) { }, // Visual enhacement (eg. font replacement) function for cloned elements
            selector: '> *'
        };
        $.extend(options, customOptions);

        //  if ($.browser.msie || (typeof ($.fn.scale) == 'undefined')) {
        //      // Got IE and want scaling effect? Kiss my ass.
        //      options.useScaling = false;
        //  }

        var callbackFunction;
        if (typeof (arguments[1]) == 'function') {
            var callbackFunction = arguments[1];
        } else if (typeof (arguments[2] == 'function')) {
            var callbackFunction = arguments[2];
        }


        return this.each(function (i) {
            var val;
            var animationQueue = []; // used to store all the animation params before starting the animation; solves initial animation slowdowns
            var $collection = $(collection).clone(); // destination (target) collection
            var $sourceParent = $(this); // source, the visible container of source collection
            var sourceHeight = $(this).css('height'); // used to keep height and document flow during the animation

            var destHeight;
            var adjustHeightOnCallback = false;

            var offset = $($sourceParent).offset(); // offset of visible container, used in animation calculations
            var offsets = []; // coordinates of every source collection item            

            var $source = $(this).find(options.selector); // source collection items

            // Replace the collection and quit if IE6
            //    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
            //        $sourceParent.html('').append($collection);
            //        return;
            //    }

            // Gets called when any animation is finished
            var postCallbackPerformed = 0; // prevents the function from being called more than one time
            var postCallback = function () {
                if (!postCallbackPerformed) {
                    $sourceParent.html($dest.html()); // put target HTML into visible source container        
                    if (typeof callbackFunction == 'function') {
                        callbackFunction.call(this);
                    }
                    if (adjustHeightOnCallback) {
                        $sourceParent.css('height', destHeight);
                    }
                    options.enhancement($sourceParent); // Perform custom visual enhancements on a newly replaced collection
                    postCallbackPerformed = 1;
                }
            };

            // Position: relative situations
            var $correctionParent = $sourceParent.offsetParent();


            var correctionOffset = $correctionParent.offset();
            if ($correctionParent.css('position') == 'relative') {


                if ($correctionParent.get(0).nodeName.toLowerCase() == 'body') {

                } else {
                    correctionOffset.top += parseFloat($correctionParent.css('border-top-width'));
                    correctionOffset.left += parseFloat($correctionParent.css('border-left-width'));
                }
            } else {
                // ie bug fix commented out
                // correctionOffset.top -= 0; //parseFloat($correctionParent.css('border-top-width'));
                // correctionOffset.left -= 0; //parseFloat($correctionParent.css('border-left-width'));
                correctionOffset.top -= parseFloat($correctionParent.css('margin-top'));
                correctionOffset.left -= parseFloat($correctionParent.css('margin-left'));
            }


            // keeps nodes after source container, holding their position
            $sourceParent.css('height', $(this).height());


            // get positions of source collections
            $source.each(function (i) {
                offsets[i] = $(this).offset();
            });

            // stops previous animations on source container
            $(this).stop();
            $source.each(function (i) {
                $(this).stop(); // stop animation of collection items
                var rawObj = $(this).get(0);

                rawObj.style.position = 'absolute';
                rawObj.style.margin = '0';

                //  if (!($.browser.msie)){ //ie bug comment //
                rawObj.style.top = (offsets[i].top - parseFloat(rawObj.style.marginTop) - correctionOffset.top) + 'px';
                rawObj.style.left = (offsets[i].left - parseFloat(rawObj.style.marginLeft) - correctionOffset.left) + 'px';
                //    }
            });

            // create temporary container with destination collection
            var $dest = $($sourceParent).clone();
            var rawDest = $dest.get(0);
            rawDest.innerHTML = '';
            rawDest.setAttribute('id', '');
            rawDest.style.height = 'auto';
            rawDest.style.width = $sourceParent.width() + 'px';
            $dest.append($collection);
            // insert node into HTML
            // Note that the node is under visible source container in the exactly same position
            // The browser render all the items without showing them (opacity: 0.0)
            // No offset calculations are needed, the browser just extracts position from underlayered destination items
            // and sets animation to destination positions.
            $dest.insertBefore($sourceParent);
            $dest.css('opacity', 0.0);
            rawDest.style.zIndex = -1;

            rawDest.style.margin = '0';
            rawDest.style.position = 'absolute';


            // if (!($.browser.msie)){ //ie bug comment //
            rawDest.style.top = offset.top - correctionOffset.top + 'px';
            rawDest.style.left = offset.left - correctionOffset.left + 'px';
            // }

            if (options.adjustHeight === 'dynamic') {
                // If destination container has different height than source container
                // the height can be animated, adjusting it to destination height
                $sourceParent.animate({ height: $dest.height() }, options.duration, options.easing);
            } else if (options.adjustHeight === 'auto') {
                destHeight = $dest.height();
                if (parseFloat(sourceHeight) < parseFloat(destHeight)) {
                    // Adjust the height now so that the items don't move out of the container
                    $sourceParent.css('height', destHeight);
                } else {
                    //  Adjust later, on callback
                    adjustHeightOnCallback = true;
                }
            }

            // Now it's time to do shuffling animation
            // First of all, we need to identify same elements within source and destination collections    
            $source.each(function (i) {
                var destElement = [];
                if (typeof (options.attribute) == 'function') {

                    val = options.attribute($(this));
                    $collection.each(function () {
                        if (options.attribute(this) == val) {
                            destElement = $(this);
                            return false;
                        }
                    });
                } else {
                    destElement = $collection.filter('[' + options.attribute + '=' + $(this).attr(options.attribute) + ']');
                }
                if (destElement.length) {
                    // The item is both in source and destination collections
                    // It it's under different position, let's move it
                    if (!options.useScaling) {
                        animationQueue.push(
                                            {
                                                element: $(this),
                                                animation:
                                                    { top: destElement.offset().top - correctionOffset.top,
                                                        left: destElement.offset().left - correctionOffset.left,
                                                        opacity: 1.0
                                                    }
                                            });

                    } else {
                        animationQueue.push({
                            element: $(this),
                            animation: { top: destElement.offset().top - correctionOffset.top,
                                left: destElement.offset().left - correctionOffset.left,
                                opacity: 1.0,
                                scale: '1.0'
                            }
                        });

                    }
                } else {
                    // The item from source collection is not present in destination collections
                    // Let's remove it
                    if (!options.useScaling) {
                        animationQueue.push({ element: $(this),
                            animation: { opacity: '0.0' }
                        });
                    } else {
                        animationQueue.push({ element: $(this), animation: { opacity: '0.0',
                            scale: '0.0'
                        }
                        });
                    }
                }
            });

            $collection.each(function (i) {
                // Grab all items from target collection not present in visible source collection

                var sourceElement = [];
                var destElement = [];
                if (typeof (options.attribute) == 'function') {
                    val = options.attribute($(this));
                    $source.each(function () {
                        if (options.attribute(this) == val) {
                            sourceElement = $(this);
                            return false;
                        }
                    });

                    $collection.each(function () {
                        if (options.attribute(this) == val) {
                            destElement = $(this);
                            return false;
                        }
                    });
                } else {
                    sourceElement = $source.filter('[' + options.attribute + '=' + $(this).attr(options.attribute) + ']');
                    destElement = $collection.filter('[' + options.attribute + '=' + $(this).attr(options.attribute) + ']');
                }

                var animationOptions;
                if (sourceElement.length === 0) {
                    // No such element in source collection...
                    if (!options.useScaling) {
                        animationOptions = {
                            opacity: '1.0'
                        };
                    } else {
                        animationOptions = {
                            opacity: '1.0',
                            scale: '1.0'
                        };
                    }
                    // Let's create it
                    d = destElement.clone();
                    var rawDestElement = d.get(0);
                    rawDestElement.style.position = 'absolute';
                    rawDestElement.style.margin = '0';


                    //   if (!($.browser.msie)){ //ie bug comment //
                    rawDestElement.style.top = destElement.offset().top - correctionOffset.top + 'px';
                    rawDestElement.style.left = destElement.offset().left - correctionOffset.left + 'px';
                    //   }



                    d.css('opacity', 0.0); // IE
                    if (options.useScaling) {
                        d.css('transform', 'scale(0.0)');
                    }
                    d.appendTo($sourceParent);

                    animationQueue.push({ element: $(d),
                        animation: animationOptions
                    });
                }
            });

            $dest.remove();
            options.enhancement($sourceParent); // Perform custom visual enhancements during the animation
            for (i = 0; i < animationQueue.length; i++) {
                animationQueue[i].element.animate(animationQueue[i].animation, options.duration, options.easing, postCallback);
            }
        });
    };
})(jQuery);

// Common functions //
function showentry(start, end, link) {
    $('.entry').each(function (intIndex) {
        if (intIndex >= start && intIndex <= end) {
            $(this).fadeIn('slow');
            //$(this).find('a').hide();
        }
        //$(this).find('a').hide();

    });
    // alert($(this).val());
    $('.' + link).hide();
}

function hideme() {
    var DEFAULT_LOGO_CSSCLASS = "poweredBySitefinityLogo";
    var nodeList = document.getElementsByTagName("p")

    var defaultPoweredByLogo = null;

    for (i = 0; i < nodeList.length; i++) {
        if (nodeList[i].getAttribute("class") == DEFAULT_LOGO_CSSCLASS ||
            nodeList[i].getAttribute("className") == DEFAULT_LOGO_CSSCLASS) {
            defaultPoweredByLogo = nodeList[i];
            break;
        }
    }

    if (defaultPoweredByLogo != null) {
        var filler = document.createElement("span");
        filler.style.display = "none";

        var parent = defaultPoweredByLogo.parentNode;
        parent.replaceChild(filler, defaultPoweredByLogo);
    }

}
// end common functions //


//Work Page Animations
function loadfacybox() {
    $(".projectModal").fancybox(
		    {
		        'scrolling': 'no',
		        'autoscale': true,
		        'transitionIn': 'fade',
		        'overlayOpacity': 0.9,
		        'overlayColor': '#FFF',
		        'centerOnScroll': false,
		        'transitionOut': 'fade',
		        'onClosed': rescroll

		    });
}

function rescroll() {
    swap();
    $("a.button").bind("hover click", function () {
        swap();

    });
    $('html, body').animate({ scrollTop: scrollPos - 250 }, 1000);

}

$(document).ready(function () {
    $("#internalAppsRotator").easySlider({ continuous: true, prevText: '', nextText: '', auto: true, horizontal: true, speed: 3000, controlsShow: false
    });
});

//CLIENT AREA//

$(function () {
    $("#Password").keydown(function (event) {
        if (event.which || event.keyCode) { if ((event.which == 13) || (event.keyCode == 13)) { Login(); } } else { return true }
    });
});

function Login() {
    var u = $('#Email').val();
    var p = $('#Password').val();
    //show image
    $("#limg1").show();
    PageMethods.Login(u, p, OnCall, OnError);
}

function OnCall(result) {
    //hide image 
    $("#limg1").hide();
    if (result) {
        window.location.href = "/work.aspx";
    }
    else {
        OnError();
        $("#limg1").hide();
    }
}

function OnError() {
    $("#msgLogin").fadeOut('fast');
    $("#msgError").fadeIn();
}

function loginBack() {
    $("#msgError").fadeOut('fast');
    $("#msgLogin").fadeIn();
}

function Request() {
    $("#msgLogin").fadeOut('fast');
    $("#msgNew").fadeIn();
}

function SendRequest() {
    var n = $('#reqName').val();
    var e = $('#reqEmail').val();

    if (isEmail(e)) {
        //call web method
        //show image
        $("#limg2").show();
        PageMethods.SendRequest(n, e, OnRequestCall, OnRequestError);

    }
    else {
        OnRequestError();
    }
}

function ForgotPassword() {
    //  $("#msgLogin").fadeOut('fast');
    //$("#msgForgot").fadeIn();
}

function Cancel() {
    $("#msgLogin").fadeOut('fast');
    $("#loginContainer").fadeOut('fast');
}



function OnRequestCall(result) {
    //hide image 
    $("#limg2").hide();
    if (result) {
        $("#msgThanks").fadeIn();
    }
    else {
        OnRequestError();
        $("#limg2").hide();
    }
}

function OnRequestError() {
    $("#msgNew").fadeOut('fast');
    $("#msgErrorReq").fadeIn();
}

function loginBackReq() {
    $("#msgErrorReq").fadeOut('fast');
    $("#msgNew").fadeIn();
}

function isEmail(email) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(email);
};


$(window).load(function () {
    slider.init();
    $('#eventslideshow').nivoSlider({ effect: 'fade', controlNav: false, directionNav: false, pauseTime: 5000 });

    /* home page content blocks */
    var total = $('.content-images ul li img').length;
    var rand = Math.floor(Math.random() * total);
    $('.content-images ul li').nivoSlider({ effect: 'fade', controlNav: false, directionNav: false, pauseTime: 3000, pauseOnHover: true, startSlide: rand });
});

function LoadTab(tab) {

    if (tab != null) {
        $(".trigger").each(function () {
            $(this).next().hide();
            $(this).removeClass('active');
        });
        var target = $("#" + tab).position();
        $("#" + tab).addClass('active');
        $('html, body').animate({ scrollTop: target.top - 155 }, 1500);
        setTimeout(function () {
            $("#" + tab).next().slideToggle("slow");
        }, 1500);
    }
}

