function changecss (s, p, c) {
    var ss = document.styleSheets;

        for (var i=0; i<ss.length; i++) {
            var rules = ss[i].cssRules || ss[i].rules;

            for (var j=0; j<rules.length; j++) {
                if (rules[j].selectorText === s) {
                    eval ('rules[j].style.' + p + ' = "' + c + '";')
                }
            }
        }
}

function adjustWidth() {
    var elem = document.getElementById("internalText");
    if (elem.offsetWidth <= 640) {
        changecss ("div .indexItem", "width", "auto");
    }
    else {
        changecss ("div .indexItem", "width", "45%");
    }
}

function quoteCycler() {
    
    window.setTimeout(function () {
      $("#quote1").fadeOut(1000);
      $("#quote2").fadeIn(1000);
    },7000);

    window.setTimeout(function () {
      $("#quote2").fadeOut(1000);
      $("#quote1").fadeIn(1000);
    },14000);

   window.setTimeout(function() {quoteCycler()},14000);

};

$.fn.image = function(src, f){
    return this.each(function(){
        var i = new Image();
        i.src = src;
        i.onload = f;
        this.appendChild(i);
    });
}

function slideShowStart() {
    $("#hb1").image("uploads/images/banners/Banner_home1.jpg", function(){
        $("#hb1").fadeIn(1000);
        $("#hb2").image("uploads/images/banners/Banner_home2.jpg", function(){
            $("#hb3").image("uploads/images/banners/Banner_home3.jpg", function(){
                slideShow();
		quoteCycler();
            });
        });
    });
};

function changeSlide (a, b, t) {
  $(b).css('z-index',1);
  $(b).fadeIn(t);
  
  window.setTimeout(function() {
    $(a).css('display','none');
    $(b).css('z-index',0);
  }, t);
}

function slideShow() {
  window.setTimeout(function() {changeSlide ('#hb1', '#hb2', 1000)}, 7000);
  window.setTimeout(function() {changeSlide ('#hb2', '#hb3', 1000)}, 14000);
  window.setTimeout(function() {changeSlide ('#hb3', '#hb1', 1000)}, 21000);
  window.setTimeout(function() {slideShow()},21000);
};

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
