var path = "";

function buildPath() {
	var url = location.href;
	if (url.indexOf(".com") != -1) {
		url = url.substring(url.indexOf(".com") + 5);
		while (url.indexOf("/") != -1) {
			path += "../";
			url = url.substring(url.indexOf("/") + 1);
		}
	}
};

buildPath();


YAHOO.namespace("VIT");

/** HEADER **/
YAHOO.VIT.Header = {
	init: function() {
		var html = "";
		html += "<!-- Header -->";
		html += "<div class='left'><a href='" + path + "'><img src='" + path + "images/logo_80.gif' alt='' class='logo-main' /></a></div>";
		html += "<div class='right'>";
		html += "<!-- Advertisement #4 -->";
		html += "<div id='advt4'></div>";
		html += "</div>";
		html += "<div class='clear'></div>";
		html += "<div class='row-space10'></div>";
		html += "<div class='navigation'>";
		html += "<div id='mainmenu' class='left'>"; 
		html += "<div class='bd'>";
		html += "<ul>";
		html += "<li class=''><a href='" + path + "'>Home</a></li>";
		html += "<li class=''><a href='" + path + "articles/'>Articles</a></li>";
		html += "<li class=''><a href='#'>Columns</a></li>";
		html += "<li class=''><a href='" + path + "eventscalendar/'>Events Calendar</a></li>";
		html += "<li class=''><a href='" + path + "businessdirectory/'>Business Directory</a></li>";
		html += "<li class='le'><a href='" + path + "about/'>About Us</a></li>";
		html += "</ul>";
		html += "</div>";
		html += "</div>";
		html += "<div class='clear'></div>";
		html += "</div>";
		
		YAHOO.util.Dom.get("header").innerHTML = html;
	}
}

YAHOO.util.Event.onContentReady("header", YAHOO.VIT.Header.init);


/** MAIN MENU **/
YAHOO.VIT.MainMenu = {
	init: function() {
		var oMenuBar = new YAHOO.widget.MenuBar("mainmenu", {autosubmenudisplay: false, hidedelay: 0, lazyload: true});
	
		var aSubmenuData = {
			id: "columns", 
			itemdata: [ 
				{ text: "Arts of India", url: path + "columns/artsofindia/" },
				{ text: "Ask The Short Sale - Loan Mod Guru", url: path + "columns/loanmodguru/" },
				{ text: "Dharma Express", url: path + "columns/dharmaexpress/" },
				{ text: "Innovative Pioneers of our Era", url: path + "columns/innovativepioneers/" },
				{ text: "Latest News &amp; Growth of the Valley", url: path + "columns/valleynews/" },
				{ text: "Live. Laugh. Eat!", url: path + "columns/livelaugheat/" },
				{ text: "Natural Healing with Homeopathy", url: path + "columns/homeopathy/" },
				{ text: "Plan My Event", url: path + "columns/planmyevent/" },
				{ text: "Seniors Corner", url: path + "columns/seniorscorner/" },
				{ text: "Square Pegs, Round Holes", url: path + "columns/drsachdev/" },
				{ text: "Thoughts &amp; Contemplations", url: path + "columns/jesal/" }
			]
		};
		
		oMenuBar.subscribe("beforeRender", function () {
		    if (this.getRoot() == this) {
		        this.getItem(2).cfg.setProperty("submenu", aSubmenuData);
		    }
		});
		
		oMenuBar.render();
	}
}

YAHOO.util.Event.onContentReady("mainmenu", YAHOO.VIT.MainMenu.init);


/** FOOTER **/
YAHOO.VIT.Footer = {
	init: function() {
		var html = "";
		html +="<div align='center'>";
		html +="<span class='copy'>&copy; 2010 Valley India Times</span>&nbsp;&nbsp;&#183;&nbsp;";
		html +="<a href='" + path + "terms/' class='footer'>Terms and Conditions</a>&nbsp;&nbsp;&#183;&nbsp;";
		html +="<a href='" + path + "contact/' class='footer'>Contact Us</a>&nbsp;&nbsp;&#183;&nbsp;";
		html +="<a href='" + path + "contact/advertise.html' class='footer'>Advertise with VIT</a>&nbsp;&nbsp;&#183;&nbsp;";
		html +="<a href='" + path + "contact/press.html' class='footer'>Send Press Releases</a>&nbsp;&nbsp;&#183;&nbsp;";
		html +="<a href='" + path + "contact/event.html' class='footer'>Send Event Information</a>"; 
		html +="</div>";
		
		YAHOO.util.Dom.get("footer").innerHTML = html;
	}
}

