$(document).ready(function () {

    //*********************************************************************
    //Homepage Banner Rotator
    //*********************************************************************
    if ($('.feat_banner').length > 0) {
        $('.feat_banner .banner').hide();
        $('.feat_banner .banner:first').fadeIn('slow');
        $('.feat_banner li a').append('<span></span>');
        $('.feat_banner li:first').addClass('active');

        rotate = function () {
            var bannerID = active.find('a').attr('rel');
            $('.banner').fadeOut('slow');
            $('#banner' + bannerID).fadeIn('slow').appendTo('#featured');
            $('.feat_banner li').removeClass('active'); //Remove all active class
            active.addClass('active');
        };

        rotateSwitch = function () {
            play = setInterval(function () {
                active = $('.feat_banner li.active').next();
                if (active.length === 0) {
                    active = $('.feat_banner li:first');
                }
                rotate();
            }, 3000);
        };

        $('.feat_banner li').click(function () {
            clearInterval(play); //Stop the rotation
            active = $(this); //Activate the clicked paging
            rotate();
            rotateSwitch(); //Resume rotation timer
            return false;
        });



        $(window).load(function () {
            rotateSwitch(); //Run function on launch
        });
    }

    //*********************************************************************
    //MISC
    //*********************************************************************
    //Dynamic Vertical + Horizontal Centering for Popups
    $.fn.absCenter = function () {
        $(this).css({
            marginLeft: -($(this).width() / 2),
            marginTop: -($(this).height() / 2)
        }).fadeIn();
        $.ajax({
            url: "http://s7.addthis.com/js/250/addthis_widget.js#domready=1",
            dataType: "script",
            cache: false,
            success: function () {
                if (typeof (window.addthis) != 'undefined' && typeof (window.addthis.ready) != 'undefined') {
                    window.addthis.ost = 0;
                    window.addthis.ready();
                }
            }
        });
        return $(this);
    }
    if ($('.abscenter').length) {
        $('.abscenter').absCenter();
    }


    //close popup then remove markup
    $('a.closepop').live('click', function () {
        $(this).parent().parent().fadeOut(function () {
            $(this).remove();
        });
    });

    //Kill auto complete for chrome/safari (yellow box)
    if ($.browser.webkit) {
        $('form').attr({
            autocomplete: 'off'
        });
    }

    //Anchor Scroll
    $('a[rel=scrollTop]').live('click', function () {
        var scrollVal = $($(this).attr('href')).offset();
        $("html, body").animate({
            scrollTop: scrollVal.top
        }, {
            duration: "slow",
            easing: "easeInOutExpo"
        });
        return false;
    });

    //Fix dotted line on sidecolumn
    $('.section:last-child').css({
        'margin-bottom': '5px'
    });


    //Fix even columns for IE
    $('.sidecol .forum_disc ul li:nth-child(even), .sidecol .categories ul li:nth-child(even)').addClass('evenlist');

    //Ditch last divider on topnav
    //$('ul.topnav li:last-child').css({'background' : 'none'});
    //Input Hints
    $('input[type=text], input[type=password], textarea#comment').live('focus', function () {

        if ($(this).attr('type') === 'password') {
            $('label.pw').hide();
        } else if (this.value === this.defaultValue && $(this).attr('name')=='user') {
            $(this).attr({
                value: ''
            });
        }
        $(this).addClass('focused');
    }).live('blur', function () {
        if (this.value === '') {
            if ($(this).attr('type') === 'password') {
                $('label.pw').show();
            }
            if ($(this).attr('name')=='user') {
                this.value = this.defaultValue;
            }
            $(this).removeClass('focused');
        }

    }).mousemove(function () {
        if ($('input[type=password]').attr('value') != '') {
            $('label.pw').hide();
        }
    });

    if ($('input[type=password]').attr('value') != '') {
        $('label.pw').hide();
    }

    $('label.pw').click(function () {
        $(this).hide();
        $(this).next('input[type=password]').focus();
    });

    //Convert Youtube link to embed src
    if ($('#youtubeembed iframe').length) {
        mediaSrc = $('#youtubeembed iframe').attr('rel');

        if (mediaSrc) {
          try {
            $('#youtubeembed').flash({
                swf: 'http://www.youtube.com/v/' + mediaSrc + '?fs=1&amp;hl=en_US&amp;rel=0&showinfo=0&color1=0x453b32&color2=0x453B32&wmode=transparent',
                height: 385,
                width: 640,
                wmode: 'transparent',
                allowFullScreen: true
            });
          } catch (e) {
          }
        }
    }

    //Lang Select
    $('a.target').toggle(function () {
        $('#language').animate({
            marginTop: 0
        }, {
            duration: "slow",
            easing: "easeInOutExpo"
        });
    }, function () {
        $('#language').animate({
            marginTop: -51
        }, {
            duration: "slow",
            easing: "easeInOutExpo"
        });
    });

    var cookieName = 'Language';
    var cookieOptions = {
        expires: 365,
        path: '/',
        domain: soap_CookieDomain
    };

    try {
      if ($.cookie(cookieName) === null) {
          $('a[rel="en_US"]').addClass("selected");
      } else {
          var SubName = jQuery.cookie(cookieName).substring(3);
          $('a.target').text(SubName);
          var SubName = jQuery.cookie(cookieName).substring(3);
          $("img[rel='" + jQuery.cookie(cookieName) + "'], a[rel='" + jQuery.cookie(cookieName) + "'] img, img[rel='" + SubName + "'], a[rel='" + SubName + "'] img").addClass("selected");
      }
    } catch (e) {

    }

    $(".select_lang a[rel]").click(function () {
        if ($(this).attr("rel") != jQuery.cookie(cookieName)) {
            $("#" + $.cookie(cookieName)).removeClass("selected");
            $.cookie(cookieName, $(this).attr("rel"), cookieOptions);
            $.cookie('R3AgeGate', '0', cookieOptions);
            $("#" + $.cookie(cookieName)).addClass("selected");
            location.reload();
        }
        return false;
    });

    //Age gate numbers only script
    jQuery.fn.ForceNumericOnly =

    function () {
        return this.each(function () {
            $(this).keydown(function (e) {
                var key = e.charCode || e.keyCode || 0;
                // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
                return (
                key == 8 || key == 9 || key == 46 || (key >= 37 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105));
            })
        })
    };
    $("input.age").ForceNumericOnly();

    //Even lists
    $('.sidecol .forum_disc ul li:nth-child(even)').addClass('evenlist');



    /****************************************************************
     #Carousel
     ****************************************************************/
    //set detfaul carousel state
    sum = 0;

    /////Carousel Function + Smart Columns
    $.fn.carousel = function () {

        var rotatorLi = $(this).find("ul.rotator li").width();
        var rotatorSum = $(this).find("ul.rotator li").size();
        var carousel = $(".carousel").width();

        var rotatorMaxLi = Math.floor(carousel / rotatorLi);
        var rotatorSlideSum = Math.ceil(rotatorSum / rotatorMaxLi);

        var adjustLi = (carousel / rotatorMaxLi);
        var adjustRotator = (adjustLi * rotatorSum);

        var lastSlideSum = Math.floor(adjustRotator / carousel);
        var lastSlide = (carousel * lastSlideSum) - adjustRotator;

        $(this).find("ul.rotator li").css({
            'width': adjustLi
        });
        $(this).find("ul.rotator").css({
            'width': adjustRotator
        });

        if (rotatorSlideSum == 1) {
            $('a.left-scroll, a.right-scroll').addClass("deactive");
        }

        if (carousel < adjustRotator) { //If the list is bigger than the carousel viewport
            $(this).parent().find("a.right-scroll").click(function () {
                if (sum < (rotatorSlideSum - 1)) {
                    sum++;
                    $(this).parent().find("a.left-scroll").removeClass("deactive");
                    switch (sum) {
                    case rotatorSlideSum:
                        //on the last slide...
                        $(this).parent().addClass("deactive");
                        break;
                    case rotatorSlideSum - 1:
                        //second to last slide...
                        $(this).parent().find("a.right-scroll").addClass("deactive");
                        if (lastSlide < -1) {
                            $(this).parent().find("ul.rotator").animate({
                                marginLeft: "+=" + lastSlide
                            }, 250);
                        } else {
                            $(this).parent().find("ul.rotator").animate({
                                marginLeft: "-=" + carousel
                            }, 250);
                        }
                        break;
                    default:
                        //on click else
                        $(this).parent().find("ul.rotator").animate({
                            marginLeft: "-=" + carousel
                        }, 250);
                        break;
                    }
                    $(this).parent().find('.reelpaging').html('Page <span>' + (sum + 1) + '</span> of <span>' + rotatorSlideSum + '</span>');
                }
                return false;
            }); //end switch case
            $(this).parent().find("a.left-scroll").addClass("deactive");
            $(this).parent().find("a.left-scroll").click(function () {
                if (sum > 0) {
                    sum--;
                    $(this).parent().find("a.right-scroll").removeClass("deactive");
                    switch (sum) {
                    case 0:
                        //if back to original slide...
                        if (lastSlide < -1 && rotatorSlideSum === 2) {
                            $(this).parent().find("ul.rotator").animate({
                                marginLeft: "-=" + lastSlide
                            }, 250);
                        } else {
                            $(this).parent().find("ul.rotator").animate({
                                marginLeft: "+=" + carousel
                            }, 250);
                        }
                        $(this).parent().find("a.left-scroll").addClass("deactive");
                        break;
                    case rotatorSlideSum - 2:
                        //1st click back from the last slide...
                        if (lastSlide < -1) {
                            $(this).parent().find("ul.rotator").animate({
                                marginLeft: "-=" + lastSlide
                            }, 250);
                        } else {
                            $(this).parent().find("ul.rotator").animate({
                                marginLeft: "+=" + carousel
                            }, 250);
                        }
                        break;
                    default:
                        $(this).parent().find("ul.rotator").animate({
                            marginLeft: "+=" + carousel
                        }, 250);
                        break;
                    }
                    $(this).parent().find('.reelpaging').html(LangTXT['Page'] + ' <span>' + (sum + 1) + '</span> '+LangTXT['of']+' <span>' + rotatorSlideSum + '</span>');
                }
                return false;
            }); //end switch case
        } else { //if there is only one slide...
            $(this).find("a.right-scroll, a.left-scroll").addClass("deactive");
        } //end if carasouel statement
        $(this).parent().find('.reelpaging').html(LangTXT['Page'] + ' <span>' + (sum + 1) + '</span> '+LangTXT['of']+' <span>' + rotatorSlideSum + '</span>');
    }; //end function

    ////Trigger Carousel + Component Functions
    $('.carousel_placement').each(function () { //for each carousel run the following code...
        tabID = $(this).attr('id'); //get the ID of the tab content
        $('#' + tabID).find("div[class^='carousel']").carousel(); //run the carousel function on that ID
    });

    //GameChoice Active State
    if ($('.gamechoice').length) {
        $('.gamechoice a').each(function () {
            if ($(this).text() === $('h1').text()) {
                $(this).parent().addClass('active');
            }
        });
    }

    //Swap Thumb to preview
    if ($('.commentbox').length) {

        $('.loader').fadeIn();
        if ($('ul.rotator').length) {
            $this = $('ul.rotator li:first');
            $('ul.rotator li a').each(function () {
                videoID = $(this).attr('href');
                getPostID = $this.attr('value');
                mediaSrc = $(this).attr('href').replace('#', '');

                var VideoHash = window.location.hash;

                if ( VideoHash == '' ) {
                   VideoHash = "#" + getParameterByName('v');
                }

                //Does it have a deeplink hash ID?
                if (VideoHash != videoID || VideoHash == '') {
                    //nope

                } else {

                    $this = $('ul.rotator li a[href=' + VideoHash + ']').parent();
                    mediaSrc = VideoHash.replace('#', '');
                    getPostID = $this.attr('value');

                    //adjust carousel
                    var liNum = ($('ul.rotator').children().index($(this).parent())) + 1;
                    var liPerRow = ($('.carousel').width() / $('ul.rotator li').width());
                    var slideNum = (Math.ceil(liNum / liPerRow)) - 1;
                    var slideMove = ($('ul.rotator li').width() * liPerRow) * slideNum;
                    sum = slideNum;
                    slideMove = -slideMove;

                    //on first slide
                    if (sum > 0) {
                        $('a.left-scroll').removeClass('deactive');
                    }

                    //On the last slide
                    if (sum == Math.ceil($('ul.rotator li').size() / liPerRow) - 1) {
                        $('a.right-scroll').addClass('deactive');

                        //If it does not have a full slide
                        if (liPerRow < $('ul.rotator li').size()) {
                            var fullSize = $('ul.rotator li').width() * $('ul.rotator li').size();
                            var slideMove = -(fullSize - $('ul.rotator li').width() * liPerRow);
                        }
                    }
                    $('ul.rotator').css({
                        'marginLeft': slideMove
                    });
                    //end adjusting carousel placement
                }
            });

            $('ul.rotator li').removeClass('active');
            $this.addClass('active');
            $('.videodetail .detail').html($this.find('.detail').html());
            $('.videodetail h2').text($this.find(' h3').text());
            mediaSrc = $this.find('a').attr('href').replace('#', '');

        } else {
            getPostID = $('.post').attr('id');
            mediaSrc = false;
        }
        //Get Comments

        //Comment Ajax Function
        getWPComments = function () {
            randomized = Math.random() * 100000 + 1;
            $('#ajax-content').load(soap_LocalURL + 'wp-content/themes/Resistance3/getComments.php?postID=' + getPostID + '&rand=' + randomized, function (TextResponse) {
                if (TextResponse.length > 0 ) {
                  $(this).fadeIn().parent().css({
                    'height': $('#comments').height() + 40
                  });
                } else {
                  $(this).parent().fadeOut();
                }
                $('.loader').fadeOut();
            });
        }

        //Trigger comment function on load
        getWPComments();

        if (mediaSrc) {

            $('#youtubeembed iframe').attr({
                src: 'http://www.youtube.com/embed/' + mediaSrc + '?fs=1&amp;hl=en_US&amp;rel=0&showinfo=0&color1=0x453b32&color2=0x453B32&wmode=transparent'
            });

            $('#youtubeembed').show(function () {
                $.ajax({
                    url: soap_RemoteURL + "?action=PicShown&v=" + encodeURI(mediaSrc),
                    dataType: "jsonp",
                    cache: false,
                    success: function (data) {}
                });
            })
            try {
              $('#youtubeembed').flash({
                swf: 'http://www.youtube.com/v/' + mediaSrc + '?fs=1&amp;hl=en_US&amp;rel=0&showinfo=0&color1=0x453b32&color2=0x453B32&wmode=transparent',
                height: 385,
                width: 640,
                wmode: 'transparent',
                allowFullScreen: true
              });
            } catch (e) {
            }

            window.location.hash = '';
            var CurrLoc = window.location.href;
            var i = CurrLoc.indexOf('?');
            if ( i > 0 ) {
              CurrLoc = CurrLoc.substr(0, i);
            }
            CurrLoc = CurrLoc.replace('#', '');
            var ShareLoc = CurrLoc + '?v=' + mediaSrc;
            window.location.hash = mediaSrc;
            $('.sharethis').html('<div class="addthis_toolbox addthis_default_style "><iframe src="http://www.facebook.com/plugins/like.php?locale=' + soap_FBLang + '&amp;href=' + ShareLoc + '&amp;layout=standard&amp;show_faces=false&amp;width=270&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px; color: #fff;" allowTransparency="true"></iframe><a class="addthis_counter addthis_pill_style"  addthis:url="' + ShareLoc + '"></a></div>');
            $.ajax({
                url: "http://s7.addthis.com/js/250/addthis_widget.js#domready=1",
                dataType: "script",
                cache: false,
                success: function () {
                    if (window.addthis) {
                        window.addthis.ost = 0;
                        window.addthis.ready();
                    }
                }
            });

            $('ul.rotator li').click(function () {
                $('ul.rotator li').removeClass('active');
                $(this).addClass('active');
                mediaSrc = $(this).find('a').attr('href').replace('#', '');
                if ( mediaSrc == '' ) {
                    mediaSrc = getParameterByName('v');
                }

                if (mediaSrc) {
                    $('#youtubeembed').show();

                    try {
                      $('#youtubeembed').flash({
                        swf: 'http://www.youtube.com/v/' + mediaSrc + '?fs=1&amp;hl=en_US&amp;rel=0&showinfo=0&color1=0x453b32&color2=0x453B32&wmode=transparent',
                        height: 385,
                        width: 640,
                        wmode: 'transparent',
                        allowFullScreen: true
                      });
                    } catch (e) {
                    }

                    $('#youtubeembed iframe').attr({
                        src: 'http://www.youtube.com/embed/' + mediaSrc + '?fs=1&amp;hl=en_US&amp;rel=0&showinfo=0&color1=0x453b32&color2=0x453B32&wmode=transparent'
                    });
                    $('.videodetail .detail').html($(this).find('.detail').html());
                    $('.videodetail h2').text($(this).find(' h3').text());

                    window.location.hash = '';
                    var CurrLoc = window.location.href;
                    var i = CurrLoc.indexOf('?');
                    if ( i > 0 ) {
                      CurrLoc = CurrLoc.substr(0, i);
                    }
                    CurrLoc = CurrLoc.replace('#', '');
                    var ShareLoc = CurrLoc + '?v=' + mediaSrc;
                    window.location.hash = mediaSrc;

                    $('.sharethis').html('<div class="addthis_toolbox addthis_default_style "><iframe src="http://www.facebook.com/plugins/like.php?locale=' + soap_FBLang + '&amp;href=' + ShareLoc + '&amp;layout=standard&amp;show_faces=false&amp;width=270&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px; color: #fff;" allowTransparency="true"></iframe><a class="addthis_counter addthis_pill_style"  addthis:url="' + ShareLoc + '"></a></div>');
                    $.ajax({
                        url: "http://s7.addthis.com/js/250/addthis_widget.js#domready=1",
                        dataType: "script",
                        cache: false,
                        success: function () {
                            if (window.addthis) {
                                window.addthis.ost = 0;
                                window.addthis.ready();
                            }
                        }
                    });

                    getPostID = $(this).attr('value');
                    $('.loader').fadeIn();
                    $('#ajax-content').fadeOut(function () {
                        getWPComments();
                    });
                    $.ajax({
                        url: soap_RemoteURL + "?action=PicShown&v=" + encodeURI(mediaSrc),
                        dataType: "jsonp",
                        cache: false,
                        success: function (data) {}
                    });
                }
                return false;
            });
        }
    } //end if video page wp comments
    var reelHeight = $('.carousel_placement').height() - 4;
    var gameChoiceHeight = $('.gamechoice').height();
    if (reelHeight > gameChoiceHeight) {
        $('.gamechoice ul').css({
            'height': reelHeight
        });
    }

    //Publish Comment via ajax
    $('#commentform input#sub').live('click', function () {
        //Get the data from all the fields
        var formurl = $('#commentform').attr('action');
        var comment = $('textarea#comment').attr('value');
        var commentPostID = $('input[name=comment_post_ID]').attr('value');
        var getData = "comment=" + comment + "& comment_post_ID=" + commentPostID;
        $.ajax({
            type: "POST",
            data: getData,
            url: formurl,
            success: function () {
                getWPComments();
            }
        });
        return false;
    });

    //Flickr Call Function
    fetchFlickrSet = function () {
        randomized = Math.random() * 100000 + 1;
        $('.flickr').load(soap_LocalURL + 'wp-content/themes/Resistance3/getImageSets.php?setID=' + getSetID + '&rand=' + randomized, function () {
            $(this).fadeIn().parent().css({
                'height': $('.desc').height() + 40
            });
            $('.loader').fadeOut();

            //Prettyphoto
            $('.flickr a').prettyPhoto({
                callback: function () {
                    window.location.hash = '';

                },
                theme: 'dark_rounded',
                changepicturecallback: function () {
                    $('.pp_nav').find('.aux').remove();
                    var imageNameLocation = $('#fullResImage').attr('src');
                    imageDate = $('.flickr a[href="' + imageNameLocation + '"]').attr('title');
                    //Load addthis script

                    window.location.hash = '';
                    var CurrLoc = window.location.href;
                    var i = CurrLoc.indexOf('?');
                    if ( i > 0 ) {
                      CurrLoc = CurrLoc.substr(0, i);
                    }
                    CurrLoc = CurrLoc.replace('#', '');
                    var ShareLoc = CurrLoc + '?i=' + imageNameLocation;
                    window.location.hash = imageNameLocation;

                    $('.pp_description').html('<span class="addthis_toolbox addthis_default_style" style="position: absolute;"><iframe src="http://www.facebook.com/plugins/like.php?locale='+soap_FBLang+'&amp;href=' + ShareLoc + '&amp;layout=standard&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=arial&amp;colorscheme=dark&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:35px; color: #fff; float: left;" allowTransparency="true"></iframe><a class="addthis_counter addthis_pill_style" addthis:url="' + ShareLoc + '"></a></span>');
                    $('.pp_nav').append('<div class="aux"><p>&nbsp;&nbsp;|&nbsp;&nbsp;'+LangTXT['Added']+' <span class="date">' + imageDate + '</span>&nbsp;&nbsp;|&nbsp;&nbsp;&raquo; <a href="' + imageNameLocation + '" target="_blank">'+LangTXT['Download']+'</a></p></div>');
                    $.ajax({
                        url: "http://s7.addthis.com/js/250/addthis_widget.js#domready=1",
                        dataType: "script",
                        cache: false,
                        success: function () {
                            if (window.addthis) {
                                window.addthis.ost = 0;
                                window.addthis.ready();
                            }
                        }
                    });
                    $.ajax({
                        url: soap_RemoteURL + "?action=PicShown&i=" + encodeURI(imageNameLocation),
                        dataType: "jsonp",
                        cache: false,
                        success: function (data) {}
                    });
                }
            }).live('click', function () {
                var imageName = $(this).attr('href');
                window.location.hash = imageName;
                $(this).addClass('visited');
                return false;
            }); //end prettyPhoto
            deepLink = (window.location.hash).replace('#', '');
            if ( deepLink == '' ) {
              deepLink = getParameterByName('i');
            }
            if (deepLink !== '') {
                $.fn.prettyPhoto({
                    callback: function () {
                        window.location.hash = '';
                    },
                    theme: 'dark_rounded',
                    overlay_gallery: true,
                    changepicturecallback: function () {
                        $('.pp_nav').find('.aux').remove();
                        var imageNameLocation = $('#fullResImage').attr('src');

                        imageDate = $('.flickr a[href="' + imageNameLocation + '"]').attr('title');

                        window.location.hash = '';
                        var CurrLoc = window.location.href;
                        var i = CurrLoc.indexOf('?');
                        if ( i > 0 ) {
                          CurrLoc = CurrLoc.substr(0, i);
                        }
                        CurrLoc = CurrLoc.replace('#', '');
                        var ShareLoc = CurrLoc + '?i=' + imageNameLocation;
                        window.location.hash = imageNameLocation;

                        //Load addthis script
                        $('.pp_description').html('<span class="addthis_toolbox addthis_default_style" style="position: absolute;"><iframe src="http://www.facebook.com/plugins/like.php?locale='+soap_FBLang+'&amp;href=' + ShareLoc + '&amp;layout=standard&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=arial&amp;colorscheme=dark&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:35px; color: #fff; float: left;" allowTransparency="true"></iframe><a class="addthis_counter addthis_pill_style" addthis:url="' + ShareLoc + '"></a></span>');
                        $('.pp_nav').append('<div class="aux"><p>&nbsp;&nbsp;|&nbsp;&nbsp;'+LangTXT['Added']+' <span class="date">' + imageDate + '</span>&nbsp;&nbsp;|&nbsp;&nbsp;&raquo; <a href="' + imageNameLocation + '" target="_blank">'+LangTXT['Download']+'</a></p></div>');
                        $.ajax({
                            url: "http://s7.addthis.com/js/250/addthis_widget.js#domready=1",
                            dataType: "script",
                            cache: false,
                            success: function () {
                                if (window.addthis) {
                                    window.addthis.ost = 0;
                                    window.addthis.ready();
                                }
                            }
                        });
                        $.ajax({
                            url: soap_RemoteURL + "?action=PicShown&i=" + encodeURI(imageNameLocation),
                            dataType: "jsonp",
                            cache: false,
                            success: function (data) {}
                        });
                    }
                });
                $.prettyPhoto.open(deepLink, '', '');
            }

        });
        $('.flickr').attr('rel', getCatName);

    } //end flickr function
    //Get Flickr Sets via Ajax
    if ($('.single-ImageGallery').length) {
        //Check for query string
        if (getParameterByName('cat') === '') {
            thisSet = ':first';
            $('.imageset li' + thisSet).addClass('active');
        } else {
            $('.imageset li').each(function () {
                if ($(this).text().replace(/ /g, '') === getParameterByName('cat')) {
                    $(this).addClass('active');
                    thisSet = '.active';
                }
            });
        }
        getCatName = $('.imageset li' + thisSet).text();
        getSetID = $('.imageset li' + thisSet + ' a').attr('rel');

        //Get Flickr Image Sets
        fetchFlickrSet();

        $('.imageset a').click(function () {
            getSetID = $(this).attr('rel');
            getCatName = $(this).text();
            //Get Flickr Image Sets
            $('.loader').fadeIn();
            fetchFlickrSet();
            window.location = "?cat=" + getCatName;
            return false;
        });

    } //end flickr set
    //Get Query String function

    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null) return "";
        else return decodeURIComponent(results[1].replace(/\+/g, " "));
    }

    //Form Avatar select
    $(".avatarchoice img").click(function () {
        var name = $(this).attr("name");
        $(".avatarchoice img").each(function () {
            $(this).removeClass("selected");
        });
        $(this).addClass("selected");
        $("#AvatarSelector").val(name);
    });

});

