
var baseURL ="";
if(window.location.protocol.indexOf('https')!=-1  )
{
baseURL=window.location.protocol+"//"+window.location.host;
}
else
{
baseURL=window.location.protocol+"//"+"stage.gt.webassets.scea.com";
}

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-shockwagt-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 - End
// ASR
$(document).ready(function(){
 

var mainPath = location.pathname ;

var tickerPath = mainPath.toLowerCase().indexOf('/support/') != -1;
if(tickerPath.toString()=="true")
{

 $("#newsticker-demo").css("display","block");
  $(".newsticker-jcarousellite").css("visibility':'visible");
 
}
 

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');
	$('#profile').css('display', 'block');
}

if((pluginlist.indexOf("Flash")<0)||(bIsPS3.toString()=="true")|| (bIsIE.toString()=="true")){
// need to add condition here

var bPath = location.pathname ;

var xmlMarqueeFile;

if(bPath.toLowerCase().indexOf('ps3/features') != -1)
{
	xmlMarqueeFile=sAssetsPath+"ps3_landing_gt.xml";
}
else if(bPath.toLowerCase().indexOf('/ps3/accesorios') != -1)
{
	xmlMarqueeFile=sAssetsPath+"ps3_landing_gt.xml";
}
else if(bPath.toLowerCase().indexOf('playstation-move') != -1)
{
	xmlMarqueeFile=sAssetsPath+"ps3_move_gt.xml";
}
else if(bPath.toLowerCase().indexOf('ps3') != -1)
{
	xmlMarqueeFile=sAssetsPath+"ps3_landing_gt.xml";
}


else if(bPath.toLowerCase().indexOf('/ps2/accesorios/') != -1)
{
	xmlMarqueeFile=sAssetsPath+"ps2_accesorios_jq_gt.xml";
}
else if(bPath.toLowerCase().indexOf('ps2') != -1)
{
	xmlMarqueeFile=sAssetsPath+"ps2_home_gt.xml";
}

else if(bPath.toLowerCase().indexOf('juegos-y-medios/') != -1)
{
	xmlMarqueeFile=sAssetsPath+"juegos_y_medios_home_gt.xml";
}
else if(bPath.toLowerCase().indexOf('/juegos-y-medios/games/') != -1)
{
	xmlMarqueeFile=sAssetsPath+"juegos_y_medios_home_gt.xml";
}


else if(bPath.toLowerCase().indexOf('psp') != -1)
{
	xmlMarqueeFile=sAssetsPath+"psp_home_gt.xml";
}

else
{
	xmlMarqueeFile = sAssetsPath+"sps_home_marquee_images_gt.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();
                        var title = $(this).find('title').text();
                        var sAltAttrib = $(this).find('alttag').text();
                        var sLinkUrlAttrib = $(this).find('linkurl').text();
                        var sTarget = $(this).find('linktarget').text();
                      var serverPath="http://"+window.location.host;
                  if(serverPath=="http://gt.playstation.com")
                  {
                  serverPath="http://stage.gt.webassets.scea.com";
                  }
                 else   if(serverPath=="http://stage-gt.playstation.com")
                  {
                  serverPath="http://stage.gt.webassets.scea.com";
                  }
                 else
                 {
                 }
                  
                  
                  
                       if(bPath.toLowerCase().indexOf('jogos-e-mais/games/white-knight-chronicles-ps3') != -1)
{

 $("<div class='items' id='link_"+id+"'></div>").html("<img src='"+serverPath+ucmroot+image+"' id='src_"+id+"' alt='"+sAltAttrib+"' title='"+sAltAttrib+"'/>").appendTo("#page-wrap");                        
}  
                     else
                     {
                      $("<div class='items' id='link_"+id+"'></div>").html("<a href='"+sLinkUrlAttrib+"' target='"+sTarget+"' style='margin-top:0;'><img src='"+serverPath+ucmroot+image+"' id='src_"+id+"' alt='"+sAltAttrib+"' title='"+sAltAttrib+"'/></a>").appendTo("#page-wrap");                        
                     }
                        $(this).find('desc').each(function(){

                        });

                    });
                }
            });