YAHOO.util.Event.onContentReady("footer", YAHOO.VIT.Footer.init);


/** ADVERTISEMENT **/
YAHOO.VIT.Advertisement = {
	/* Advt #1 (250 x 250) */
	advt1: {
		name: "advt1", timer: 10000,
		list: ["advt1_a.gif"],
		url: ["http://www.mybhod.com/"]
	},
	
	/* Advt #2 (250 x 100) */
	advt2: {
		name: "advt2", timer: 15000,
		list: ["advt2_a.jpg", "advt2_b.jpg"],
		url: ["http://www.asafsf.org/", "http://www.iaphx.org/"]
	},
	
	/* Advt #3 (960 x 120) */
	advt3: {
		name: "advt3", timer: 10000,
		list: ["advt3_a.jpg", "advt3_b.jpg"],
		url: ["http://www.marrow.org/", "http://www.valleyindiatimes.com/contact/advertise.html"]
	},
	
	/* Advt #4 (400 x 80) */
	advt4: {
		name: "advt4", timer: 10000,
		list: ["advt4_a.jpg"],
		url: ["http://www.unicef.org/"]
	},
	
	/* Advt #5 (300 x 600) */
	advt5: {
		name: "advt5", timer: 10000,
		list: ["advt5_a.jpg", "advt5_b.jpg"],
		url: ["http://www.facebook.com/group.php?gid=2201538332", ""]
	},
	
	/* Advt #6 (950 x 100) */
	advt6: {
		name: "advt6", timer: 10000,
		list: ["advt6_a.jpg", "advt6_b.jpg"],
		url: ["http://www.thebreastcancersite.com/clickToGive/home.faces?siteId=2", "http://usa.humanityfirst.org"]
	},
	
	/* Advt-VIT (300 x 60) */
	advt_vit: {
		name: "advt-vit", timer: 10000,
		list: [],
		url: []
	},
	
	init: function(advt, idx) {
		if (idx == undefined || idx == advt.list.length)
			idx = 0;
		
		var html = "";
		if (advt.url[idx].length > 0)
			html += "<div><a href='" + advt.url[idx] + "' target='_blank'><img src='" + path + "advertisement/" + advt.list[idx] + "' alt='' /></a></div>";
		else
			html += "<div><img src='" + path + "advertisement/" + advt.list[idx] + "' alt='' /></div>";
		
		YAHOO.util.Dom.get(advt.name).innerHTML = html;
		
		if (advt.list.length > 1)
			setTimeout(function(){YAHOO.VIT.Advertisement.init(advt, ++idx);}, advt.timer);
	}
}

YAHOO.util.Event.onContentReady("advt1", YAHOO.VIT.Advertisement.init, YAHOO.VIT.Advertisement.advt1);
YAHOO.util.Event.onContentReady("advt2", YAHOO.VIT.Advertisement.init, YAHOO.VIT.Advertisement.advt2);
YAHOO.util.Event.onContentReady("advt3", YAHOO.VIT.Advertisement.init, YAHOO.VIT.Advertisement.advt3);
YAHOO.util.Event.onContentReady("advt4", YAHOO.VIT.Advertisement.init, YAHOO.VIT.Advertisement.advt4);
YAHOO.util.Event.onContentReady("advt5", YAHOO.VIT.Advertisement.init, YAHOO.VIT.Advertisement.advt5);
YAHOO.util.Event.onContentReady("advt6", YAHOO.VIT.Advertisement.init, YAHOO.VIT.Advertisement.advt6);
//YAHOO.util.Event.onContentReady("advt-vit", YAHOO.VIT.Advertisement.init, YAHOO.VIT.Advertisement.advt_vit);


/** SUBMIT BUTTON **/
YAHOO.util.Event.onContentReady("btnSubmit", function() {
	var oSubmitButton = new YAHOO.widget.Button("btnSubmit");
	oSubmitButton.on("click", submitForm);
});


/** STRING PROTOTYPE **/
String.prototype.trim = function() {
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

