// JavaScript Document

/*Javascript for dealing with menu */
var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();
	// close old layer
	if(ddmenuitem) 
		ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';
	document.getElementById("maincolumn").style.zIndex = -1000;
}
// close showed layer
function mclose()
{
	if(ddmenuitem) 
		ddmenuitem.style.visibility = 'hidden';
	document.getElementById("maincolumn").style.zIndex = 0;
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 


/** Javascript for homepage masthead */
function promotionalDivAnimate(id)
{
	if(max_rotation_count <= 2)
		return;
	var div_id = "#dynamic-banner" + id;
	$(".dynamic-banner").hide();
	$("#dynamic-banner" + id).fadeIn("slow");
	$(".promotionalButton").removeClass("selected");
	$(".promotionalButton"+id).addClass("selected");
}

function updateCalendarView(month_id,key)
{
	//var url = "<?=$token->values[3]?>/eventcalendar";
	$(".left-column-month").removeClass("selected");
	$("#" + month_id).addClass("selected");
	
	window.location=url + "/2009/" + key;
}


function promotionalDivRotate(id)
{
	var div_id = ".dynamic-banner" + id;
	$(".dynamic-banner").hide();
	$(div_id).fadeIn("medium");

	id = id+1;
	var func_call = "promotionalDivRotate(";
	if(id>=max_rotation_count)
		func_call = func_call+1+")";
	else
		func_call = func_call+id+")";

	$(".promotionalButton").removeClass("selected");
	$(".promotionalButton"+id).addClass("selected");
	setTimeout(func_call,5000);	
}


/** Javascript for show hide block  e.g: history-legacy page */
var selected_block = 1;
function showMyInfo(theme_path,id)
{
	 var plus = theme_path + "images/plus.jpg";
	 var minus = theme_path + "images/plus.jpg";
	 if(selected_block != id)
	 {
    	 var faqid = "#faq" + id;
		 var image_path = "#faq" + id + "-title img";   	
		 var faq_title_txt = "#faq" + id + "-title_txt";
		 
		 $(".eg-bar").removeClass("selected");
		 $(faq_title_txt).addClass("selected");
		 
    	 $(".icongroup").slideUp("fast");
    	 $(faqid).slideDown("fast");
    	 $('.iconspan img').attr("src",plus); 
    	 $(image_path).attr("src",minus);
    	 selected_block = id; 
	 }
 	 else
	 {
    	 var faqid = "#faq" + id;
		 var image_path = "#faq" + id + "-title img";   	
		 var faq_title_txt = "#faq" + id + "-title_txt";
		 	
		 $(".eg-bar").removeClass("selected");
		 //$(faq_title_txt).addClass("selected");
		 
    	 $(".icongroup").slideUp("fast");
    	 $('.iconspan img').attr("src",minus); 
    	 selected_block = -1; 
	 }
}


$(document).ready(
		function(){
			if($("ul#portfolio").is('*')) {
				$('ul#portfolio').innerfade({
					speed: 1000,
					timeout: 5000,
					type: 'sequence',
					containerheight: '180px'
				});
			}
		}
	);



function showCorporateSponsorshipDiv()
{
	var category = document.getElementById("sponsorship_category").value
	$(".corporate-sponsorship").slideUp("fast");
	if( category != "-1" )	
	{
		var category_id = "#"+category;
		$(category_id).slideDown("fast");
	}			
}


/** High Res Image Request */

function sendHighResolutionImageRequest(site_path)
{
	var functionToCall = 'sendHighResolutionImageRequest';
	var call_url = site_path + "/ajaxcontent"
	
	$("#loader")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
	
	$.ajax({
			type: "POST",
			url: call_url,
			data: "functionToCall="+functionToCall+"&high_resolution_name="+$('#high_resolution_name').val()+"&high_resolution_email="+$('#high_resolution_email').val()+"&high_resolution_request_details="+$('#high_resolution_request_details').val(),
			success: function(msg){
				//$("#loader").hide();
				$("#details").html(msg);
				$("#details").slideDown("slow");	                                 
			}
		});
	resetForm("high_res_img_form");
	setTimeout('$("#results").slideUp("slow")',10000); 
}

function resetForm(id) {
	$('#'+id).each(function(){
	        this.reset();
	});
}
/* end */ 


/* hack writen for event calender to show dates beyond 2010*/
$(document).ready(function(){
	var prev_month = $('span.date-prev a').attr('href');
	//alert(prev_month);
	if( prev_month =='/eventcalendar/2011/11/all')	{
		$('span.date-next').html('<a id="nextMonthLinkCalendar" rel="nofollow" href="/eventcalendar/2012/01/all"><img src="http://www.ncpamumbai.com/themes/ncpa/images/next_button.jpg"></a>');
	}	
});
