// Javascript document
var gAjaxUrl = document.location.protocol + "//" + document.location.host + "/" + "saveaslave/ajax.php";
$(document).ready( function(){
	//$(".newscontainer").newsSlider( "news");
	initTripRouteModule();
	
	setInterval( "newsAnimation()", 5000 );
	/*******Lite box for Flag discription and Flag Enlarge *********/
	$("a#show_flag_description").click(function(){
	 $("#lightbox, #lightbox-panel").fadeIn(300);
	 })
	 $("a#close_flag_description").click(function(){
	 $("#lightbox, #lightbox-panel").fadeOut(300);
	 })

	$("a#show_enlarge_flag").click(function(){
	 $("#lightbox, #enlarged_flag").fadeIn(300);
	 })
	 $("a#close_enlarge_flag").click(function(){
	 $("#lightbox, #enlarged_flag").fadeOut(300);
	 })
	 
	 $("#showpaypal").click(function(){
		$("#giveusingpaypal, #lightbox").fadeIn(300);					
	})
	 $("a#closepaypal").click(function(){
	 $("#giveusingpaypal, #lightbox").fadeOut(300);
	 })
	 
	 $(".close_button").click(function(){
		$("#giveusingpaypal, #lightbox").fadeOut(300);
	});
	/************Lite box end**********/
	/**********showing content while clicking sidemenu********/
		 $(".country_reports ul li").click(function(){
	 	$(".country_reports ul li").removeClass();
		$(this).addClass("selectlink");
		
		var index = $('.country_reports ul li').index(this);
		$('.main_bottomright ul li').hide();
		$('.main_bottomright ul li').eq(index).fadeIn(1500);
	 });
	 
	 $('.main_bottomright ul li').hide();
	 $('.main_bottomright ul li').eq(0).show();
	 /******** End*******/
	 
	 $(".selectbox").change(function(){
		$(".selectbox option:selected").each(function (){
			var countryCode = $(this).val();
			if((countryCode!= null) && (countryCode != "") )
			{
					/*alert(countryCode);*/
					//window.location.href = "index.php?countrycode="+countryCode;
					window.location.href = gBaseUrl + gPageVar+"countrycode="+countryCode;
				
			}
		});								
	});	
});
function mCustomScrollbars(){
	 $("#mcs2_container").mCustomScrollbar("vertical",0,"easeOutCirc",1.05,"auto","yes","no",0);
}
$.fn.newsSlider = function( newsClassName ){
	var module = this;
	var moduleWidth = $(module).width() + $(module).css("padding");
	alert( $(module).find(" :first-child").className  );
	$(module).find("div.module_news").css("position", "relative").animate({
		left: "-=" + moduleWidth 						
	}, "slow", function(){
					$(this).find("first-child").appendTo($(module).find("div.module_news"));
				});
	setTimeout('$(".' + $(module).attr("class") + '").newsSlider( "' + newsClassName + '");', 5000 );						
}
function initTripRouteModule(){
	// init trip route module actions and events
	// origin boxes
	$("#origin").live('focus', function(e){
		if( $(this).val() == $(this).defaultValue ){
			//$(this).css('color', "#b7b7b7" );
			$(this).val("");
		} else {
			$(this).css('color', "#000000" );
		}
	});
	$("#origin").live('blur', function(e){
		if( $.trim( $(this).val() ) == "" ){
			//$(this).css('color', "#b7b7b7" );
			$(this).val($(this).defaultValue);
		} else {
			$(this).css('color', "#000000" );
		}
	});
	// destination boxes
	$("#destination").live('focus', function(e){
		if( $(this).value == $(this).defaultValue ){
			//$(this).css('color', "#b7b7b7" );
		} else {
			$(this).css('color', "#000000" );
		}
	});
	$("#destination").live('blur', function(e){
		if( $(this).value == $(this).defaultValue ){
			//$(this).css('color', "#b7b7b7" );
		} else {
			$(this).css('color', "#000000" );
		}
	});
	//alert( gAjaxUrl );
	var url = gAjaxUrl + "?module=triproute";
	// get directions button  event
	/*$(".getdirection").live('click', function(){
		$.ajax({
			  url: url
			, data: $("#direction_frm").serialize()
			, type: "post"
			, success: function(response){
				$("#direction_result").html( response );
			}
		})
	});*/
	$(".getdirection").live('click', function(){
		$("#map_triprouting").show();
			var start = document.getElementById("origin").value;
			var end = document.getElementById("destination").value;
			var request = {
				origin:start, 
				destination:end,
				travelMode: google.maps.DirectionsTravelMode.DRIVING
			};
			directionsService.route(request, function(response, status) {
			  if (status == google.maps.DirectionsStatus.OK) {
				directionsDisplay.setDirections(response);
			  }
			});
		});
		
	//Chat implementation
	$(".getaddonchat,.chatadd_on").click(function(){
		$(".getaddonchat").hide();									  
		$(".addonchat").show();									  
	});
	$(".closeaddonchat").click(function(){
		$(".addonchat").hide();
		$(".getaddonchat").show();
	});
}

//for News slider
function newsAnimation(){
	var liArray = $(".newscontainer .module_news .news");
	var width = 400;
	// alert( $(liArray).length * width );
	if( parseInt( $(".newscontainer .module_news").css("left")) <= - parseInt( ($(liArray).length - 1) * width ) ){
		return ;
	}
	$(".newscontainer .module_news").animate({
		left: "-=" + width +"px"
	}, {"duration": "fast", "complete":function(){
		var firstLi = $(liArray[0]);
		$(firstLi).appendTo( $(".newscontainer .module_news"));
		$(".newscontainer .module_news").css( "left", "-" + width + "px" );
	}});
}	

$.fn.newsSlider = function( newsClassName ){
	var module = this;
	var moduleWidth = $(module).width() + $(module).css("padding");
	//alert( $(module).find(" :first-child").className  );
	$(module).find("div.module_news").css("position", "relative").animate({
		left: "-=" + moduleWidth 						
	}, "slow", function(){
					$(this).find("first-child").appendTo($(module).find("div.module_news"));
				});
	setTimeout('$(".' + $(module).attr("class") + '").newsSlider( "' + newsClassName + '");', 5000 );						
}
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
	pageLanguage: 'en'
  }, 'google_translate_element');
}