//New XML Marquee Ends


}
var ucmWebRoot  = ucmroot;

    
    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();
    
    
    //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();
    });
   
    //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'
        });        
    });


    /* 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);         
            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');
        
              
        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(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);
        }
    );

});

/* 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;   
}
function decrMarqueeHeight() {  
    $("#moduleSpace").animate({height:446}, 500);
    isExpanded=false;
  
} 
function holdPause(){   
    getMovieName("marquee").holdPause();
}
function releasePause(){   
    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="/mxps/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++){  
      
        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="/gtplaystation/";
if(window.location.toString().indexOf("gtplaystation")==-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(){      

 
$('#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();           
        }
        else if(linkText.indexOf('gamesp') > -1) {
            $('.browser .subnav').hide();
            $("#subnavgamesp").show();
        }
        else if(linkText.indexOf('games2') > -1) {        
            $('.browser .subnav').hide();
            $("#subnavgames2").show();           
        }
        else if(linkText.indexOf('games') > -1) {
            $('.browser .subnav').hide();
            $("#subnavgames").show();           
        }
        else if(linkText.indexOf('newmovie') > -1) {
            $('.browser .subnav').hide();
            $("#subnavnewmovie").show();         
        }           
        else if(linkText.indexOf('newtvseries') > -1) {
            $('.browser .subnav').hide();
            $("#subnavnewtvseries").show();          
        }
        else if(linkText.indexOf('moviesnew') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmoviesnew").show();           
        }
        else if(linkText.indexOf('moviesbuy') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmoviesbuy").show();           
        }
        else if(linkText.indexOf('moviesrent') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmoviesrent").show();          
        }
        else if(linkText.indexOf('movies1') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmovies1").show();          
        }
        else if(linkText.indexOf('movies2') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmovies2").show();          
        }
        else if(linkText.indexOf('movies') > -1) {
            $('.browser .subnav').hide();
            $("#subnavmovies").show();           
        }
        
        else if(linkText.indexOf('add-ons') > -1) {
            $('.browser .subnav').hide();
            $("#subnavaddons").show();          
        }
        
        else if(linkText.indexOf('demos') > -1) {
            $('.browser .subnav').hide();
            $("#subnavdemos").show();           
        }
        else if(linkText.indexOf('tv-show') > -1) {
            $('.browser .subnav').hide();
            $("#subnavtvshow").show();          
        }
        else if(linkText.indexOf('playstation3') > -1) {
            $('.browser .subnav').hide();
            $("#subnavplaystation3").show();          
        }
        else if(linkText.indexOf('psp') > -1) {
            $('.browser .subnav').hide();
            $("#subnavpsp").show();          
        }
        else if(linkText.indexOf('playstation2') > -1) {
            $('.browser .subnav').hide();
            $("#subnavplaystation2").show();          
        }       
        else if(linkText.indexOf('op') > -1) {
            $('.browser .subnav').hide();
            $("#subnavop").show();           
        }
        else if(linkText.indexOf('system') > -1) {
            $('.browser .subnav').hide();
            $("#subnavsystem").show();         
        }
        else if(linkText.indexOf('accessory') > -1) {
            $('.browser .subnav').hide();
            $("#subnavaccessory").show();           
        }

    });
});

//------------------ footer --------------------
        
function loadFooter() {



    $(document).ready(function() {

        var url=window.location;
        
        var root="";
        if(url.toString().indexOf("gtplaystation")==-1){
            root="";
        }else{
            root="/gtplaystation";
          
        }
        $("#footercontainer").load(root+"/footer/index.htm #footer", function(data){
            var innerString = $("#footercontainer").get(0).innerHTML;
            
        	
        	//alert(document.getElementById($("#footercontainer").get(0).innerHTML));
        	//$("#footercontainer").get(0).innerHTML = innerString.replace("..","");
        	$("#footercontainer").get(0).innerHTML = replaceAll(innerString,"..","");
        	
        	
        });
    });

}


//------------------ Share This --------------------
        
function loadShareThis() {
    $(document).ready(function() {

        var url=window.location;
        var root="";
        if(url.toString().indexOf("gtplaystation")==-1){
            root="";
        }else{
            root="/gtplaystation";
        }
        $("#shareThiscontainer").load(root+"/sharethis/index.htm #shareThisId", function(){
       
			//document.getElementById('myspace').href="http://www.myspace.com/index.cfm?fuseaction=postto&t="+document.title+"<br/>"+encodeURIComponent('Explore the official website of Sony PlayStation 3')+" &u="+encodeURIComponent(window.location); 
			
			if(document.getElementById('reddit')!=null){
   document.getElementById('reddit').href="http://www.reddit.com/submit?url="+encodeURIComponent(window.location)+"&title="+encodeURIComponent(document.title); 
   }
   if(document.getElementById('twitter')!=null){
   document.getElementById('twitter').href="http://twitter.com/home?status="+encodeURIComponent(window.location); 
   }
   if(document.getElementById('delicious')!=null){
   document.getElementById('delicious').href="http://del.icio.us/post?v=2&amp;url="+encodeURIComponent(window.location)+"&amp;notes="+encodeURIComponent('Explore the official website of Sony PlayStation.')+"&amp;tags=&amp;title="+encodeURIComponent(document.title); 
   }
   if(document.getElementById('stumbled')!=null){
   document.getElementById('stumbled').href="http://www.stumbleupon.com/submit?url="+encodeURIComponent(window.location)+"&amp;title="+encodeURIComponent(document.title) 
   }
   if(document.getElementById('linkedIn')!=null){
   document.getElementById('linkedIn').href="http://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent(window.location)+"&title="+encodeURIComponent(document.title) }    
   if(document.getElementById('digg')!=null){
   document.getElementById('digg').href="http://digg.com/submit?phase=2&amp;url="+window.location+"&amp;bodytext="+encodeURIComponent('Explore the official website of Sony PlayStation')+"&amp;tags=&amp;title="+encodeURIComponent(document.title) 
   }
   if(document.getElementById('facebook')!=null){
   document.getElementById('facebook').href="http://www.facebook.com/share.php?u="+encodeURIComponent(window.location)+"&amp;d=&amp;tag=&amp;"
   } 
   if(document.getElementById('myspace')!=null){ 
   var myspaceurl="http://www.myspace.com/index.cfm?fuseaction=postto&t="+encodeURIComponent(document.title);
   myspaceurl=myspaceurl+encodeURIComponent("<br/>");
   myspaceurl=myspaceurl+encodeURIComponent('Explore the official website of SonyPlayStation3')+"&u=";
   myspaceurl=myspaceurl+encodeURIComponent(window.location);  
   document.getElementById('myspace').href=myspaceurl;           
   }

            
            var sceaUserInfo=getCookieValueFromServer("userinfo");
			var email =  getUserInfoKeyValue(sceaUserInfo,"email");
			var firstName = getUserInfoKeyValue(sceaUserInfo,"firstName");
			var lastName = getUserInfoKeyValue(sceaUserInfo,"lastName");
			if(typeof(email) != "undefined"){
				//document.frm.Uremail.value=email;
			} else {
				//document.frm.Uremail.value="";
			}
			if(typeof(firstName) != "undefined"){
				//document.frm.sname.value=firstName + " " +lastName;
			} else {
				//document.frm.sname.value="";
			} 
        		
        });
    });

}
function replaceAll(Source,stringToFind,stringToReplace){

  var temp = Source;
    var index = temp.indexOf(stringToFind);
        while(index != -1){
            temp = temp.replace(stringToFind,stringToReplace);
            index = temp.indexOf(stringToFind);
        }
        
	return temp;
}

//------------------ 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();
        
    });

 //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")){
		resetSlider();
		$(".browsernew .footer #moreLinks").css({'display': 'none'});
	}
	
}else{
		resetSlider(); 
	} 
}



function loadDynamicAjaxData(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');
    }
    var getUrl="section=landing&noOfRecords=10&type="+section+"&platform="+platform;
    //alert('vikas'+getUrl);
   $("#gridData").get(0).innerHTML = $("#overlayLoader").get(0).innerHTML;
	$.ajax({
	type: "POST",
	url: "/gtuwps/GetDetailPageGrid",
	data: getUrl,
	cache: false,
	success: function(html){
	//alert('vikas-'+html);
	
	document.getElementById('gridData').innerHTML=html;
	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("gtplaystation")==-1){
            root="";
        }else{
            root="/gtplaystation";
        }
        $("#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();
        });

    });

}


function loadAjaxDataPSP(section, platform) {              
    $(document).ready(function() {
        $.ajaxSetup ({
            cache: true
        });

        var url=window.location;
        var root="";
        if(url.toString().indexOf("gtplaystation")==-1){
            root="";
        }else{
            root="/gtplaystation";
        }
        $("#gridData").get(0).innerHTML = $("#overlayLoader").get(0).innerHTML;
        //document.getElementById("girdData").innerHTML=document.getElementById("overlayLoader").innerHTML;

        $('#gridData').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("gtplaystation")==-1){
            root="";
        }else{
            root="/gtplaystation";
        }
        $("#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();

}


function resetSlider() {
    $('.browser').each(function() {
        new SliderTrack({
            container: $(this),
            lastClass: 'last'
        });
    });

/* Added by ASR */
    $('.browsernew').each(function() {
        new SliderTrack({
            container: $(this),
            lastClass: 'last'
        });
    });

    registerExpandos();
    
}

