var section;
var section_attributes;
var state = 1;

rotateBanner = function () {
	if (state == 1) {
		section_attributes = { opacity: { to: 0 }};	
		section = new YAHOO.util.Motion('fs1', section_attributes);	
	} else {
		YAHOO.util.Dom.setStyle(['fs1'], 'z-index', '1');		
		section_attributes = { opacity: { to: 1 }};	
		section = new YAHOO.util.Motion('fs1', section_attributes);
	}
	section.onComplete.subscribe(function() { 
		resetPositions();
	});
	section.animate();
}
resetPositions = function () {	
	if (!(++currentSection < nSections)) {
		currentSection = 0;
	}
	if (state == 1) {
		YAHOO.util.Dom.setStyle(['fs1'], 'z-index', '-1');
		loadSection('fs1');	
	}
	else {
		loadSection('fs2');
	}
	state *= -1;
	setTimeout(rotateBanner, 6000);	
}

init = function () {
	setTimeout(rotateBanner, 6000);
	
	loadSection('fs2');
}

YAHOO.util.Event.onDOMReady(init);

loadSection = function (fs) {
	document.getElementById(fs + '_h3').innerHTML = featuredSections[currentSection][0];
	document.getElementById(fs + '_title').innerHTML = featuredSections[currentSection][1];
	document.getElementById(fs + '_title').href = featuredSections[currentSection][2];
	document.getElementById(fs + '_link').href = featuredSections[currentSection][2];
	document.getElementById(fs + '_summary').innerHTML = featuredSections[currentSection][3];
	document.getElementById(fs + '_img').src = featuredSections[currentSection][4];	
}


var featuredSections = new Array();
/*featuredSections[0] = new Array(
	"Business Profile",
	"Dr. Juliet V. Garcia",
	"http://rgvisionmagazine.com/2009/06/dr-juliet-v-garcia/",
	"University of Texas at Brownsville President",
	"http://rgvisionmagazine.com/images/090708/features/garcia.jpg"
);
featuredSections[1] = new Array(
	"Business Profile",
	"Kay Bailey Hutchison",
	"http://rgvisionmagazine.com/2009/06/senator-kay-bailey-hutchison/",
	"United States Senator, Texas",
	"http://rgvisionmagazine.com/images/090708/features/hutchison.jpg"
);
featuredSections[2] = new Array(
	"Medical Profile",
	"Dr. Charmaine Browne",
	"http://rgvisionmagazine.com/2009/06/dr-charmaine-browne/",
	"The Dermatology Institute of South Texas",
	"http://rgvisionmagazine.com/images/090708/features/browne.jpg"
);
featuredSections[3] = new Array(
	"Medical Profile",
	"Dr. Bonnie D. Villarreal",
	"http://rgvisionmagazine.com/2009/06/dr-bonnie-d-villarreal/",
	"Rio Vista Dentistry",
	"http://rgvisionmagazine.com/images/090708/features/villarreal.jpg"
);
featuredSections[4] = new Array(
	"Real Estate Profile",
	"Lew Vassberg",
	"http://rgvisionmagazine.com/2009/06/lew-vassberg/",
	"Valley Designs &ndash; Harlingen, TX",
	"http://rgvisionmagazine.com/images/090708/features/vassberg.jpg"
);*/

featuredSections[0] = new Array(
	"Medical Profile",
	"Dr. Manuel Espinoza",
	"http://rgvisionmagazine.com/2010/01/dr-manuel-espinoza-medical-and-family-practice/",
	"Medical and Family Practice",
	"http://rgvisionmagazine.com/images/100102/features/espinoza.jpg"
);
featuredSections[1] = new Array(
	"Business Profile",
	"Veronica Gonzales",
	"http://rgvisionmagazine.com/2010/01/veronica-gonzales-state-representative/",
	"State Representative",
	"http://rgvisionmagazine.com/images/100102/features/gonzales.jpg"
);
featuredSections[2] = new Array(
	"Business Profile",
	"Delia Perez",
	"http://rgvisionmagazine.com/2010/01/delia-perez-associate-director-for-llano-grande-center/",
	"Associate Director for Llano Grande Center",
	"http://rgvisionmagazine.com/images/100102/features/perez.jpg"
);
featuredSections[3] = new Array(
	"Business Profile",
	"Jo Rae Wagner",
	"http://rgvisionmagazine.com/2010/01/jo-rae-wagner-predident-of-cto-commercial-plumbing/",
	"Predident of CTO Commercial Plumbing",
	"http://rgvisionmagazine.com/images/100102/features/wagner.jpg"
);
featuredSections[4] = new Array(
	"Medical Profile",
	"Dr. Alexander Sudarshan",
	"http://rgvisionmagazine.com/2010/01/dr-alexander-sudarshan-sudarshan-eye-experts/",
	"Sudarshan Eye Experts",
	"http://rgvisionmagazine.com/images/100102/features/sudarshan.jpg"
);

