// JavaScript Document -- Global
// Functions for robsta.id.au
//
//
// By Robert Morgan <robsta@robsta.id.au>
// unless otherwise noted.


// Static Vars
iconload = '<img src="/wp-content/themes/reforce/img/spinner.gif" alt="Loading..." />';

// ---===== Smooth Scrolling =====---
// based on work from: http://www.mad4milk.net/entry/scroll-your-internal-links-smoothly

var ScrollLinks = {
    currentHash: false,
    start: function(){
        this.scroll = new fx.Scroll({duration: 800, onComplete: function(){ScrollLinks.end();}});
        this.allinks = document.getElementsByTagName('a');
        for (i=0; i<this.allinks.length; i++){
            var lnk = this.allinks[i];
            if ((lnk.href && lnk.href.indexOf('#') != -1) && ( (lnk.pathname == location.pathname) || ('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search)) {
                lnk.onclick = function(){
                    ScrollLinks.scroll.clearTimer();
                    this.initialHref = this.href;
                    this.initialHash = this.hash;
                    this.href = "javascript:void(0)";
                    setTimeout(function(){this.href = this.initialHref;}.bind(this), 200);
                    ScrollLinks.click(this);
                }
            }
        }
    },

    click: function(link){
        this.currentHash = link.initialHash.substr(1);
        if (this.currentHash) {
            for (j=0; j<this.allinks.length; j++){
                if (this.allinks[j].id == this.currentHash){
                    if (!window.opera) this.scroll.scrollTo(this.allinks[j]);
                    else this.scroll.scrollTo(this.allinks[j].parentNode);
                    break;
                }
            }
        }
    },

    end: function(){
        window.location.href = "#"+this.currentHash;
        this.currentHash = false;
    }
}

window.onload = function(){
    ScrollLinks.start();
}

// ---===== IE PNG TRANSPARENCY HACK =====---
// based on work from: http://homepage.ntlworld.com/bobosola/pnghowto.htm

function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }

// ---===== DIGG NEWS DISPLAY USING AJAX =====---

/* Function called to get the product categories list */
function fetch_diggfeed() {
	/* Hide Link to Fetch Feed and show digg feed div */
	$('diggview').style.display = 'none';
	$('diggnews').style.display = 'block';
	
	/* Display loading indicator */
	$('diggnews').innerHTML = iconload;
	
	// show about content
	var url = 'http://robsta.id.au/bin/ajax_request.php?feed=digg';
	var pars = null;
	var myAjax = new Ajax.Updater( 
		'diggnews', 
		url, 
		{
			method: 'get', 
			parameters: pars
		});

}