if (navigator.userAgent.indexOf('iPhone') != -1) {
    addEventListener("load",
    function() {
        setTimeout(hideURLbar, 0);
    },
    false);
}


function hideURLbar() {
    window.scrollTo(0, 1);
}
jQuery.preloadImages = function() {
    for (var i = 0; i < arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}


$.preloadImages("loader.gif", "load_bg.png");


function hideAddressBar() {
    window.scrollTo(0, 1);
}


$(function() {
    hideAddressBar();
    $('#back_link').hide();
    $('section_title').hide();
    $('img#info_button').click(function() {
        alert('The iTunes Mobile store allows you to purchase songs and albums heard on your favorite radio station directly from your iPhone or iPod Touch. \n \n Simply select a category from the top menu and choose a song or album to automatically launch the iTunes store application built into iPhone or iPod Touch.');

    });
 
});


function back_link(link) {
	if (link === 'artists') {
		$('#music ul#recent').html('');
		$('#music ul#albums').html('');
		$('#music ul#artists').slideDown('slow');
		$('#section_title').html('<h2><img src="images/ico_artists.png" alt="" />  <span>Select an Artist Below</span></h2>');
		$('#back_link').html('<a href="javascript:void(0)" onclick="back_link(\'a-z\')"><img src="images/back_az.png" /></a>');
		$('section_title').hide();
	} else {
		$('#music ul#recent').html('');
		$('#music ul#albums').html('');
		$('#music ul#artists').hide();
		$('#music ul#artists').html('');
		$('#music ul#a-z').slideDown('slow');
		$('#section_title').html('<h2><img src="images/ico_artists.png" alt="" />  <span>Alphanumeric Artist List</span></h2>');
		$('#back_link').hide();
		$('section_title').hide();
	}
}


function preload(state) {
    if (state === 'on') {
        $('#preload').fadeIn('#slow');
    } else {
        $('#preload').fadeOut('#slow');
    }
}


function content_switch() {
    $('#music ul#recent').hide();
    $('#music ul#a-z').hide();
    $('#music ul#list').hide();
    $('#music ul#albums').hide();
    $('#music ul#artists').hide();
    $('#back_link').hide();
    $('div#nav ul  li#a_all').removeClass('hit');
    $('div#nav ul  li#a_list').removeClass('hit');
    $('div#nav ul  li#a_recent').removeClass('hit');
    hideAddressBar(); //$('#music ul#artists').html('');
}


function content_show(section) {
    if (section === 'artists') {
        $('#music ul#artists').slideDown('slow');
    }
    switch (section) {
    case 'artists':
        $('#music ul#artists').slideDown('slow');
        break;
    case 'albums':
        $('#music ul#albums').slideDown('slow');
        break;
    case 'recent':
        $('#music ul#recent').slideDown('slow');
        break;
    case 'list':
        $('#music ul#list').slideDown('slow');
        break;
    case 'a-z':
        $('#music ul#a-z').slideDown('slow');
        break;
    default:
        $('#music ul#recent').slideDown('slow');
    }
}
