/*************************************************************************
    This code is from Dynamic Web Coding at dyn-web.com
    Copyright 2008 by Sharon Paine 
    See Terms of Use at www.dyn-web.com/business/terms.php
    regarding conditions under which you may use this code.
    This notice must be retained in the code as is!
    
    for use with dw_rotator.js
*************************************************************************/
function jg_swapUrl(urlIn){
		var urlOut = urlIn;
//		alert(urlOut + "   " + urlIn);
		if (urlOut.match(/allinternal\S*/gi)){
			urlOut = urlOut.replace(/allinternal\S*/gi,'http://www.allinternal.com/go/979839/2/9/n/PG1'); 
		} else if (urlOut.match(/asstraffic\S*/gi)){
			urlOut = urlOut.replace(/asstraffic\S*/gi,'http://www.asstraffic.com/go/979839/1/9/n/PG1');  
		} else if (urlOut.match(/moregonzo\S*/gi)){
			urlOut = urlOut.replace(/moregonzo\S*/gi,'http://www.moregonzo.com/go/979839/23/9/n/PG1');  
		} else if (urlOut.match(/primecups\S*/gi)){
			urlOut = urlOut.replace(/primecups\S*/gi, 'http://www.primecups.com/go/979839/21/9/n/PG1');  
		} else if (urlOut.match(/tamedteens\S*/gi)){
			urlOut = urlOut.replace(/tamedteens\S*/gi, 'http://www.tamedteens.com/go/979839/22/9/n/PG1');  
		} else if (urlOut.match(/spermswap\S*/gi)){
			urlOut = urlOut.replace(/spermswap\S*/gi, 'http://www.spermswap.com/go/979839/20/9/n/PG1');  
		} else if (urlOut.match(/givemepink\S*/gi)){
			urlOut = urlOut.replace(/givemepink\S*/gi, 'http://www.givemepink.com/go/979839/19/9/n/PG1');  
		} else if (urlOut.match(/cumforcover\S*/gi)){
			urlOut = urlOut.replace(/cumforcover\S*/gi, 'http://www.cumforcover.com/go/979839/25/9/n/PG1');  
		} else if (urlOut.match(/purepov\S*/gi)){
			urlOut = urlOut.replace(/purepov\S*/gi, 'http://www.purepov.com/go/979839/26/9/n/PG1');  
		} else if (urlOut.match(/milfthing\S*/gi)){
			urlOut = urlOut.replace(/milfthing\S*/gi, 'http://www.milfthing.com/go/979839/27/9/n/PG1');  
		} else if (urlOut.match(/fistflush\S*/gi)){
			urlOut = urlOut.replace(/fistflush\S*/gi, 'http://www.fistflush.com/go/979839/28/9/n/PG1');  
		} else {
			urlOut = 'http://www.asstraffic.com/go/979839/1/9/n/PG1';
		}
//alert(url);

}

// display image at random
// rObj: object literal holding data 
function dw_getRandomImage(rObj) {
    var imgAr = rObj.images;  if (!imgAr ) return;
//alert(imgAr);
	var num = Math.floor( Math.random() * imgAr.length );
    var imgStr = ''; 
	var imgFile = imgAr[ num ];
    rObj.num = num; // hold which img selected
    var path = rObj.path || ''; var id = rObj.id || '';
    var title, alt = '', url;
    // If there are *any* entries for actions, alt or title include them here 
    if (rObj.alt) {
        alt = rObj.alt[num]? rObj.alt[num]: rObj.alt[0]? rObj.alt[0]: '';
    }
    if (rObj.title) {
        title = rObj.title[num]? rObj.title[num]: rObj.title[0]? rObj.title[0]: '';
    }
    if (rObj.actions) {
        //url = rObj.actions[num]? rObj.actions[num]: rObj.actions[0]? rObj.actions[0]: null; //original array swapper
	/*
		define the patterns
		get the file name
		find the pattern in the file name
		return the url
	*/
		url = imgFile;
		if (url.match(/allinternal\S*/gi)){
			url = url.replace(/allinternal\S*/gi,'http://www.allinternal.com/go/979839/2/9/n/PG1'); 
		} else if (url.match(/asstraffic\S*/gi)){
			url = url.replace(/asstraffic\S*/gi,'http://www.asstraffic.com/go/979839/1/9/n/PG1');  
		} else if (url.match(/moregonzo\S*/gi)){
			url = url.replace(/moregonzo\S*/gi,'http://www.moregonzo.com/go/979839/23/9/n/PG1');  
		} else if (url.match(/primecups\S*/gi)){
			url = url.replace(/primecups\S*/gi, 'http://www.primecups.com/go/979839/21/9/n/PG1');  
		} else if (url.match(/tamedteens\S*/gi)){
			url = url.replace(/tamedteens\S*/gi, 'http://www.tamedteens.com/go/979839/22/9/n/PG1');  
		} else if (url.match(/spermswap\S*/gi)){
			url = url.replace(/spermswap\S*/gi, 'http://www.spermswap.com/go/979839/20/9/n/PG1');  
		} else if (url.match(/givemepink\S*/gi)){
			url = url.replace(/givemepink\S*/gi, 'http://www.givemepink.com/go/979839/19/9/n/PG1');  
		} else if (url.match(/cumforcover\S*/gi)){
			url = url.replace(/cumforcover\S*/gi, 'http://www.cumforcover.com/go/979839/25/9/n/PG1');  
		} else if (url.match(/purepov\S*/gi)){
			url = url.replace(/purepov\S*/gi, 'http://www.purepov.com/go/979839/26/9/n/PG1');  
		} else if (url.match(/milfthing\S*/gi)){
			url = url.replace(/milfthing\S*/gi, 'http://www.milfthing.com/go/979839/27/9/n/PG1');  
		} else if (url.match(/fistflush\S*/gi)){
			url = url.replace(/fistflush\S*/gi, 'http://www.fistflush.com/go/979839/28/9/n/PG1');  
		} else {
			url = 'http://www.asstraffic.com/go/979839/1/9/n/PG1';
		}
    }
    if (url) {
        imgStr += '<a href="';
        imgStr += typeof url == 'string'? url: 'javascript: void ' + url;
        imgStr += '">';
	}
    
    imgStr += '<img src="' + path + imgFile + '"';
    imgStr += id? ' id="' + id + '"': '';
    if (title) {
        imgStr += ' title="' + title + '"';
    }
    imgStr += ' alt="' + alt + '" border="0" />';
    if (url) {
        imgStr += '</a>';
    }
    document.write(imgStr); document.close();
}

