var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var op  = (navigator.appName.indexOf("Opera") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);

if (ie && win) {    pluginlist = detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash"); }

if (ns || op || !win) {
        nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
        pluginlist = detectNS("application/x-shockwave-flash","Shockwave Flash") ;
}

function detectIE(ClassID,name) { result = false; if (result) return name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);





/*ps_jquery.timer_js*/
 

jQuery.fn.extend({
    everyTime: function(interval, label, fn, times, belay) {
        return this.each(function() {
            jQuery.timer.add(this, interval, label, fn, times, belay);
        });
    },
    oneTime: function(interval, label, fn) {
        return this.each(function() {
            jQuery.timer.add(this, interval, label, fn, 1);
        });
    },
    stopTime: function(label, fn) {
        return this.each(function() {
            jQuery.timer.remove(this, label, fn);
        });
    }
});

jQuery.event.special

jQuery.extend({
    timer: {
        global: [],
        guid: 1,
        dataKey: "jQuery.timer",
        regex: /^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,
        powers: {
            // Yeah this is major overkill...
            'ms': 1,
            'cs': 10,
            'ds': 100,
            's': 1000,
            'das': 10000,
            'hs': 100000,
            'ks': 1000000
        },
        timeParse: function(value) {
            if (value == undefined || value == null)
                return null;
            var result = this.regex.exec(jQuery.trim(value.toString()));
            if (result[2]) {
                var num = parseFloat(result[1]);
                var mult = this.powers[result[2]] || 1;
                return num * mult;
            } else {
                return value;
            }
        },
        add: function(element, interval, label, fn, times, belay) {
            var counter = 0;
            
            if (jQuery.isFunction(label)) {
                if (!times) 
                    times = fn;
                fn = label;
                label = interval;
            }
            
            interval = jQuery.timer.timeParse(interval);

            if (typeof interval != 'number' || isNaN(interval) || interval <= 0)
                return;

            if (times && times.constructor != Number) {
                belay = !!times;
                times = 0;
            }
            
            times = times || 0;
            belay = belay || false;
            
            var timers = jQuery.data(element, this.dataKey) || jQuery.data(element, this.dataKey, {});
            
            if (!timers[label])
                timers[label] = {};
            
            fn.timerID = fn.timerID || this.guid++;
            
            var handler = function() {
                if (belay && this.inProgress) 
                    return;
                this.inProgress = true;
                if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
                    jQuery.timer.remove(element, label, fn);
                this.inProgress = false;
            };
            
            handler.timerID = fn.timerID;
            
            if (!timers[label][fn.timerID])
                timers[label][fn.timerID] = window.setInterval(handler,interval);
            
            this.global.push( element );
            
        },
        remove: function(element, label, fn) {
            var timers = jQuery.data(element, this.dataKey), ret;
            
            if ( timers ) {
                
                if (!label) {
                    for ( label in timers )
                        this.remove(element, label, fn);
                } else if ( timers[label] ) {
                    if ( fn ) {
                        if ( fn.timerID ) {
                            window.clearInterval(timers[label][fn.timerID]);
                            delete timers[label][fn.timerID];
                        }
                    } else {
                        for ( var fn in timers[label] ) {
                            window.clearInterval(timers[label][fn]);
                            delete timers[label][fn];
                        }
                    }
                    
                    for ( ret in timers[label] ) break;
                    if ( !ret ) {
                        ret = null;
                        delete timers[label];
                    }
                }
                
                for ( ret in timers ) break;
                if ( !ret ) 
                    jQuery.removeData(element, this.dataKey);
            }
        }
    }
});

jQuery(window).bind("unload", function() {
    jQuery.each(jQuery.timer.global, function(index, item) {
        jQuery.timer.remove(item);
    });
});

/*ps_jquery.timer_js*/

var isExpanded=false;

// Modf for jQuery Slider
if((pluginlist.indexOf("Flash")!=-1)||((bIsPS3.toString()=="false")||(bIsIE.toString()=="false")))
{
    if($('#marquee').length > 0) {
        
        var controlsPosition = 252;
        if($('#home').length > 0) {
            controlsPosition = 349;
        }
        
        var flashvars = {
            data_path: ""+ucmWebRoot+"groups/public/documents/webcontent/sps_home_marquee_data.xml",
            controls_position: controlsPosition
        };
        var params = {
            menu: "false",
            wmode: "transparent",
            scale: "noscale"
        };
        var attributes = {
            id: "marquee",
            name: "marquee"
        };

        swfobject.embedSWF(ucmWebRoot+"groups/public/documents/webasset/sps_home_marquee.swf", "marquee", "1160", "600", 
"9.0.0",""+ucmWebRoot+"groups/public/documents/webasset/sps_home_marquee.swf", flashvars, params, attributes);
        
    }
}
// Modf for jQuery Slider - End
// ASR
$(document).ready(function(){
var mainPath = location.pathname ;

 



var bPS3AccessaryPath = mainPath.toLowerCase().indexOf('ps3/accessories/scph-98048') != -1;
if(bPS3AccessaryPath.toString()=="true")
{
$("ul.accessory li:first").css("background","none");
}

var bIsIE = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
var bIsPS3 = navigator.userAgent.toLowerCase().indexOf('playstation') != -1;
var sAssetsPath = ucmroot+"groups/public/documents/webasset/"; /*getAssetPath(); */

if (bIsPS3.toString()=="true"){
	$('#profile').css('display', 'none');
}

if((pluginlist.indexOf("Flash")<0)||(bIsPS3.toString()=="true")|| (bIsIE.toString()=="true")){
// need to add condition here

var bPath = location.pathname ;

var xmlMarqueeFile = sAssetsPath+"sps_home_marquee_images_ss.xml";
var bPSPPath = bPath.toLowerCase().indexOf('psp') != -1;
var bPSPGMPath = bPath.toLowerCase().indexOf('psp/games-and-media') != -1;

var bPS3ACCPath = bPath.toLowerCase().indexOf('ps3/accessories') != -1;

var bPS3GMPath = bPath.toLowerCase().indexOf('ps3/games-and-media') != -1;
var bPSNPath = bPath.toLowerCase().indexOf('psn/playstation-store') != -1;
var bGamesMediaPath = bPath.toLowerCase().indexOf('games-and-media') != -1;
var bGamesMediagamesPath = bPath.toLowerCase().indexOf('games-and-media/games') != -1;
var bps3gamingPath = bPath.toLowerCase().indexOf('ps3/gaming') != -1;

var bPS2ACCPath = bPath.toLowerCase().indexOf('ps2/accessories') != -1;
var bPSPSYSPath = bPath.toLowerCase().indexOf('psp/systems') != -1;
var bPSPFEATPath = bPath.toLowerCase().indexOf('psp/features') != -1;

if(bPSPSYSPath.toString()=="true")
{
    xmlMarqueeFile = sAssetsPath+"sps_psp_sys_marquee_images_ss.xml"
}
if(bPSPFEATPath.toString()=="true")
{
    xmlMarqueeFile = sAssetsPath+"sps_psp_feat_marquee_images_ss.xml"
}

if(bPSPPath.toString()=="true")
{
    xmlMarqueeFile = sAssetsPath+"sps_psp_marquee_images_ss.xml"
}

if(bPS3ACCPath.toString()=="true")
{
    xmlMarqueeFile = sAssetsPath+"sps_ps3_marquee_images_ss.xml"
}

if(bPS2ACCPath.toString()=="true")
{
    xmlMarqueeFile = sAssetsPath+"sps_ps2_marquee_images_ss.xml"
}

if(bPS3GMPath.toString()=="true")
{
    xmlMarqueeFile = sAssetsPath+"sps_ps3_gnm_marquee_images_ss.xml"
}
if(bps3gamingPath.toString()=="true")
{
    xmlMarqueeFile = sAssetsPath+"sps_ps3_gaming_images.xml"
}
if(bPSNPath.toString()=="true")
{
    xmlMarqueeFile = sAssetsPath+"sps_psn_marquee_images_ss.xml"
}

if(bGamesMediaPath.toString()=="true")
{
    xmlMarqueeFile = sAssetsPath+"sps_gnm_marquee_images_ss.xml"
}
if(bGamesMediagamesPath.toString()=="true")
{
    xmlMarqueeFile = sAssetsPath+"sps_gnm_games_data_images.xml"
}

if(bPSPGMPath.toString()=="true")
{
    xmlMarqueeFile = sAssetsPath+"sps_psp_gnm_data_images.xml"
}

//Build path to xml feed
xmlMarqueeFile = "http://" + location.hostname + xmlMarqueeFile;

//New XML Marquee Starts
            $.ajax({
                type: "GET",
                url: xmlMarqueeFile,
                dataType: "xml",
                success: function(xml) {
                    
                    $(xml).find('item').each(function(){
                        var id = $(this).attr('id');
                        var title = $(this).find('title').text();
                        var image = $(this).find('src').text();
                        $("<div class='items' id='link_"+id+"'></div>").html("<img src='http://webassets.scea.com"+ucmroot+image+"' id='src_"+id+"' />").appendTo("#page-wrap");
                        
                        $(this).find('desc').each(function(){

                        });

                    });
                }
            });

//New XML Marquee Ends

}
var ucmWebRoot  = ucmroot;

        
    //If the marquee exists on the page, embed the marquee flash module.
    // Modf by ASR for jQuery Slider
    // This code is moved outside the $ready
    /* if($('#marquee').length > 0) {
        
        var controlsPosition = 252;
        if($('#home').length > 0) {
            controlsPosition = 349;
        }
        
        var flashvars = {
            data_path: ""+ucmWebRoot+"groups/public/documents/webcontent/sps_home_marquee_data.xml",
            controls_position: controlsPosition
        };
        var params = {
            menu: "false",
            wmode: "transparent",
            scale: "noscale"
        };
        var attributes = {
            id: "marquee",
            name: "marquee"
        };

        swfobject.embedSWF(""+ucmWebRoot+"groups/public/documents/webasset/ps_marquee_swf.swf", "marquee", "1160", "600", 
"9.0.0",""+ucmWebRoot+"groups/public/documents/webasset/ps_expressinstall.swf", flashvars, params, attributes);
        
        
    } */
    
    
    if($(window).width() > 960) {
            $('html').css('overflow-x', 'hidden');
        }
        
        $(window).resize(function(){
            if($(window).width() < 960) {
                $('html').css('overflow-x', 'auto');            
            }
            else {
                $('html').css('overflow-x', 'hidden');
            }
        });
    
    
    
  
    registerFeaturesAccordion();
    
    //The hover states begin!
    //Hardware modules on home page (0.0.home)
    //$('#hardware div').hover(function(){
    //      $(this).addClass('active');
    //  },
    //  function(){
    //      $(this).removeClass('active');      
    //  });
    //$('#hardware div').click(function(){
    //  window.location = $(this).find('a').attr('href');
    //  return false;
    //});
    
    //News items
    $('#main .browser.news .grid .item .top').hover(function(){
            $(this).parents('.item').addClass('active'); 
        },
        function(){
            $(this).parents('.item').removeClass('active');         
        });
    

    
    
    //System box
    $('#main #system .box').hover(function(){
            $(this).addClass('active').css('cursor','pointer');
        },
        function(){
            $(this).removeClass('active');      
        });
    $('#main #system .box').click(function(){
        window.location = $(this).find('a').attr('href');
        return false;
    });
    
    //Horizontal news items
    $('#main #content .newsDiscussions .item .comment').hover(function(){
            $(this).addClass('active');
            $(this).siblings().find('.link').addClass('active');
        },
        function(){
            $(this).removeClass('active');      
            $(this).siblings().find('.link').removeClass('active');
        });
    $('#main #content .newsDiscussions .item .comment').click(function(){
        window.location = $(this).siblings('.location').find('a').attr('href');
        return false;
    });
    $('#main #content .newsDiscussions .item .location .link').hover(function(){
            $(this).parents('.location').siblings().addClass('active');
        },
        function(){
            $(this).parents('.location').siblings().removeClass('active');
        }); 
    
    //Game details inside the friends module
    $('.gameplay .games .friends .gameDetails a').hover(function(){
            $(this).parents('.gameDetails').find('a').addClass('active');
        },
        function(){
            $(this).parents('.gameDetails').find('a').removeClass('active');
        })
        
    //Hide/show review form
    $('.user_reviews .review_form').hide();
    $('.user_reviews .write_a_review').click(function(){
        $('.user_reviews .review_form').show();
        return false;
    });
    $('.user_reviews .review_form .cancel').click(function(){
        $('.user_reviews .review_form').hide();
        $('.user_reviews .my_review').show();
        
        return false;
    });
    $('.user_reviews .edit_review a').click(function(){
        $('.user_reviews .review_form').show();
        $('.user_reviews .my_review').hide();
        
        var title = $('.review.edit .review_title').text();
        var comment = $('.review.edit .review_title').siblings('p').text();
        
        $('.user_reviews .review_form #title').val(title);
        $('.user_reviews .review_form #comment').val(comment);
        
        return false;
    });

    
    //Star bar on review form
    $('.starbar li a').hover(function(){
            var className = $(this).parent().attr('class');
            var stars = 0;
            switch(className) {
                case "one":
                    stars = 1;
                    break;
                case "two":
                    stars = 2;
                    break;
                case "three":
                    stars = 3;
                    break;
                case "four":
                    stars = 4;
                    break;
                case "five":
                    stars = 5;
                    break;
                default:
                    stars = 0;
                    break;
            }
            pos = stars * 14;
            $(this).parents('.starbar').css('background-position', "left " + -pos + "px");
        },
        function(){
            $(this).parents('.starbar').css('background-posiiton', '0 0'); 
        });
        
    //custom radio button in user reviews
    $('.user_reviews .terms').hover(function(){
            $(this).css('background-position', '0 -15px');
        },
        function(){
            if($(this).attr('class').indexOf('down') < 0) {
                $(this).css('background-position', '0 0');                      
            }
        });
    $('.user_reviews .terms').click(function(){
        $(this).toggleClass('down');
    });
    //custom radio buttons in overlays
    $('#overlay .addRadio').hover(function(){
            $(this).css('background-position', '0 -15px');
        },
        function(){
            if($(this).attr('class').indexOf('down') < 0) {
                $(this).css('background-position', '0 0');                      
            }
        });
    $('#overlay .addRadio').click(function(){
        $(this).toggleClass('down');
    });
    //Overlay close
    $('#overlay .close').click(function(){
        $(this).parents('#overlay').hide();
         
        $('#black_overlay').hide();
         $('#nameValidationMessage').remove();
          $('#toValidationMessage').remove();
        $('span').removeClass('error');
    $('#black_overlay1').hide();
    });
    

    
    $('#overlay .cancel').click(function(){
        $(this).parents('#overlay').hide();
     $('#black_overlay1').hide();
        $('#black_overlay').hide();
    });
    //Profile hover
    /*$('#header #profile').hover(function(){
            $(this).oneTime(1000, function(){
                $(this).addClass('open');
                $(this).find('.panel').show();
            
            });
        },
        function(){
            $(this).stopTime();
            $(this).removeClass('open');
            $(this).find('.panel').hide();      
        });
    $('#header #profile li').bind('mouseleave', function(){
        $('#header #profile').stopTime();
    });
    $('#header #profile li').bind('mouseenter', function(){
        $('#header #profile').oneTime(1000, function(){
            $(this).addClass('open');
            $(this).find('.panel').show();
        
        });
    });
    
    // added for Profile Dialog
    $('#profile_dialog').hide();
    $('#header #profile .logo_active').hover(function(){
        $('#profile_dialog').show();
    },
    function(){
        $('#profile_dialog').hide();        
    });
    
    // added for ProfileOut Dialog
    $('#header #profileOut .logo_active').hover(function(){
        $('#profile_dialog').show();
    },
    function(){
        $('#profile_dialog').hide();        
    });
    
    //Profile ID hover
    $('#header #profile').hover(function(){
            $(this).oneTime(1000, function(){
                $(this).addClass('open');
                $(this).find('.panel').show();
            
            });
        },
        function(){
            $(this).stopTime();
            $(this).removeClass('open');
            $(this).find('.panel').hide();      
        });
    $('#header #profile li').bind('mouseleave', function(){
        $('#header #profile').stopTime();
    });
    $('#header #profile li').bind('mouseenter', function(){
        $('#header #profile').oneTime(1000, function(){
            $(this).addClass('open');
            $(this).find('.panel').show();
        
        });
    }); */ 
    //Remove the guide test from all input fields
    removeGuideText();
    
    
    /* Primary Navigation */
    var isOpen = false;
    var time = 500;
    var open = '';
    var searchFocus = false;
    
    /* reset timer upon mouse out */
    $('#navigation').hover(function(){
        },
        function(){
            time = 500;
        });
        
    /* change the z-index upon hover, show the extended nav after (time) */
    $('#navigation li:not(".open") a').hover(function(){
            $(this).css('z-index',999);
            $(this).oneTime(time, function(){               
                $(this).addClass('active');
                time = 1;
            });
            if(!searchFocus){
                $('#search').removeClass('expanded');
                $('#search').css('z-index', 9);
            }
        },
        function(){
            $(this).stopTime();
            $(this).css('z-index',9);
            $(this).removeClass('active');              
    });
    
    /* change z-index and show the search extended panel after (time) */
    $('#navigation #search').hover(function(){
            $(this).css('z-index',999);
            $(this).parents('ul').children('li:not(".open")').children('ul').hide();            
            $(this).parents('ul').children('li').children('a').removeClass('active');           
            $(this).oneTime(time, function(){
                $(this).addClass('expanded');
                time = 1;
            });
            $('#navigation li a').stopTime();
            $('#navigation li:not("#search")').stopTime();
        },
        function(){
            $(this).removeClass('expanded');
        });
        
    /* stop the timer on the anchors and containers when you hover the search input box */
    $('#navigation #search input').hover(function(){
            $('#navigation li a').stopTime();
            $('#navigation li:not("#search")').stopTime();
        },
        function(){
        });
        
    /* show the expanded nav items after (time) */
    $('#navigation li:not(".open")').hover(function(){
            $(this).oneTime(time, function(timer){
                $(this).children('ul').show();
            });
        },
        function(){
            $(this).stopTime();
            $(this).children('ul').hide();          
        });
    
    
    /* add the active class to the appropriate anchor when hovering the expanded nav */
    $('#navigation li:not(".open") ul').hover(function(){
            $(this).parents('li').children('a').addClass('active');
            $(this).parents('li').children('a').css('z-index',999);
            // $(this).css('z-index',999);              
        },
        function(){
            $(this).stopTime();
            $(this).parents('li').children('a').removeClass('active');          
            $(this).parents('li').children('a').css('z-index',1);
        });
        
    /* if this nav item is open, find out which one */
    $('#navigation ul li').each(function(){
        if($(this).attr('class').indexOf('open') > -1) {
            open = $(this).attr('id');
        }
    });
    
    /* if the nav item is open, set the appropriate class to the other nav items */
    if(open == "ps3") {
        $('#navigation #psp').addClass('alt');
        $('#navigation #ps2').addClass('alt');
        $('#navigation #psn').addClass('alt');
        $('#navigation #games_and_media').addClass('alt');
        $('#navigation #search').addClass('alt');
    }
    else if (open == "psp") {
        $('#navigation #ps2').addClass('alt');
        $('#navigation #psn').addClass('alt');
        $('#navigation #games_and_media').addClass('alt');
        $('#navigation #search').addClass('alt');       
    }
    else if (open == "ps2") {
        $('#navigation #psn').addClass('alt');
        $('#navigation #games_and_media').addClass('alt');
        $('#navigation #search').addClass('alt');       
    }
    else if (open == "psn") {
        $('#navigation #games_and_media').addClass('alt2');
        $('#navigation #search').addClass('alt2');      
    }
    else if (open == "games_and_media") {
        $('#navigation #search').addClass('alt3');      
    }
    
    $('#navigation #search input').bind('focus', function(){
        searchFocus = true;
    });
    
    $('#navigation #search input').bind('blur', function(){
        $(this).parents('#search').css('z-index',9);
        $(this).parents('#search').removeClass('expanded'); 
        searchFocus = false;    
    });
    
    
  // faq page
  $('.faq_section .qa_group .answer').hide();

  $('.faq_section .qa_group .question').click(function()
  {
    element = $(this).next();
    if(element.css('display') == 'none')
    {
      element.slideDown();
    }
    else
    {
      element.slideUp();
    }
    return false;
  });

    //Tab button hovers
    $('ul.tabs li, ul.subnav li').hover(function(){
            $(this).addClass('hover');
        },
        function(){
            $(this).removeClass('hover');       
        });

    var browseAll = $('#main .browser.all ul.tabs li a');
    var dropdowns = $('#main .browser.all .dropdown');

    if (browseAll.length && dropdowns.length) {
        browseAll.click(function(e) {
            e.preventDefault();
            var index = browseAll.index(this);
            dropdowns.hide();
            browseAll.parent().css('visibility', 'visible');    

            dropdowns.eq(index).show();
            browseAll.parent().eq(index).css('visibility', 'hidden');           
        });

        dropdowns.find('a.close').click(function(e) {
            e.preventDefault();
            var index = dropdowns.index($(this).parent().parent());
            browseAll.parent().eq(index).css('visibility', 'visible');          
            dropdowns.eq(index).hide(); 
        });         
    }


    //expandos
    registerExpandos();
    
    // This should automatically setup the carousels:

    $('.browser').each(function() {
        new SliderTrack({
            container: $(this),
            lastClass: 'last'
        });        
    });

/* Added by ASR */
    $('.browsernew').each(function() {
        new SliderTrack({
            container: $(this),
            lastClass: 'last'
        });        
    });


    // But if the number of items per page isn't right, try this approach instead:
    /*
    new SliderTrack({
        container: '#main .browser.moviesTV',
        item: '.item',
        track: '.grid .gridInner .track',
        display: 5,
        lastClass: 'last'       
    }); 
    */

    /* Friends Accordion */     
    registerFriendsAccordion();
});

function registerFriendsAccordion() {
    var i = 0;
    $('.gameplay .games div h4').each(function(){

        //Add alt class to every other item
        if(i % 2 == 0) {
            $(this).addClass('alt');
            $(this).parent('div').children('ul').addClass('alt');
        }

        //Hide the friends lists on load if its doesn't start open
        if($(this).attr('class').indexOf('open') < 0) $(this).parent('div').children('.friends').hide(); 

        i++;

    });

    window.friendsHalt = false;

    $('.gameplay .games .friends li').click(function(){
        window.location = $(this).find('a').attr('href');
        return false;
    });

    $('.gameplay .games div h4').click(function(e){
        if (window.friendsHalt) return;
        window.friendsHalt = true;

        //If the clicked item was already open
        if($(this).attr('class').indexOf('open') > -1) {
            $(this).addClass('justClosed');
        }

        var effects = [];

        //Close the other open lists
        $(this).parents('.games').children('div').children('h4').each(function(){                       
            if($(this).attr('class').indexOf('open') > -1) {
                $(this).removeClass('open');

                var friends = $(this).parent('div').children('.friends').get();
                for (var i=0; i<friends.length; i++) {
                    effects.push(new Effect.BlindUp(friends[i], {sync:true, duration:0.25}));
                }               
            }
        }); 
        //If the clicked item wasn't open or wasn't just closed
        if($(this).attr('class').indexOf('open') < 0 && $(this).attr('class').indexOf('justClosed') < 0) {
            $(this).addClass('open');
            $(this).siblings('.friends').addClass('open');

            var friends = $(this).siblings('.friends').get();
            for (var i=0; i<friends.length; i++) {
                effects.push(new Effect.BlindDown(friends[i], {sync:true, duration:0.25}));
            }               
        }
        else {
            $(this).removeClass('open');
            $(this).siblings('.friends').removeClass('open');
            $(this).removeClass('justClosed');
        }

        new Effect.Parallel(effects, { 
            duration: 0.25,
            afterFinish: function() {
                window.friendsHalt = false;
            }.bind(this)
        });
    }); 

    $('#main .browser.news .grid .item .top').mouseenter(function() {
        $(this).addClass('hover');
    });
    
    $('#main .browser.news .grid .item .top').mouseleave(function() {
        $(this).removeClass('hover');
    }); 
}

/*function registerExpandos() {
    var expandoHovers = $('.browser .grid .item .expando, .trophy.item');

    if (expandoHovers.length) {

        var halt = false;

        //For non multi-row items
        $('.browser:not(".news") .grid:not(".multiRow") .item, .trophy.item').each(function() {
            var item = $(this);

      var expando = item.find('.expando');

            if (!expando.length) return;

            $(this).find('a.bg').bind('mouseenter', {item: item, expando: expando}, function(e) {
                var item = e.data.item;

                item.find('h4').addClass('active');
                var expando = e.data.expando;

                var expandoClone = expando.clone().prependTo('body');
                $('#expando').remove();
                expandoClone.attr('id', 'expando');
                if(expandoClone.attr('class').indexOf('left') > -1) {
                    var left = Math.ceil(item.offset().left + 138);
                }
                else {
                    var left = Math.ceil(item.offset().left - 221);                 
                }
                var top = Math.ceil(item.offset().top + 30);

                if(item.hasClass('trophy'))
                {
                  top = top-30;
                  left = left-5;
                }

                expandoClone.css({
                    'position' : 'absolute',
                    'left' : left,
                    'top' : top,
                    'z-index' : 999
                });

                item.oneTime(500, function(){
                    expandoClone.fadeIn(150);
                });             

            });

            $(this).mouseleave(function() { 
                $(this).find('h4').removeClass('active');
                $(this).stopTime();             
                $('#expando').fadeOut(75);
            });
        });

        //For multi-row items
        $('.browser:not(".news") .grid .item .thumb').each(function() {
            var item = $(this);

            var expando = item.find('.expando');
            if (!expando.length) return;

            $(this).find('a.bg').bind('mouseenter', {item: item, expando: expando}, function(e) {
                var item = e.data.item;

                item.find('h4').addClass('active');
                var expando = e.data.expando;

                var expandoClone = expando.clone().prependTo('body');
                $('#expando').remove();
                expandoClone.attr('id', 'expando');
                if(expandoClone.attr('class').indexOf('left') > -1) {
                    var left = Math.ceil(item.offset().left + 138);
                }
                else {
                    var left = Math.ceil(item.offset().left - 221);                 
                }
                var top = Math.ceil(item.offset().top + 30);

                expandoClone.css({
                    'position' : 'absolute',
                    'left' : left,
                    'top' : top,
                    'z-index' : 999
                });

                item.oneTime(500, function(){
                    expandoClone.fadeIn(150);
                });             

            });

            $(this).mouseleave(function() { 
                $(this).find('h4').removeClass('active');
                $(this).stopTime();             
                $('#expando').fadeOut(75);
            });
        });
    }   
    
}*/

function registerExpandos() {
    var expandoHovers = $('.browser .grid .item .expando, .trophy.item');

    if (expandoHovers.length) {

        var halt = false;

        //For non multi-row items
        $('.browser:not(".news") .grid:not(".multiRow") .item, .trophy.item').each(function() {
            var item = $(this);         
            createExpandos(item);
        });

        //For multi-row items
        $('.browser:not(".news") .grid .item .thumb').each(function() {
            var item = $(this);         
            createExpandos(item);   
        });
    }   
    
}

function createExpandos(item) {
    var expando = item.find('.expando');
    if (!expando.length) return;

    item.find('a.bg').bind('mouseenter', {item: item, expando: expando}, function(e) {
        
        var item = e.data.item;
        var image = item.children('a.bg');
        var headline = item.children('h4');
        var links = item.children('p');             
        var expando = e.data.expando;
        var expandoClone = expando.clone().prependTo('body');
        
        /*if(item.parents('#content').length) 
        {
            image.css
            ({
                'width': '124px',
                'height': '157px'
            });
        }*/ 
        
        headline.addClass('active');
        if(expandoClone.find('.system').length) {
            image.clone().insertAfter(expandoClone.find('.system'));    
        }
        else {
            image.clone().prependTo(expandoClone);
        }
        headline.clone().insertAfter(expandoClone.find('a.bg'));
        links.clone().insertAfter(expandoClone.find('h4'));

        expandoClone.attr('id', 'expando');
        
        //var left = Math.ceil(item.offset().left - 17);
        var left = Math.ceil(item.offset().left - 19);                  
        var top = Math.ceil(item.offset().top - 27);
        //if($.browser.mozilla) top -= 1;
        //if($.browser.mozilla) left += 1;


        expandoClone.css({
            'position' : 'absolute',
            'left' : left,
            'top' : top,
            'z-index' : 999
        });
        
        item.mouseleave(function(){ 
            headline.removeClass('active');
            $(this).stopTime();             
            $('#expando').fadeOut(1, function(){ $('#expando').remove(); });
        });
        
        item.oneTime(1, function(){
            item.unbind('mouseleave');
            expandoClone.fadeIn(1);
        });
        
        expandoClone.mouseleave(function() {
            headline.removeClass('active');
            $(this).stopTime();             
            $('#expando').fadeOut(0, function(){ expandoClone.remove(); });
        }); 

    }); 
}

function removeGuideText() {
    
    //For inputs
    $('input.text').each(function(){
        input = $(this);
        if(input.val() != '') {
            
            input.defaultValue = input.val();
            
            input.bind('focus', function(e){
                
                if($(e.target).val() == e.target.defaultValue) {
                    $(e.target).val('');
                }
            });
            input.bind('blur', function(e){
                
                if($(e.target).val() == '' && e.target.defaultValue) {
                    $(e.target).val(e.target.defaultValue);
                }
                
            });
            
        }
    });
    
    //For textareas
    $('textarea').each(function(){
        textarea = $(this);
        if(textarea.text() != '') {
            
            textarea.defaultValue = textarea.val();
            
            textarea.bind('focus', function(e){
                
                if($(e.target).val() == e.target.defaultValue) {
                    $(e.target).val('');
                }
            });
            textarea.bind('blur', function(e){
                
                if($(e.target).val() == '' && e.target.defaultValue) {
                    $(e.target).val(e.target.defaultValue);
                }
                
            });
            
        }
    });
}

// SliderTrack
function SliderTrack(x)
{
    var self = this;
    
    this.c = $(x.container);
    if (this.c.length == 0) return;
    this.c = this.c.eq(0);

    this.items = this.c.find(x.item || '.item');
    this.thumbs = this.c.find(x.thumb || '.thumb');
    
    this.prevButton = this.c.find(x.prev || 'a.previous');
    this.nextButton = this.c.find(x.next || 'a.next');
    this.track = this.c.find(x.track || '.track');
    if (this.track.length == 0) return;
    
    this.paging = this.c.find(x.paging || '.paging');
    this.pages = this.c.find(x.page || 'a.page');   
    
    var pageCopy = this.pages.eq(0).clone();
    this.pages.remove();
    
    if (this.items.length == 0)
    {
     this.paging.css({'visibility': 'hidden'});
     return;
    }
    
    this.items.removeClass('last');

    this.bounds = this.c.find(x.bounds || '.gridInner');
    this.itemWidth = (parseInt(this.items.css('width'),10) + parseInt(this.items.css('marginRight'),10));
    this.display = this.display || Math.ceil(this.bounds.width() / this.itemWidth);
    this.perclick = x.perclick || this.display;

    if (this.thumbs.length) {
        this.thumbWidth = (parseInt(this.thumbs.css('width'),10) + parseInt(this.thumbs.css('marginRight'),10));    
        this.perrow = Math.ceil(this.bounds.width() / this.thumbWidth);     
    }

    this.items.css({
        'width': this.itemWidth + 'px', 
        'marginRight': 0
    });
    
    // if the slider is grid/page structured        
    if (this.thumbs.length) {

        for (var i=0; i<this.thumbs.length; i++)
        {
            if ((i+1) % this.perrow == 0) {
                if (x.lastClass)
                    this.thumbs.eq(i).addClass(x.lastClass);        
            }
            // for .expando hovers
            if (i % this.perrow == 0 || i % this.perrow == 1) {
                this.thumbs.eq(i).find('.expando').addClass('left');
            }                                   
        }           
        
    // else the slider is item structured               
    } else {
    
        for (var i=0; i<this.items.length; i++)
        {
            if ((i+1) % this.display == 0) {
                if (x.lastClass)
                    this.items.eq(i).addClass(x.lastClass);     
            }
            // for .expando hovers
            if (i % this.display == 0 || i % this.display == 1) {
                this.items.eq(i).find('.expando').addClass('left');
            }       
        }   
    }

    for (var i=0; i<Math.ceil(this.items.length/this.perclick); i++)
    {
        pageCopy.find('span').html(i+1);
        pageCopy = pageCopy.insertBefore(this.nextButton).clone();              
    }
    this.pages = this.c.find(x.page || 'a.page');   
    
    if (this.pages.length <= 1) {
        this.paging.css({'visibility': 'hidden'});

/* Check for the new browser grid and bypass by ASR/RJV */    
        if($(".browsernew")){
        	$(".browsernew .footer .paging").css({'visibility': 'visible'});        
        	$(".browsernew .footer #moreLinks").css({'display': 'none'});        
        }


    }else{
    
        this.paging.css({'visibility': 'visible'});
    }
    
    this.width = this.items.width();
    this.track.width(this.items.length * this.width);
    
    this.prevButton.addClass('off');
    if (this.items.length <= this.display)
        this.nextButton.addClass('off');
    
    this.first = 0;
    this.currentPage = 0;
    this.setPage();
    
    this.prevButton.unbind("click");
    this.nextButton.unbind("click");
    
    this.prevButton.click(function(event) { self.prev(event); });
    this.nextButton.click(function(event) { self.next(event); });       
    this.pages.click(function(event) {self.page(event); });
    
    this.move(0);

    this.nextButton.removeClass('off'); 
    this.prevButton.removeClass('off');         
    
    if (this.first + this.display >= this.items.length)
        this.nextButton.addClass('off');

    if (this.first == 0)
        this.prevButton.addClass('off');
}

SliderTrack.prototype.prev = function(event)
{
    var self = this;
    
    event.preventDefault();
    event.stopPropagation();    

    if (this.prevButton.hasClass('off')) return;
    if (this.halt) return;

    this.nextButton.removeClass('off');

    this.currentPage--;
    this.setPage();
    
    this.first -= this.perclick;
    this.move(this.first * this.width);
    
    if (this.first == 0)
        this.prevButton.addClass('off');
}

SliderTrack.prototype.next = function(event)
{
    var self = this;
    
    event.preventDefault();
    event.stopPropagation();    
    
    if (this.nextButton.hasClass('off')) return;
    if (this.halt) return;
    
    this.prevButton.removeClass('off');

    this.currentPage++;             
    this.setPage();

    this.first += this.perclick;
    this.move(this.first * this.width);

    if (this.first + this.display >= this.items.length)
        this.nextButton.addClass('off');
}

SliderTrack.prototype.page = function(event)
{
    var self = this;
    event.preventDefault();
    event.stopPropagation();    

    var thisPage = this.pages.index(event.target);
    if (thisPage == this.currentPage) return;
    if (this.halt) return;
    
    this.first += (thisPage - this.currentPage) * this.perclick;    
    
    this.currentPage = thisPage;        
    this.setPage();
    
    this.move(this.first * this.width);

    this.nextButton.removeClass('off'); 
    this.prevButton.removeClass('off');         
    
    if (this.first + this.display >= this.items.length)
        this.nextButton.addClass('off');

    if (this.first == 0)
        this.prevButton.addClass('off');            
}

SliderTrack.prototype.setPage = function()
{
    this.paging.find('.on').removeClass('on');
    this.pages.eq(this.currentPage).addClass('on');
}

SliderTrack.prototype.move = function(pos)
{
    var self = this;

    this.halt = true;
    
    this.items.parent().animate({left: -pos}, 'normal', false, function() {
        self.items.parent().css({left: -pos+'px'}); // jQuery won't take us there so force the position
        self.halt = false;
    }); 
}
function registerFeaturesAccordion() {
    window.featuresHalt = false;

    $(".systems_section .section_content").each(function() { // on page load the content sections should not be seen
     //    if ($('.systems_section').length <= 1)  {
       // $(this).parent().removeClass("closed");
        //   $(this).parent().addClass("open");
         // $(this).parent().find('.section_header').children("a").text("Close");
         // $(this).parent().find('.section_header').children("a").css({'display': 'none'});
         //   $(this).parent().find('.section_header').css({'cursor': 'default'}); 
      //  return;
      //  }
       // $(this).hide();
        if(location.hash.indexOf($(this).parent().attr("id")) > -1) {
            $(this).show();
            $(this).parent().removeClass("closed");
            $(this).parent().addClass("open");
            $(this).parent().find('.section_header').children("a").text("Close");
            if(location.hash) window.location.href = window.location;
        }
        
    });
    
    $('.systems_section .section_header').click(function(e){
        onFeatureClick(this);   
    });
    $('.systems_section .section_header a').click(function(e){
        onFeatureClick($(this).parent('.section_header')[0]);
        return false;
    });
    
}
function onFeatureClick(element) {
    if (window.featuresHalt) return;
    if ($('.systems_section').length <= 1) return;
    window.featuresHalt = true;

    var effects = [];
    
    if($(element).parent().hasClass('closed')) {
        var feature = $(element).siblings('.section_content')[0];
        effects.push(new Effect.BlindDown(feature, {sync:true, duration:0.25}));
    }
    else {          
        var feature = $(element).siblings('.section_content')[0];
        effects.push(new Effect.BlindUp(feature, {sync:true, duration:0.25}));
    }
 
    new Effect.Parallel(effects, { 
        duration: 0.25,
        afterFinish: function() {
            if($(element).parent().hasClass('open')) {
                $(element).children("a").text("Open");
                $(element).parent().removeClass('open');
                $(element).parent().addClass('closed'); 
                $(".systems_section.closed .section_header"); /*.attr("title", "Click to Expand");*/
            }
            else {
                $(element).children("a").text("Close");
                $(element).parent().removeClass('closed');
                $(element).parent().addClass('open');
                $(".systems_section.open .section_header"); /*.attr("title", "Click to Collapse");*/
                $(".systems_section.closed .section_header"); /*.attr("title", "Click to Expand");*/
                
            }
            window.featuresHalt = false;
        }.bind(element)
    });
}

// done by snlg (dec,22, 2009)
var getBrowser=navigator.appName;
var b_version=navigator.appVersion;
var getVersion=parseFloat(b_version);
var getBrowserVersion = getBrowser + " "+ getVersion;



// managing flash nav width at runtime to make underneath links visible
function onNavigationOut(){
    getMovieName("navswf").width=140;   
    
}
function onNavigationOver(){
    getMovieName("navswf").width=267;  
         
    if (getBrowserVersion.toLowerCase()  == "opera 9.1"){   
        getMovieName("navswf").style.width=267;
    }
    
    if(getBrowserVersion.toLowerCase()  == "netscape 5") {
        getMovieName("navswf").width=267;
    }
}

function getMovieName(movieName) {

     if (navigator.appName.indexOf("Microsoft") != -1) { 
        return window[movieName];
     } 
     else {
         return document[movieName];
    }
 }
 function playSelectedMovie(movieId)
 {
 
    getMovieName("PSMediaPlayer").playSelectedId(movieId);
 }



function onProfileOver(){
    getMovieName("profile_login").style.height=400; 
    
    if (getBrowserVersion.toLowerCase()  == "opera 9.1"){       
        getMovieName("profile_login").style.height=400;
    }
    
    if(getBrowserVersion.toLowerCase()  == "netscape 5") {
        getMovieName("profile_login").height=400;
    }
}

function onProfileOut(){
    getMovieName("profile_login").height=50;
}
//Function to redirect to a page with some parameters
function redirectTo(pageURL,paramText)
{
overwriteCookie("movieName",paramText);
    window.location=location.protocol +"//" + window.location.host +pageURL;
}
//Function to add animation to "main" content

$(function() {
    $("#moduleSpace").toggle(function(){
            $("#moduleSpace").animate({height:heightnew}, 300);
        },
        function(){
            $("#moduleSpace").animate({height:heightold}, 300);
        }
    );

/*
$('#main .browser .grid #news ').hover(function(){
            
            css("background-position-x");
        },
        function(){
                        
        });
*/


/*$('#psn_community #main #news .item .comment').hover(function(){
            
        },
        function(){
                        
        });


$('#psn_community #main #news .comment').mouseover(function(){
    
});
*/

});

/* New added for Flash functionality */
function initialIncrMarqueeHeight() {
    if(isExpanded==true)
    {   
        $("#moduleSpace").animate({height:600}, 500);
        //holdPause();
    }
}
function incrMarqueeHeight() 
{
    $("#moduleSpace").animate({height:600}, 500);
    isExpanded=true;
    //holdPause();  
}
function decrMarqueeHeight() {  
    $("#moduleSpace").animate({height:446}, 500);
    isExpanded=false;
    //releasePause();
}
function holdPause(){
    //var flash = document.getElementById("marquee");
    // flash.showMarqeeCloseButton();
    getMovieName("marquee").holdPause();
}
function releasePause(){
    //var flash = document.getElementById("marquee");
    // flash.showMarqeeCloseButton();
    getMovieName("marquee").releasePause();
}

function isAgeGateRated(esrbRating)
{
    esrbRating=esrbRating.toLowerCase();
    if(esrbRating == 'mature' || esrbRating == 'adults only' || esrbRating == 'rp-m' ||  esrbRating == 't')
    {
    
            return true;    
    }
    else
    {
        return false;
    }
}
function createAgeGateCookie(ageLevel){
    xmlstorehttp=GetXmlHttpObject();
    if (xmlstorehttp==null){
        alert ("Your browser does not support AJAX!");
        return;
    }
    var storeurl="/uwps/CreateAgeGateCookie";
    storeurl=storeurl+"?op.anValue="+ageLevel;
    storeurl=storeurl+"&sid="+Math.random();
    xmlstorehttp.onreadystatechange=getAgeGateDetail
    xmlstorehttp.open("GET",storeurl,true);
    xmlstorehttp.send(null);
}
function getAgeGateDetail()
{
    if (xmlstorehttp.readyState==4)
    {
        var returnStoreStr = xmlstorehttp.responseText;
        
    }
}
function isUserAllowedAgeGate(){  

                var cookieValue="";
                var valueNow="";

                var serverName=window.location.host;

                ageGateCook = readCookie("op.an");
                if(ageGateCook)
                {
                    if(ageGateCook == "false")
                    {
                        valueNow= "nc";
                    }
                    else if(ageGateCook == "bD7YHksGRXI=")
                    {
                        valueNow= "true";
                    }
                    else if(ageGateCook == "3VvAmD195zs=")
                    {
                        valueNow= "false";
                    }
                }
                else
                {
                    valueNow= "nc";
                }
return valueNow;
                }
function isUserAllowedAgeGate1()
{
    var ageGateCook=readCookie("op.an");
    if(ageGateCook)
    {
        if(ageGateCook == "false")
        {
            return "nc";
        }
        else if(ageGateCook == "m")
        {
            return "true";
        }
        else
        {
            return "false";
        }
    }
    else
    {
        return "nc";
    }
}
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trimString(stringToTrim){
if(stringToTrim=='undefined')
    return "";
    return stringToTrim.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
var globalSiteName="/usplaystation/";
if(window.location.toString().indexOf("usplaystation")==-1)
    globalSiteName="/";
    
    
$(document).ready(function(){
    $("a.effect").mouseover(
    function()
    {
     $(this).parent().children(':first').addClass("toggleclass");
    }).mouseout(
    function()
    {
     $(this).parent().children(':first').removeClass("toggleclass");
    });
});
/* FAQ Question hover effect */

$(".question a").mouseover(
function()
{
 $(this).css('color','#D12127'); 
}).mouseout(
function()
{
  $(this).css('color','#000'); 
});

/*PNG FIX*/
 
/* FAQ Question hover effect */  


$(document).ready(function(){      

//$('.systems_section:last').addClass('open');
//$('.systems_section:last').removeClass('closed');
//$('.section_content:last').show();  

  
$('#VistLocal table tr td table tr:even td').css("background","#f2f2f2");
$('#VistLocal table tr td table tr:odd td').css("background","#f9f9f9");
$('img#psnstoreaboutimg').click(function() 
{ 
    writeGSVideo();
    $('#overlay1').toggle();
    $('#black_overlay').toggle();
});
$(".systems_section.closed .section_header"); /*.attr("title", "Click to Expand");*/
$(".systems_section.open .section_header"); /*.attr("title", "Click to Collapse");*/
});


// Netwok card

 
$(document).ready(function() {
$("a.networkcardtoggle").click(function() 
{ 
    if($("#VistLocal").css('display') == 'none')
    {
      $("#VistLocal").slideDown();
    }
    else
    {
      $("#VistLocal").slideUp();
    }
    return false;
    
});
}); 

/*ps_ajax_js*/
var tier2Category="";
var tier1Category="";

$('document').ready(function(){
    
    //Initially we want to register the click events for the conditions
    registerConditions();
    
    //For each option in the dropdowns we register a function to add them to the conditions list
    $('.browser .dropdown .body a').click(function(){
        var condition = $(this).text();
        var html = "<div class=\"condition\"><p>" + condition + "<a href=\"#\"><span>REMOVE CONDITION</span></a></p></div>";
        $('.browser .conditions').append(html);
        registerConditions();
        
        //The AJAX call
        $.ajax({
            type: 'POST',
            url: '#',
            data: 'example=true&save=something',
            dataType: 'xml'
        });
                
        return false;
    });
    
    //For each view option we want to make a call to the server and resort the list, also add an on class to display the on state.
    $('.browser.all .view a').click(function(){
        $(this).parent('.view').find('a').removeClass('on');
        $(this).addClass('on');
        
        $.ajax({
            type: "POST",
            url: "#",
            data: 'example=true&save=some',
            dataType: "html",
            success: function(html){
                //do somehting with our returned html. probably updated our pages list
                // $('.browser.all .list').html(html);
            }
        });
        return false;
    });
    
    //When the user changes a option in the drop down we want to make an ajax call and resort the list with the returned html.
    $('.browser.all select').change(function(event){
        $.ajax({
            type: "POST",
            url: "#",
            data: event.target.value,
            dataType: "html",
            success: function(html){
                //do somehting with our returned html. probably updated our pages list
                // $('.browser.all .list').html(html);
            }
        });
    });
    
    //To hide and show different subnav groups, other instances for other tabs need to be added
    $('.browser .tabs li a').click(function(){
        //var linkText = $(this).text().toLowerCase();
        var linkText = $(this).attr('id');
        
        if(linkText.indexOf('games3') > -1) {
    
            $('.browser .subnav').hide();
            $("#subnavgames3").show();
            //$('.browser .subnav.games').show();
        }
        else if(linkText.indexOf('gamesp') > -1) {

            $('.browser .subnav').hide();
            $("#subnavgamesp").show();

            //$('.browser .subnav.games').show();
        }
        else if(linkText.indexOf('games2') > -1) {
        
            $('.browser .subnav').hide();
            $("#subnavgames2").show();
            //$('.browser .subnav.games').show();
        }
        else if(linkText.indexOf('games') > -1) {
            $('.browser .subnav').hide();
            $("#subnavgames").show();
            //$('.browser .subnav.games').show();
        }
        else if(linkText.indexOf('newmovie') > -1) {
            $('.browser .subnav').hide();
            $("#subnavnewmovie").show();
            //$('.browser .subnav.system').show();
        }           
        else if(linkText.indexOf('newtvseries') > -1) {
            $('.browser .subnav').hide();
            $("#subnavnewtvseries").show();
            //$('.browser .subnav.system').show();
        }
        else if(linkText.indexOf('moviesnew') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmoviesnew").show();
            //$('.browser .subnav.games').show();
        }
        else if(linkText.indexOf('moviesbuy') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmoviesbuy").show();
            //$('.browser .subnav.games').show();
        }
        else if(linkText.indexOf('moviesrent') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmoviesrent").show();
            //$('.browser .subnav.games').show();
        }
        else if(linkText.indexOf('movies1') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmovies1").show();
            //$('.browser .subnav.movies').show();
        }
        else if(linkText.indexOf('movies2') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmovies2").show();
            //$('.browser .subnav.movies').show();
        }
        else if(linkText.indexOf('movies') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmovies").show();
            //$('.browser .subnav.movies').show();
        }
        
        else if(linkText.indexOf('add-ons') > -1) {
            $('.browser .subnav').hide();
            $("#subnavaddons").show();
            //$('.browser .subnav.addons').show();
        }
        
        else if(linkText.indexOf('demos') > -1) {
            $('.browser .subnav').hide();
            $("#subnavdemos").show();
            //$('.browser .subnav.demos').show();
        }
        else if(linkText.indexOf('tv-show') > -1) {
            $('.browser .subnav').hide();
            $("#subnavtvshow").show();
            //$('.browser .subnav.tvshow').show();
        }
        else if(linkText.indexOf('playstation3') > -1) {
            $('.browser .subnav').hide();
            $("#subnavplaystation3").show();
            //$('.browser .subnav.playstation3').show();
        }
        else if(linkText.indexOf('psp') > -1) {
            $('.browser .subnav').hide();
            $("#subnavpsp").show();
            //$('.browser .subnav.psp').show();
        }
        else if(linkText.indexOf('playstation2') > -1) {
            $('.browser .subnav').hide();
            $("#subnavplaystation2").show();
            //$('.browser .subnav.playstation2').show();
        }       
        else if(linkText.indexOf('op') > -1) {
            $('.browser .subnav').hide();
            $("#subnavop").show();
            //$('.browser .subnav.playstation2').show();
        }
        else if(linkText.indexOf('system') > -1) {
            $('.browser .subnav').hide();
            $("#subnavsystem").show();
            //$('.browser .subnav.system').show();
        }
        else if(linkText.indexOf('accessory') > -1) {
            $('.browser .subnav').hide();
            $("#subnavaccessory").show();
            //$('.browser .subnav.system').show();
        }

    });
});

//------------------ footer --------------------
        
function loadFooter() {
    
    $(document).ready(function() {

        var url=window.location;
        var root="";
        if(url.toString().indexOf("usplaystation")==-1){
            root="";
        }else{
            root="/usplaystation";
        }
        $("#footercontainer").load(root+"/footer/index.htm #footer", function(){
        	var innerString = $("#footercontainer").get(0).innerHTML;
        	$("#footercontainer").get(0).innerHTML = innerString.replace("..","");
        });
    });

}

//------------------ No Flash Left Navigation --------------------
 

//This is the function that registers the click event for all the conditions, it needs to be called after the conditions are resorted so new conditions have the click event.
function registerConditions() {
    $('.browser .conditions a').click(function(){
        $(this).parents('.condition').remove();
        
        //The AJAX call
        $.ajax({
            type: 'POST',
            url: '#',
            data: 'example=true&save=something',
            dataType: 'xml'
        });
        return false;
    }); 

}

//This function is called from the gameplay module and asynchronously pulls an html file based on the type of data needed, which is passed into the function
function loadGameplayData(object, section, type) {
    $(object).parent('li').siblings('li').removeClass('on');
    $(object).parent('li').addClass('on');
    
    var dataUrl = "/assets/data/gameplay_" + type + ".html";
    
    $(object).parents('.gameplay').find('.games').load(dataUrl, {}, registerFriendsAccordion);
}

function loadLinkData(type,platform,linkText){
        
        $("#hiddenType").get(0).innerHTML=type;
        $("#hiddenPlatform").get(0).innerHTML=platform;
        $("#moreHyperLink").get(0).innerHTML =  linkText;
}

//This funciton is called from them browser grid, it returns the appropriate html based on what section and type is passed in (ie: games and playstation 3)
function loadBrowserData(object, section, platform) {
tier2Category= platform;
tier1Category = section;

    $(object).parent('li').siblings('li').removeClass('on');
    $(object).parent('li').addClass('on');
    if($(object).parents('.tabs').length > 0) {
        $(object).parents('.browser').find('.subnav li').removeClass('on');
        $(object).parents('.browser').find('.subnav li:first-child').addClass('on');
    }
    
    $(document).ready(function() {

        $("#trackValue").get(0).innerHTML = $("#"+platform+""+section).get(0).innerHTML;
        $(".moreLink").hide();
        $("#games3link").hide();
        $("#demoslinks").hide();
        $("#accessorylink").hide();
        $("#games2link").hide();
        $("#gamesplink").hide();
        $("#gameslink").hide(); 
        $("#gamesdatalink").hide(); 
        $("#movieslink").hide();
        $("#moviesnewlink").hide();
        $("#moviesbuylink").hide();
        $("#moviesrentlink").hide();
        $("#newmovielink").hide();
        $("#addonslink").hide();
        $("#addons3link").hide();
        $("#addonsplink").hide();
        $("#addonlink").hide();
        $("#tvshowlink").hide();
        $("#tvshowseasonlink").hide();
        $("#tvshowseasonepisodelink").hide();
        $("#tvshowlatestlink").hide();
        $("#tvshowhdlink").hide();
        $("#newtvserieslink").hide();
        $("#games1link").hide();
        $("#games2link").hide();
        $("#"+section+"link").show();
        $("#more"+section).show();
        /*if($(".noresult").parent().attr("id")=="trackValue")
        {
            $(".noresult").parent().css('width','400px');
        }*/
        
    });

 //Check for the new browser grid and bypass by ASR/RJV     
 var mainPath1 = location.pathname ;

var bplayMovePath = mainPath1.toLowerCase().indexOf('ps3/playstation-move') != -1;
if(bplayMovePath.toString()=="true")
{
		if($(".browsernew")){
		$(".browsernew .footer #moreLinks").css({'display': 'none'});
	}
	
}else{
		resetSlider(); 
	}
 
  /*  resetSlider();*/
    
    //var dataUrl = "/assets/data/browser_grid_" + section + "_" + platform + ".html";

    //$(object).parents('.browser').find('.gridInner .track').load(dataUrl, {}, resetSlider);
}


function loadAjaxData(object, section, platform) {
    
    $(object).parent('li').siblings('li').removeClass('on');
    $(object).parent('li').addClass('on');
    if($(object).parents('.tabs').length > 0) {
        $(object).parents('.browser').find('.subnav li').removeClass('on');
        $(object).parents('.browser').find('.subnav li:first-child').addClass('on');
    }
    $(document).ready(function() {
    
        $.ajaxSetup ({
            cache: true
        });

        var url=window.location;
        var root="";
        if(url.toString().indexOf("usplaystation")==-1){
            root="";
        }else{
            root="/usplaystation";
        }
        $("#gridData").get(0).innerHTML = $("#overlayLoader").get(0).innerHTML;
        //document.getElementById("girdData").innerHTML=document.getElementById("overlayLoader").innerHTML;

        $(object).parents('.browser').find('.gridInner').load(root+"/grid/"+section+"_"+platform+"/index.htm #trackValue", function(){
            resetSlider();
        });

        $(object).parents('.browsernew').find('.gridInner').load(root+"/grid/"+section+"_"+platform+"/index.htm #trackValue", function(){
            resetSlider();
        });


    });

}
//This function is called in PSP Games & media for gettin parameter from URL

function loadURLDataPSP(section, platform) {
    $(document).ready(function() {
    
        $.ajaxSetup ({
            cache: true
        });

        var url=window.location;
        var root="";
        if(url.toString().indexOf("usplaystation")==-1){
            root="";
        }else{
            root="/usplaystation";
        }
        $("#girdData").get(0).innerHTML = $("#overlayLoader").get(0).innerHTML;
        //document.getElementById("girdData").innerHTML=document.getElementById("overlayLoader").innerHTML;
        
        $('.gridInner').load(root+"/grid/"+section+"_"+platform+"/index.htm #trackValue", function(){
            resetSlider();
        });
    });
}


//This funciton is called from Event landing page used for pagination
function getEventData(object, divname, count, sort) {

    $(object).parent('li').siblings('li').removeClass('on');
    $(object).parent('li').addClass('on');

    $(document).ready(function() {  
        
        try{
            $("#events").get(0).innerHTML = $("#"+divname+count+sort).get(0).innerHTML;
            $("#cat1").get(0).innerHTML = $("#"+divname+"Cat").get(0).innerHTML;
            $("#"+divname+(count-1)).siblings('li').removeClass('on');
            $("#"+divname+(count-1)).addClass('on');
        }catch(err){
            //alert("No Event exist in this category");
            $("#events").get(0).innerHTML = "There are no events currently available";
            $("#cat1").get(0).innerHTML = "";
        }

    });
    
}


//This funciton is called from Event landing page used for pagination
function eventPaging(object, divname, eventPage) {

    $(document).ready(function() {
        var count = $("#pageno").val();
        for(index=0; index<eventPage; index++){
            $("#"+divname+index).hide();
        }
        $("#"+divname+count).show();
    });
}


//This funciton is called from them browser grid, it returns the appropriate html based on what section and type is passed in (ie: accessories and playstation 3)
function loadSystemBrowserData(object, section, platform) {

    $(object).parent('li').siblings('li').removeClass('on');
    $(object).parent('li').addClass('on');
    if($(object).parents('.tabs').length > 0) {
        $(object).parents('.browser').find('.subnav li').removeClass('on');
        $(object).parents('.browser').find('.subnav li:first-child').addClass('on');
    }
    
    $(document).ready(function() {
        $("#accsys").removeClass('systems');
        $("#accsys").removeClass('accessories');
        $("#ps3accessory").hide();
        $("#ps2accessory").hide();
        $("#pspaccessory").hide();
        $("#pspgame").hide();
        $("#ps3system").hide();
        $("#ps2system").hide();
        $("#pspsystem").hide();
        $("#ps2game").hide();
        $("#allaccessory").hide();
        $("#pspgoaccessory").hide();
        $("#psp3000accessory").hide();
        $("#game").hide();
        $("#accessory").hide();
        $("#bundle").hide();
        $("#"+platform+""+section).show();
        $("#"+section).show();
        if(section == "accessory"){
            section = "accessories";
            $("#accsys").addClass(section);
        }
        else if(section == "system"){
            section = "systems";
        }
        
    });

}

//Activate related content fragment
function loadRetaledBrowserData(object, section) {

    $(object).parent('li').siblings('li').removeClass('on');
    $(object).parent('li').addClass('on');
    if($(object).parents('.tabs').length > 0) {
        $(object).parents('.browser').find('.subnav li').removeClass('on');
        $(object).parents('.browser').find('.subnav li:first-child').addClass('on');
        
    }
    $(document).ready(function() {
        $("#bundle").hide();
        $("#game").hide();
        $("#morebundle").hide();
        $("#moregame").hide();
        $("#"+section).show();
        $("#more"+section).show();
         
   });
    //resetSlider();

}

//This function is called after the browser grid loads to data to reset the slider so it has the appropriate number of pages, and click events are re-registered.
/*function resetSlider() {
    $('.browser').each(function() {
        new SliderTrack({
            container: $(this),
            lastClass: 'last'
        });
    });
    registerExpandos();
}*/
function resetSlider() {
    $('.browser').each(function() {
        new SliderTrack({
            container: $(this),
            lastClass: 'last'
        });
    });

/* Added by ASR */
    $('.browsernew').each(function() {
        new SliderTrack({
            container: $(this),
            lastClass: 'last'
        });
    });

    registerExpandos();
    /*if ($.browser.msie && $.browser.version < 8) {
     $('#main .browser .grid .item a.bg img').each(function(){
            var thish = $(this).height();
            var parenth = $(this).parent().height();
            var topmargin = (parenth - thish) / 2;
            $(this).css('margin-top', topmargin);
        });
    }*/
}

//This function is needed for XML Static Marquee by ASR
function slideSwitch() {
    var $active = $('#page-wrap DIV.active');

    if ( $active.length == 0 ) $active = $('#page-wrap DIV:last');
    var $next =  $active.next().length ? $active.next()
        : $('#page-wrap DIV:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});
  

    $(document).ready(function() {
            
                
            if ($.browser.msie && $.browser.version.substr(0,1)<7) {
            $("#overlaybuynow").css("position","absolute"); }
            $("#black_overlay11").height($(document).height()+400+"px");
             
         
                
    });
    
 
	if (screen.width == 1024) {
document.write("<style>#blackHeader_bar .toplogo{width:960px;}</style>")
}
else{document.write("<style>#blackHeader_bar .toplogo{width:1160px;}</style>")}
  
