/** * -------------------------------------------------------------------- * jQuery-Plugin "preloadCssImages" * by Scott Jehl, scott@filamentgroup.com * http://www.filamentgroup.com * reference article: http://www.filamentgroup.com/lab/automated_image_preloading/ * demo page: http://www.filamentgroup.com/examples/preloadImages/ *  * Copyright (c) 2008 Filament Group, Inc * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses. * * Version: 1.0, 31.05.2007 * Changelog: * 	02.20.2008 initial Version 1.0 * -------------------------------------------------------------------- */$.preloadCssImages = function(settings){	//overrideable defaults	settings = jQuery.extend({		 imgDir: '/images/bg'	}, settings);	//dump all the css rules into one string	var sheets = document.styleSheets;	var cssPile = '';	for(var i = 0; i<sheets.length; i++){		if(!$.browser.msie){			var thisSheetRules = document.styleSheets[i].cssRules;			for(var j = 0; j<thisSheetRules.length; j++){				cssPile+= thisSheetRules[j].cssText;			}		}		else {			cssPile+= document.styleSheets[i].cssText;		}	}	//parse string for image urls and load them into the DOM	var allImgs = [];//new array for all the image urls  	var imgUrls = cssPile.match(/[^\/]+\.(gif|jpg|jpeg|png)/g);//reg ex to get a string of between a "/" and a ".filename"	if(imgUrls != null && imgUrls.length>0 && imgUrls != ''){//loop array		var arr = jQuery.makeArray(imgUrls);//create array from regex obj	 		$(arr).each(function(k){			allImgs[k] = new Image(); //new img obj			allImgs[k].src = settings.imgDir +'/'+ this;			});	}	return allImgs;}$(document).ready(function () {	// swap out main promo bg	var i = Math.floor(3*Math.random()) ;	var bgImg = ['url(/images/bg/main-bg.png)','url(/images/bg/main-bg2.png)','url(/images/bg/main-bg3.png)']	var promoUrl = ['/pub_works','/sheet_music','/listen'];		$('body.home #main-content').css('background-image',bgImg[i]);	$('#main-promo a').attr('href',promoUrl[i]);		// Opens external links in new window	$('.external').click(function () {		$(this).attr('target','_blank');				   	});		// scroll back to top	$('a.to-top').click(function() {		 $.scrollTo(0,'slow');		 return false;	 });			// Append music player when listen page loads	$('<embed src="/mp3/Adagio.mp3"></embed>').appendTo('#music-controller');		// controls music player	$('.mp3').click(function () {		$('#music-controller').html('');		var html = '<embed src="' + $(this).attr('href') + '"></embed>'; 		$('#music-player h4').text('Now Playing: ' + $(this).attr('title'));		$('#music-controller').append(html);		return false;	});		// get query results for selected composition type	$('#select-type').change(function () {		if ($('#select-type').val() == 'chamber') {			location.href = '/compositions';		} else {			location.href = '/' + $('#select-type').val();		}	});});