//This function is needed for XML Static Marquee by ASR
function slideSwitch() 
{
    
	var $active = $('#page-wrap DIV.active');  	
	
	if($('#page-wrap DIV.active a').attr('href') != undefined)
	{		
		resetModuleLink();
		document.getElementById('moduleLink').href =  $('#page-wrap DIV.active a').attr('href');
	}

	/* Change in PreLoad Marquee Visibility modf by ASR */
	$(".preload_marquee").css("background","none");

	/*Single node check by ASR*/
    if($('#page-wrap').children('div').size()>1)
	{
	
    
		if ( $active.length == 0 ) 
		{
			
			$active = $('#page-wrap DIV:last');
								
			if($('#page-wrap DIV:last a').attr('href') != undefined)
			{
				resetModuleLink();
				document.getElementById('moduleLink').href =  $('#page-wrap DIV:last a').attr('href');
			}
		}
    
   		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');
		
						
		if($('#page-wrap DIV.active a').attr('href') != undefined )
		{	
			resetModuleLink();								
			document.getElementById('moduleLink').href =  $('#page-wrap DIV.active a').attr('href');
		}
        });
    }
	else
	{
    	$('#page-wrap DIV:first').addClass('active');
			
		if($('#page-wrap DIV:first a').attr('href') != undefined)
		{		
			resetModuleLink();			
			document.getElementById('moduleLink').href =  $('#page-wrap DIV:first a').attr('href');
		}
	}


	if ($('#moduleLink').attr('href') == "#") 
	{	
		$('#moduleLink').remove();
	}

}


