$(document).ready(function() {

    var el = $('div.messageboard .s_date');
    if (el.length >= 1) {
        el.each(function() {
            this.innerHTML = this.innerHTML.replace(/\(GMT-08:00\)/ig, '');
        }); //end:each inner
    } //end:if

    var el = $('body.pg-home div#s_events span.location');
    if (el.length >= 1) {
        el.each(function() {
            this.innerHTML = this.innerHTML.replace(/, United States/ig, '');
        }); //end:each inner
    } //end:if

    try {
       $('p.s_blmlist').removeClass('clearfix').show().html('<a href="/buy" title="Buy" id="btn_buy" >Buy</a>');
    }
    catch (e) {
        return false;
    }

    
    var target = $('body.pg-home div#s_discography h4 a');
    target.each(function() {
        this.href = this.href.replace(/detail.aspx/, 'default.aspx');
    }); //end:each

    var target = $('body.pg-home div#s_events h4 a');
    target.each(function() {
        this.href = this.href.replace(/detail.aspx/, 'default.aspx');
    }); //end:each 
           
    
    
});

// COUNTRIES
$(document).ready(function() {
    $('#mod_dropdown').show();
    $("#country").change(onSelectChange);

    if ($.cookie('country_cookie')) {
        switch ($.cookie('country_cookie')) {
            case 'us':
                country_us();
                showChoosenCountry('us');
                break;
            case 'uk':
                country_uk();
                showChoosenCountry('uk');
                break;
            case 'fr':
                country_fr();
                showChoosenCountry('fr');
                break;
            case 'pt':
                country_pt();
                showChoosenCountry('pt');
                break;

            case 'ie':
                country_ie();
                showChoosenCountry('ie');
                break;

            case 'de':
                country_de();
                showChoosenCountry('de');
                break;

            case 'es':
                country_es();
                showChoosenCountry('es');
                break;

            case 'au':
                country_au();
                showChoosenCountry('au');
                break;

            case 'nl':
                country_nl();
                showChoosenCountry('nl');
                break;

            case 'ch':
                country_ch();
                showChoosenCountry('ch');
                break;

            case 'br':
                country_br();
                showChoosenCountry('br');
                break;

            case 'it':
                country_it();
                showChoosenCountry('it');
                break;

            default:
                country_all();
                showChoosenCountry('all');
                break;
        }
    } // end if

  

});           // end DOM ready



        function onSelectChange() {
            $('#mod_dropdown').hide();
        var selected = $("#country option:selected");
	    var COOKIE_NAME = 'country_cookie';
	    var options = { path: '/', expires: 10 };
		$.cookie(COOKIE_NAME, null, { path: "/" }); // destroy

		if (selected.val() == 'us') {
		    $.cookie(COOKIE_NAME, 'us', options)
		}
		if (selected.val() == 'uk') {
		    $.cookie(COOKIE_NAME, 'uk', options)
		}
		if (selected.val() == 'fr') {
		    $.cookie(COOKIE_NAME, 'fr', options)
		}
		if (selected.val() == 'pt') {
		    $.cookie(COOKIE_NAME, 'pt', options)
		}

		if (selected.val() == 'ie') {
		    $.cookie(COOKIE_NAME, 'ie', options)
		}
		if (selected.val() == 'de') {
		    $.cookie(COOKIE_NAME, 'de', options)
		}

		if (selected.val() == 'es') {
		    $.cookie(COOKIE_NAME, 'es', options)
		}

		if (selected.val() == 'au') {
		    $.cookie(COOKIE_NAME, 'au', options)
		}
		if (selected.val() == 'nl') {
		    $.cookie(COOKIE_NAME, 'nl', options)
		}
		
		if (selected.val() == 'br') {
		    $.cookie(COOKIE_NAME, 'br', options)
		}

		if (selected.val() == 'it') {
		    $.cookie(COOKIE_NAME, 'it', options)
		}

		if (selected.val() == 'ch') {
		    $.cookie(COOKIE_NAME, 'ch', options)
		}

		if (selected.val() == 'all') {
		    $.cookie(COOKIE_NAME, 'all', options)
		}
		window.location.reload(true);

		var newsPage = $('body.pg-news');
		if ((newsPage.length >= 1) && (selected.val() == 'us')) { window.location = "/country/us"; }
		if ((newsPage.length >= 1) && (selected.val() == 'uk')) { window.location = "/country/uk"; }
		if ((newsPage.length >= 1) && (selected.val() == 'fr')) { window.location = "/country/fr"; }
		if ((newsPage.length >= 1) && (selected.val() == 'pt')) { window.location = "/country/pt"; }
		if ((newsPage.length >= 1) && (selected.val() == 'ie')) { window.location = "/country/ie"; }
		if ((newsPage.length >= 1) && (selected.val() == 'de')) { window.location = "/country/de"; }
		if ((newsPage.length >= 1) && (selected.val() == 'es')) { window.location = "/country/es"; }
		if ((newsPage.length >= 1) && (selected.val() == 'au')) { window.location = "/country/au"; }
		if ((newsPage.length >= 1) && (selected.val() == 'nl')) { window.location = "/country/nl"; }
		if ((newsPage.length >= 1) && (selected.val() == 'ch')) { window.location = "/country/ch"; }
		if ((newsPage.length >= 1) && (selected.val() == 'br')) { window.location = "/country/br"; }
		if ((newsPage.length >= 1) && (selected.val() == 'it')) { window.location = "/country/it"; }
		if ((newsPage.length >= 1) && (selected.val() == 'all')) { window.location = "/blog"; }
		
    } //end: onSelectChange



    function showChoosenCountry(showMe) {
        try {
            if (showMe.indexOf('all') != 1) {
                $('div.all').hide();
                $('div.' + showMe).show();
                } // end:if
            }
        catch (e) {
            return false;
        }

        var linkNews = $('a.nav-blog');
        var commentLinks = $("body.pg-home div#s_news a.commentslink");
        var homepageNewsHeader = $("body.pg-home div#s_news h4 a");
        var homepageNewsTitle = $("body.pg-home div#s_news h3 a");
        var commentLinksNewsPage = $("body.pg-news div#s_news a.commentslink");
        if (showMe != 'all') {
            linkNews.attr('href', '/country/' + showMe + '/default.aspx');
            commentLinks.each(function() {
                this.href = this.href.replace(/blog/, 'country/' + showMe);
            }); //end:each
            homepageNewsHeader.each(function() {
                this.href = this.href.replace(/blog/, 'country/' + showMe);
            }); //end:each
            homepageNewsTitle.each(function() {
                this.href = this.href.replace(/blog/, 'country/' + showMe);
            }); //end:each
            commentLinksNewsPage.each(function() {
                this.href = this.href.replace(/blog/, 'country/' + showMe);
            }); //end:each 
        }
    } //end: function showChoosenCountry
    