/////////////////////////////////////////////////////////////////////
//  code to add stop/restart links

dw_Rotator.addControls = function() {
    var els = dw_getElementsByClassName('rotator_controls');
    for (var i=0; els[i]; i++) {
        var links = els[i].getElementsByTagName('a');
        for (var j=0; links[j]; j++) {
            if ( dw_hasClass( links[j], 'stop') ) {
                links[j].onclick = function () { dw_Rotator.stop(); return false }
            } else if ( dw_hasClass( links[j], 'start') ) {
                links[j].onclick = function () { dw_Rotator.restart(); return false }
            } 
        }
        els[i].style.display = 'block';
    }
}

// restart rotation for all instances 
dw_Rotator.restart = function() {
    var len = dw_Rotator.col.length, obj;
    for (var i=0; i<len; i++) {
        obj = dw_Rotator.col[i];
        if (obj && obj.id ) //obj.rotate(); // no delay? 
            obj.timer = setTimeout( obj.animString + ".rotate()", dw_Rotator.resumeDelay );
    }
}

function dw_hasClass(el, cl) {
    var re = new RegExp("\\b" + cl + "\\b", "i");
    if ( re.test( el.className ) ) {
        return true;
    }
    return false;
}

function dw_getElementsByClassName(sClass, sTag, oCont) {
    var result = [], list, i;
    var re = new RegExp("\\b" + sClass + "\\b", "i");
    oCont = oCont? oCont: document;
    if ( document.getElementsByTagName ) {
        if ( !sTag || sTag == "*" ) {
            list = oCont.all? oCont.all: oCont.getElementsByTagName("*");
        } else {
            list = oCont.getElementsByTagName(sTag);
        }
        for (i=0; list[i]; i++) 
            if ( re.test( list[i].className ) ) result.push( list[i] );
    }
    return result;
};


/////////////////////////////////////////////////////////////////////
// example use of function pointer in actions
// id: id by which the instance can be obtained using dw_Rotator.getInstanceById
// (id passed to constructor - id attached to img tag)
function displayImgInSubWin(id) {
    var rObj = dw_Rotator.getInstanceById(id);
    var file = rObj.imgs[rObj.ctr].src;
    openSubWin(file);
    return false;
}

// arguments: file to open, subwindow name, left, top, width, height, other attributes
// common attributes: (comma separator, no spaces!)
// "resizable,scrollbars,toolbar,location,directories,status,menubar"
// all but url are optional with defaults provided below 
function openSubWin(url, nm, x, y, w, h, atts) {
    nm = nm || "subwindow";
    atts = atts || "menubar,resizable,scrollbars";
    w = w || 600; h = h || 450;
    x = (typeof x=="number")? x: Math.round( (screen.availWidth - w)/2 );
    y = (typeof y=="number")? y: Math.round( (screen.availHeight - h)/2 );
    atts += ',width='+w+',height='+h+',left='+x+',top='+y;
    var win = window.open(url, nm, atts); 
    if (win) {
        if (!win.closed) { win.resizeTo(w,h); win.moveTo(x,y); win.focus(); return false; }
    } 
    return true;
}