function resetModuleLink()
{
    
    if ($('#moduleSpace').length > 0 ) 
	{
		if ($('#moduleLink').length == 0 ) 
		{
			$('<a id="moduleLink" href="#" style="cursor:default; display:block; height:100%; width:100%">&nbsp;</a>').appendTo("#moduleSpace");	
		}
	}
    
}
$(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>")}



function loadRelatedGames(object,section,skuid,platform,genre)
{

var getUrl="section="+section+"&skuid="+escape(skuid)+"&platform="+escape(platform)+"&genre="+escape(genre);

	$.ajax({
	type: "POST",
	url: "/gtuwps/GetDetailPageGrid",
	data: getUrl,
	cache: false,
	success: function(html){
	
	document.getElementById('gridData').innerHTML=html;
	resetSlider();
	}
	});

/*
$(object).parents('.browser').find('.gridInner').load("/mxps/GetDetailPageGrid?skuid="+escape(skuid)+"&platform="+escape(platform)+"&genre="+escape(genre) , function(){
            resetSlider();
        });*/
}



function loadRelatedAddon(object,section,skuid,relatedgame,platform,genre)
{

var getUrl="section="+section+"&skuid="+escape(skuid)+"&relatedgame="+relatedgame+"&platform="+escape(platform)+"&genre="+escape(genre);
	$.ajax({
	type: "POST",
	url: "/gtuwps/GetDetailPageGrid",
	data: getUrl,
	cache: false,
	success: function(html){
	document.getElementById('gridData').innerHTML=html;
	resetSlider();
	}
	});

/*
$(object).parents('.browser').find('.gridInner').load("/mxps/GetDetailPageGrid?skuid="+escape(skuid)+"&platform="+escape(platform)+"&genre="+escape(genre) , function(){
            resetSlider();
        });*/
}
  
  
function loadRelatedDemos(object,section,skuid,relatedgame,platform,genre)
{

var getUrl="section="+section+"&skuid="+escape(skuid)+"&relatedgame="+relatedgame+"&platform="+escape(platform)+"&genre="+escape(genre);
	$.ajax({
	type: "POST",
	url: "/gtuwps/GetDetailPageGrid",
	data: getUrl,
	cache: false,
	success: function(html){
	document.getElementById('gridData').innerHTML=html;
	resetSlider();
	}
	});
}
  
  
function loadRelatedMovie(object,section,skuid,genre)
{

var getUrl="section="+section+"&skuid="+escape(skuid)+"&genre="+escape(genre);
	$.ajax({
	type: "POST",
	url: "/gtuwps/GetDetailPageGrid",
	data: getUrl,
	cache: false,
	success: function(html){
	document.getElementById('gridData').innerHTML=html;
	resetSlider();
	}
	});
}


function backtosharediv(){
	$(document).ready(function() {
	
    	$("#black_overlay").show();
      	$("#shareDetails").toggle();
       	$("#shareDetails_msg").toggle();
  	$("#divCont1").toggle();
        	
	});
    
    var sceaUserInfo=getCookieValueFromServer("userinfo");
		var email =  getUserInfoKeyValue(sceaUserInfo,"email");
		var firstName = getUserInfoKeyValue(sceaUserInfo,"firstName");
		var lastName =  getUserInfoKeyValue(sceaUserInfo,"lastName");
		if(typeof(email) != "undefined"){
			document.frm.Uremail.value=email;
		} else {
			document.frm.Uremail.value="";
		}
		if(typeof(firstName) != "undefined"){
			document.frm.sname.value=firstName + " " + lastName;
		} else {
			document.frm.sname.value="";
		}

}
function getBaseURL(){
	var siteName="/gtplaystation";
	
	var urlString = "";
	urlString = window.location.toString();
	if(urlString.indexOf(siteName)==-1){
    	siteName="";
	}
	
	return window.location.protocol+"//"+window.location.host+siteName;
}

function hideShare()
	{	
		$('.share-this').css("display","none");		 
	 	$('.share-this2').css("display","none");
		document.getElementById('overlay').style.display="none"; 
		document.getElementById('black_overlay').style.display='none';
		document.getElementById('black_overlay1').style.display='none';
			
		if(document.getElementById('overlay').style.display=="block".cursor=="pointer"){
			$('.share-this').toggle();
			$('.black_overlay').toggle();
			$('#black_overlay1').toggle();
		}
        
	}
	
$(document).ready(function(){
//$('#sidebar').css('padding-top','10px');
$('.hasSupport #main p.innerbreadcrum a').css('font-size','12px');
});




//****** CUSTOM ALERT BOX **********//

window.onload=function(){
var ALERT_TITLE = "PlayStation.com";

var ALERT_BUTTON_TEXT = "Ok";
if(document.getElementById) {

window.alert = function(txt1) {
createCustomAlert(txt1);
 
}

} 
function createCustomAlert(txt1) {
	//document.getElementById('black_overlay').style.display="block";

d = document;
if(d.getElementById("modalContainer")) return;
mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
mObj.id = "modalContainer";
mObj.style.height = d.documentElement.scrollHeight + "px";
alertObj = mObj.appendChild(d.createElement("div"));
alertObj.id = "alertBox";
//if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
if(d.all && !window.opera) alertObj.style.top = "100px";
alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px"; 

alertObj.style.visiblity="visible";

h1 = alertObj.appendChild(d.createElement("h1"));
h1.appendChild(d.createTextNode(ALERT_TITLE));
msg1 = alertObj.appendChild(d.createElement("p"));
//msg1.appendChild(d.createTextNode(txt1));
msg1.innerHTML = txt1;
btn = alertObj.appendChild(d.createElement("a"));
btn.id = "closeBtn";
btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT) );
btn.href = "javascript:void(0);";
btn.focus();

btn.onclick = function() {
	removeCustomAlert();
	$("#black_overlay1").hide()
	}
alertObj.style.display = "block";
btn1 = alertObj.appendChild(d.createElement("a"));
btn1.id = "closeBtn1";
btn1.appendChild(d.createTextNode(ALERT_BUTTON_TEXT) );
btn1.href = "javascript:void(0);";
btn1.focus();
btn1.onclick = function() {
	removeCustomAlert();
	$("#black_overlay1").hide()
	}
}}
function removeCustomAlert() {
	//document.getElementById('black_overlay').style.display="none";
document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}


function getUserInfoKeyValue(userInfo,key){	
	var userInfoValues=userInfo.split(",");
	for(i = 0; i < userInfoValues.length; i++){
    	var pair=userInfoValues[i].split("=");
        if(pair[0]==key){
            	return pair[1];
        }
    }
}
 
function callback(str)
	{
	$("#black_overlay1").show();
	alert(str);
}  
$(document).ready(function(){
var frame_height=$(document).height()+350;
if(bIsPS3){ 
$("#black_overlay1").height(frame_height)
}
});
