Scripting Stylesheets


			
			$(function(){
				
				function selectStylesheetByTitle(title){
					for(var i=0; i< document.styleSheets.length; i++){
						var thisStylesheet = document.styleSheets[i];
						var thisTitle = document.styleSheets[i].title;
						if(thisTitle.toLowerCase() == title.toLowerCase()){
							alert('found it: '+ i);
							return document.styleSheets[i];
						}
					}
				}
				
				//selectStylesheetByTitle('main');
				
				
/*
				function selectRuleBySelector(sel){
					var stylesheet;
					if(document.styleSheets[1].cssRules){
						theRules = document.styleSheets[1].cssRules;
					}else if(document.styleSheets[1].rules){
						theRules = document.styleSheets[1].rules
					}
					for(){
						
					}
				}
*/
				
				
				
				
				var theRules = new Array();
				console.log(document.styleSheets);
				
				setTimeout(function(){
					console.log(document.styleSheets[0].rules[0].cssText);
					try{
						            document.styleSheets[0].rules[0].style.color = 'green';
						console.log(document.styleSheets[0].rules[0].cssText);
					}catch(e){
						alert('oop!: '+ e.message);
					}
				}, 2000);
				
				if (document.styleSheets[1].cssRules){
					// Safari
					theRules = document.styleSheets[1].cssRules;
					console.log(theRules);
					for(var i=0; i