﻿var home_timer = '';
var home_old = '';
var place_title = 'delhi';
var latlng = '';
var adAPI = '';
var newsAPI = '';
var flickrAPI = '';
var youtubeAPI = '';
var holidayAPI = '';
var hotelAPI = '';
var place = '';

$(document).ready(function(){
	$("ul.tabs").tabs("div.panes > div");
	
	adAPI = $(".adpanes").scrollable({ size: 1 }).circular().mousewheel(400).autoscroll({ autoplay: true, api: true });
	newsAPI = $(".newspanes").scrollable({ size: 1, vertical: true }).circular().mousewheel(400).autoscroll({ autoplay: true, api: true });
	
	$('#list1a').accordion();
	
	originalTitle = $('document').attr('title');
	startChatSession();
	chatWith('voyazer');
	
	$('.hotels .boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'70px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'92px'},{queue:false,duration:160});
	});
	$('#tagbox').tagdragon({
		'field':'tags',
		'url':'/xml/places-list.php',
		'max':'5',
		'onSelectItem': function(val) { $('#placeid').val(val.id); }
	});
	
	$.ajax({
		url: "/xml/places.php?placeid=1",
		success: function(msg){
		   setHomeTabs(msg);
		}
   	});
	
});

function getPlaceData() {
	$.blockUI({ centerY: 0, message: 'loading tour guide.. please wait..', css: { 
            border: 'none', 
            padding: '15px',
			'font-size': '16px',
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff',
			top: '10px', 
			left: '', 
			right: '10px'
    } });
	var place_id = $('#placeid').val();
	$.ajax({
		url: "/xml/places.php?placeid="+place_id,
		success: function(msg){
		   setHomeTabs(msg);
		}
   	});
}

function setHomeTabs(tempPlace) {
	place = tempPlace;
	$("#myplace").html(place);
	
	$("#tabsplace").tabs('#panesplace > div' , {
		effect: 'fade'
	});
	tabAPI = $("#tabsplace").tabs();
	tabAPI.onClick(function(evt, tabIndex) {
		if (tabIndex == 1) {
			google.maps.event.trigger(map, 'resize'); 
			map.setZoom(map.getZoom());
			map.setCenter(latlng);
		}
	});
	
	flickrAPI = $(".homeimagepanes").scrollable({size: 6}).mousewheel(400).autoscroll({ autoplay: false, api: true });
	youtubeAPI = $(".homevideopanes").scrollable({size: 4}).mousewheel(400).autoscroll({ autoplay: false, api: true });
	holidayAPI = $(".homeholidaypanes").scrollable({size: 1}).mousewheel(400).autoscroll({ autoplay: false, api: true });
	hotelAPI = $(".homehotelpanes").scrollable({size: 1}).mousewheel(400).autoscroll({ autoplay: false, api: true });
	
	$("a.izoom").fancybox({
		'transitionIn'			: 'elastic',
		'transitionOut'			: 'elastic',
		'hideOnContentClick'	: false
	});
	$("a.vzoom").fancybox({
		'transitionIn'			: 'fade',
		'transitionOut'			: 'fade',
		'hideOnContentClick'	: false,
		'centerOnScroll'        : true,
		'autoDimensions'    	: false,
		'frameWidth'        	: 480,
		'frameHeight'       	: 295
	});	
	$.unblockUI();
}
function setDestination(place,lat,lon) {
	place_title = place;
	$.Juitter.start({
		searchType:"searchWord", 
		searchObject: place_title,
		lang:"en", 
		live:"live-15",
		placeHolder:"hometweetpanes", 
		loadMSG: "Loading gossips...", 
		total: 4, 
		readMore: " ", 
		nameUser:"image", 
		openExternalLinks:"newWindow", 
        filter:"sex->*BAD word*,porn->*BAD word*,fuck->*BAD word*"
	});
	
	var places = [ 
	  [place, lat, lon]
	]; 

	latlng = new google.maps.LatLng(places[0][1],places[0][2]);
	var myOptions = {
	 zoom: 4,
	 center: latlng,
	 mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	map = new google.maps.Map(document.getElementById("gmap"), myOptions);
	setMarkers(map, places); 
}

function setMarkers(map, locations) { 
	for (var i = 0; i < locations.length; i++) { 
		var place = locations[i]; 
		var myLatLng = new google.maps.LatLng(place[1], place[2]); 
		var marker = new google.maps.Marker({ 
			position: myLatLng, 
			map: map,
			title: place[0]
		}); 
	}

}

function home_menu_on(el_id){
	var current_menu = 0;
	current_menu = el_id.substr(4);
    if ($('#header').attr('class') != el_id){
        if ('' != home_timer){
            clearTimeout(home_timer);
            home_timer = '';
        }            

        if ('' == home_old){
            home_old = $('#header').attr('class');
        }    

        $('#header').attr('class' , el_id);

		to_exec = "if (home_old != '" + el_id + "') {$('#" + home_old + "-bg').fadeOut('slow'); $('#" + el_id + "-bg').fadeIn('slow');} home_old = '';";

		home_timer = setTimeout(to_exec, 1000);
		
		//$('#laptop_'+current_menu).fadeOut('slow');
    }
}

function home_menu_off(el){}

function home_menu_restore(){}

function nextNews() {
	newsAPI.pause();
	newsAPI.prev();
}

function prevNews() {
	newsAPI.pause();
	newsAPI.next();
}

function flickrNext() {
	flickrAPI.move(6);
}

function flickrPrev() {
	flickrAPI.move(-6);
}

function youtubeNext() {
	youtubeAPI.move(4);
}

function youtubePrev() {
	youtubeAPI.move(-4);
}

function holidayNext() {
	holidayAPI.move(1);
}

function holidayPrev() {
	holidayAPI.move(-1);
}

function hotelNext() {
	hotelAPI.move(1);
}

function hotelPrev() {
	hotelAPI.move(-1);
}

function submitEnquiry() {
	var _username = $("#username").val();
	var _email = $("#email").val();
	var _phone = $("#phone").val();
	var _message = $("#message").val();
	
	var hasError = false;
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

	if(_username == '' || _email == '' || _phone == '') {
		hasError = true;
		$("#form-error").html('Please check your form.');
	}
	if(!emailReg.test(_email)) {
		hasError = true;
		$("#form-error").html('Enter a valid email address.');
	}
	
	if(!hasError) {
		$.post("/xml/mail.php", { username: _username, email: _email, phone: _phone, message: _message },
			function(data){
				$("#enquiryForm").html('<h2>Request a callback</h2><br /><h3 style="margin-bottom:7px">Thankyou</h3><p>We have received your request. Please expect a callback within 2 hours.</p>');
		});
		return false;
	} else {
		return false;
	}
}