function country_all() {
    $('img#country_flag').attr('src', '/images/flags/globe.png').show();
    $('#country')[0].selectedIndex = 0;
}

function country_us() {
    $('img#country_flag').attr('src', '/images/flags/24/USA.png').show();
    $('#country')[0].selectedIndex = 1;
}

function country_uk() {
    $('img#country_flag').attr('src', '/images/flags/24/UK.png').show();
    $('#country')[0].selectedIndex = 2;
}

function country_fr() {
    $('img#country_flag').attr('src', '/images/flags/24/France.png').show();
    $('#country')[0].selectedIndex = 3;
}

function country_pt() {
    $('img#country_flag').attr('src', '/images/flags/24/Portugal.png').show();
    $('#country')[0].selectedIndex = 4;
}

function country_ie() {
    $('img#country_flag').attr('src', '/images/flags/24/Ireland.png').show();
    $('#country')[0].selectedIndex = 5;
}

function country_de() {
    $('img#country_flag').attr('src', '/images/flags/24/Germany.png').show();
    $('#country')[0].selectedIndex = 6;
}

function country_es() {
    $('img#country_flag').attr('src', '/images/flags/24/Spain.png').show();
    $('#country')[0].selectedIndex = 7;
}

function country_au() {
    $('img#country_flag').attr('src', '/images/flags/24/Australia.png').show();
    $('#country')[0].selectedIndex = 8;
}

function country_nl() {
    $('img#country_flag').attr('src', '/images/flags/24/Netherlands.png').show();
    $('#country')[0].selectedIndex = 9;
}

function country_ch() {
    $('img#country_flag').attr('src', '/images/flags/24/Switzerland.png').show();
    $('#country')[0].selectedIndex = 10;
}

function country_br() {
    $('img#country_flag').attr('src', '/images/flags/24/Brazil.png').show();
    $('#country')[0].selectedIndex = 11;
}

function country_it() {
    $('img#country_flag').attr('src', '/images/flags/24/Italy.png').show();
    $('#country')[0].selectedIndex = 12;
}





