﻿/// <reference path="jquery-1.2.6-vsdoc.js" />
$(document).ready(function () {
	$('#loading').hide();

	//category image click event
	$(".division img").click(function () {
		$(".division img").animate({ opacity: '0.25' }); //set opacity to all
		$("." + this.id).show(); //show only the related block
		$("#" + this.id).animate({ opacity: '1' }); //set the selected category image opactiy to 1
		$('#loading').show();
		location.href = "#loading";
		$('#tourlist').html("");
		//a cid with random data for IE only. It forces IE refresh the TourList.aspx
		$.get("../TourList.aspx", { division: getDivision(), subdivision: $(this).attr("id"), cid: Math.random() },
      function (data) {
      	//twice replace actions for replace name and ID. To replace the __Viewstate variable to avoid the conflict to the Main(container) page's viewstate. This for hacking IE too
      	data = data.replace("__VIEWSTATE", "nothing");
      	data = data.replace("__VIEWSTATE", "nothing");
      	$('#tourlist').html(data);
      	$('#loading').hide();

      	//hack for Chrome - it can't run the js code in TourList.aspx document.ready()
      	var is_webkit = navigator.userAgent.toLowerCase().indexOf('chrome') > -1 || navigator.userAgent.toLowerCase().indexOf('safari') > -1; ;
      	if (is_webkit) {
      		var arrSlide = $('.travel_slide');
      		var arrNav = $('.nav');
      		var i = 0;

      		$(".Block_Content").show(); //show all content block
      		for (i = 0; i < arrSlide.length; i++) {
      			$('#' + arrSlide[i].id).cycle({
      				fx: 'zoom', // fade, turnDown, shuffle, curtainX, zoom
      				speed: 'slow',
      				timeout: 4000,
      				pager: '#' + arrNav[i].id,
      				pagerAnchorBuilder: function (idx, slide) {
      					// return sel string for existing anchor
      					//return '.nav li:eq(' + (idx) + ') a';
      					return '<li><a href="#"><img src="' + slide.src + '" /></a></li>';
      				}
      			});
      		}

      		$('.Highlight ul').addClass("Highlightlist").css({ "list-style-image": "url('Images/star.gif')" });
      		//show all blocks' content to avoid the jumping 
      		$(".Block_Title").click(function () { $(this).next().slideToggle(); }); //pre-set the toggle effect
      		$(".Block_Content").hide(); //hide all content block

      	}
      }
    );
	});

});

function getDivision() {
	var url = location.href.split("/");
	var page = url[url.length - 2];
	var division;
	switch (page.toLowerCase()) {
		case "us_canada":
			division = "North America";
			break;
		case "europe":
			division = "Europe";
			break;
		case "asia":
			division = "Asia";
			break;
		case "packagetour":
			division = "PackageTours";
			break;
	}
	return division;
}