var nSections = featuredSections.length;
var currentSection = 1; // set initially to 1 to load second section in the bg

/*--------------------------------------------------------------------------------------*/


searchFocus = function () {
		document.getElementById('s').className = 'searchformActive';
		if (document.getElementById('s').value == 'Search RG Vision') {
			document.getElementById('s').value = '';
		}
}
searchBlur = function () {
		document.getElementById('s').className = 'searchformInactive';
		if (document.getElementById('s').value == '') {
			document.getElementById('s').value = 'Search RG Vision';
		}
}

// issue scroller code
var issues = new Array();

// image, link, text
issues[0] = new Array(
	"http://rgvisionmagazine.com/images/covers/thumbs/Issue1edition1.jpg",
	"javascript:;",
	"Jan/Feb 2009"
);
issues[1] = new Array(
	"http://rgvisionmagazine.com/images/covers/thumbs/Issue1edition2.jpg",
	"javascript:;",
	"Mar/Apr 2009"
);
issues[2] = new Array(
	"http://rgvisionmagazine.com/images/covers/thumbs/Issue1edition3.jpg",
	"javascript:;",
	"May/June 2009"
);
issues[3] = new Array(
	"http://rgvisionmagazine.com/images/covers/thumbs/Issue1edition4.jpg",
	"javascript:;",
	"July/Aug 2009"
);
issues[4] = new Array(
	"http://rgvisionmagazine.com/images/covers/thumbs/Issue1edition5.jpg",
	"javascript:;",
	"Sept/Oct 2009"
);
issues[5] = new Array(
	"http://rgvisionmagazine.com/images/covers/thumbs/Issue1edition6.jpg",
	"javascript:;",
	"Nov/Dec 2009"
);
issues[6] = new Array(
	"http://rgvisionmagazine.com/images/covers/thumbs/Issue1edition7.jpg",
	"javascript:;",
	"Jan/Feb 2010"
);

var currentIssue = issues.length - 1;


scrollIssue = function (direction) {
	if (direction == -1 && currentIssue > 0) {
		currentIssue--;
		populateIssue();
		document.getElementById('issueNext').style.display = '';
		if (currentIssue == 0) {
			document.getElementById('issuePrev').style.display = 'none';
		}
	}
	else if (direction == 1 && currentIssue < issues.length - 1) {
		currentIssue++;
		populateIssue();
		document.getElementById('issuePrev').style.display = '';
		if (currentIssue == issues.length - 1) {
			document.getElementById('issueNext').style.display = 'none';
		}		
	}
}
populateIssue = function () {
	document.getElementById('issue_cover').src = issues[currentIssue][0];
	document.getElementById('issue_link').href = issues[currentIssue][1];
	document.getElementById('issue_date').innerHTML = issues[currentIssue][2];
}

/*---- tracking ad clicks ---*/


function getHTTPObject() {
	if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest) return new XMLHttpRequest();	
	else {
		//alert("Your browser does not support AJAX.");
		return null;
	}
}
 
// Change the value of the outputText field
function setOutput(){
	return true;
}
 
// Implement business logic
function trackClick(element){
	httpObject = getHTTPObject();
	if (httpObject != null) {
		dst = element.href;
		src = document.location.href;
//		alert("?src="+src+"&dst="+dst);
		httpObject.open("GET", "http://rgvisionmagazine.com/wp-content/themes/rgvision/track_click.php?src="+src+"&dst="+dst, true);
		httpObject.send(null);
		httpObject.onreadystatechange = setOutput;
	}
}

var httpObject = null;
var src = null;
var dst = null;