jQuery.noConflict(); 
jQuery(document).ready(function(){
	// after load move call-me-back into tab Itinerary
	/*jQuery("#call-me-back-small").insertAfter("#itinery .product_main .right_colomb .product_lightbox");
	jQuery("#call-me-back-small").show();*/
	
	//show for all the rest
	/*
	jQuery(".inner_tab").click(function(){
		jQuery("#call-me-back-small").show();
		if(jQuery("#call-me-back-small").hasClass("moved_up")){
			jQuery("#call-me-back-small").removeClass("moved_up");
		}else if(jQuery("#call-me-back-small").hasClass("moved_up_more")){
			jQuery("#call-me-back-small").removeClass("moved_up_more");
		}
	});
	*/
	//hide on extend your stay tab
	jQuery(".extend").click(function(){
		jQuery("#call-me-back-small").hide();				
	});
	//hide on destination info
	jQuery(".destination_info").click(function(){
		jQuery("#call-me-back-small").hide();				
	});
	//move up when dates and prices are clicked
	/*
	jQuery(".prices").click(function(){
		if(jQuery('.interactive_link').attr('title') != null){
			jQuery("#call-me-back-small").addClass("moved_up_more");
		}else{
			jQuery("#call-me-back-small").addClass("moved_up");
		}
	});
	*/
	

		if(jQuery.browser.msie && jQuery.browser.version <= 7.0){
			/*jQuery('#similar-tours').addClass('ie7below');
			jQuery('#blogs').addClass('ie7below');*/
		};

	// Apri 2011 Tom, Alternative Tours Box
	if(jQuery('.side_google_map_box').length){

		jQuery('#similar-tours').addClass('with-map');
	};
	// Position Blogs
	//Check for existence of effecting divs
	/*
	if(jQuery('#similar-tours').length && jQuery('.side_google_map_box').length){

		jQuery('#blogs').addClass('with-maps-and-alternates');
	}else if (jQuery('#similar-tours').length){

		jQuery('#blogs').addClass('with-alternates');
	}else if(jQuery('.side_google_map_box').length){

		jQuery('#blogs').addClass('with-map');
	}else{
		//alert('neither');
	};
	*/

	jQuery("#add_tour").bind("click", function() {
		var url = jQuery(this).attr("href").replace("display_page=product", "display_page=none");
		
		try {
			/*jQuery.ajax({
				url: url,
				success: function(request, status){
					jQuery("#add_tour").hide();
					jQuery("#remove_tour").show();
					alert("Tour has been saved to My Tours.");
				}
			});*/
			jQuery(".working").width(jQuery("#container").width());
			jQuery(".working").height(jQuery("#container").height());
			jQuery(".working span").css("padding-top", 250);
			jQuery(".working").slideDown("normal");
			jQuery.ajax({
				url: url,
				success: function(request, status){
					jQuery("#add_tour").hide();
					jQuery("#remove_tour").show();
					jQuery(".working").slideUp("normal", function() {
						//alert("Tour has been saved to My Tours.");
					});
				}
			});
		}
		catch (error) {
		}
		return false;
	});
	
	jQuery("#remove_tour").bind("click", function() {
		var url = jQuery(this).attr("href").replace("display_page=product", "display_page=none");
		
		try {
			/*
			jQuery.ajax({
				url: url,
				success: function(request, status){
					jQuery("#remove_tour").hide();
					jQuery("#add_tour").show();
					alert("Tour has been removed from My Tours.");
				}
			});
			*/
			jQuery(".working").width(jQuery("#container").width());
			jQuery(".working").height(jQuery("#container").height());
			jQuery(".working span").css("padding-top", 250);
			jQuery(".working").slideDown("normal");
			jQuery.ajax({
				url: url,
				success: function(request, status){
					jQuery("#remove_tour").hide();
					jQuery("#add_tour").show();
					jQuery(".working").slideUp("normal", function() {
						//alert("Tour has been removed from My Tours.");
					});
				}
			});
		}
		catch (error) {
		}
		return false;
	});
	
//   loadDatesAndRates(false, '<xsl:value-of select="$product/bookable_online"/>', escape("<xsl:value-of select="$product/name"/>"));
   loadDestinationInfo();
   		jQuery('a[@rel=lightbox_1]').lightBox();
		jQuery('a[@rel=lightbox_2]').lightBox();
		jQuery('a[@rel=lightbox_3]').lightBox();
		jQuery('a[@rel=lightbox_4]').lightBox();
		jQuery('a[@rel=lightbox_accomm]').lightBox();
		jQuery('a[@rel=lightbox_maps]').lightBox();
	
		changeTab("itinery");
		jQuery("#extensions_javascript").show();
		jQuery("#prices_content_javascript").show();
		jQuery("#destionations_noscript").hide();
				
       switchTab(referer);
});

function show_google_map(tour_name,height,width){
	//load map data via ajax
	if (jQuery('#geocode_map').length > 0){
		tb_show(tour_name, '#TB_inline?height=540&width=705&inlineId=geocode_map',true);
		mapload(height,width);	
	}else{		
		jQuery(".clickgmap").text("Loading...");
		jQuery(".gmap_link").text("Loading...");		
		jQuery.ajax({
		url: '/content/mapdata.php?id='+jQuery('#product_id').val(),
		success: function(data){
			jQuery("#product_id").after(data);
			tb_show(tour_name, '#TB_inline?height=540&width=705&inlineId=geocode_map',true);
			mapload(height,width);
			jQuery(".clickgmap").text("Click Here");
			jQuery(".gmap_link").text("Interactive Map");		
		}
	});
	}	
	/*if(mapload(height,width)){
		tb_show(tour_name, '#TB_inline?height=540&width=705&inlineId=geocode_map',true);
	}*/
}

function show_image_map(){
	tb_show('Tour Map','#TB_inline?height=490&width=540&inlineId=image_map',true);
}

var map_state = null;

// This array contains calls of functions, which cannot be called in tight loop.
// If they are, Google API will return G_GEO_TOO_MANY_QUERIES.
var actions_to_perform = [];

// This variable indicates how many unprocessed actions are in array actions_to_perform
var number_of_actions = 0;

// This variable contains index of the first unprocessed action in array actions_to_perform
var first_action = 0;

// This variable contains index of the last unprocessed action in array actions_to_perform
var last_action = -1;

// Variable current_delay holds curent delay between two actions.
// If Google API returns G_GEO_TOO_MANY_QUERIES, this delay is increased by current_step_delay.
var current_delay = 100;
var current_step_delay = 2;

// This variable holds success status of performed action. It is true by default.
// If any error occurs, it is set to false by error handler.
var action_success = true; 

// This function will add one action to array actions_to_perform
function addActionToPerform(action_name,parameter1,parameter2,parameter3,parameter4)
{
	last_action++;
	number_of_actions++;

	var action_array = [];
	action_array[0] = action_name;
	action_array[1] = parameter1;
	action_array[2] = parameter2;
	action_array[3] = parameter3;
	action_array[4] = parameter4;

	actions_to_perform[last_action] = action_array;
}

// this function performs first unperformed action from array actions_to_perform
function performAction()
{
	if(number_of_actions < 1)
		return false;

	action_success = true;
	var action_array = actions_to_perform[first_action];
	action_name = action_array[0];

	/*if(action_name == "addMarker")
	{
		map_state.addMarker(action_array[1]);
	} else if(action_name == "addRandomMarker")
	{
		map_state.addRandomMarker(action_array[1],action_array[2],action_array[3],action_array[4]);
	} else if(action_name == "addQuickSequenceMarker")
	{
		map_state.addQuickSequenceMarker(action_array[1]);
	} else */
	
	if(action_name == "addQuickLine")
	{
		map_state.addQuickLine(action_array[1]);
	} else if(action_name == "addRndMarkerLine")
	{
		map_state.addRndMarkerLine(action_array[1]);
	} else {
		alert("Uknown action to perform");
		// action_success is not set to false. This action is just skipped.
	}
}

function scheduleAction()
{
	if(number_of_actions > 0)
	{
		// Schedule performing of next action
		setTimeout("performAction()", current_delay);
	}	
}

function removeAction()
{
		actions_to_perform[first_action] = null;
		first_action++;
		number_of_actions--;
}

//google map object
var map = null;

// This function will load the map.
// Be careful when using it. Actions performed by this function are scheduled by setTimeout and therefore,
// some actions can still be uncomplete when this function exits.
function mapload(height,width)
{
	if (GBrowserIsCompatible())
    {
		map = new GMap2(document.getElementById("map"),{size: new GSize(width,height)}); 
		
        //geocoder = new GClientGeocoder();            
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.enableScrollWheelZoom();
        
        
        var set = false;
        var saved_center_geo_code = jQuery('#saved_mapcenter').val().split(",");
        if(saved_center_geo_code.length == 5){
        	//center geo code not set
        	var latetude = parseFloat(saved_center_geo_code[0]);
    		var longetude = parseFloat(saved_center_geo_code[1]);
    		var accuracy = parseInt(saved_center_geo_code[2]);
    		var zoom = parseInt(saved_center_geo_code[3]);
    		var map_type = saved_center_geo_code[4];
    		//console.log('hier2');   		
    		switch(map_type){
    			case 'Map': map.setMapType(G_NORMAL_MAP);
    			break;
    			case 'Satellite' : map.setMapType(G_SATELLITE_MAP);
    			break;
    			case 'Hybrid' : map.setMapType(G_HYBRID_MAP);
    			break;
    			default:map.setMapType(G_NORMAL_MAP);
    		}
    		map.setCenter(new GLatLng(latetude,longetude), zoom);
    		set = true;
        }else{
        	//alert('no valid geo code set');
        }      
        
        //place map center to first item with geo_code set if no saved mapcenter was found
        if(set == false){
	        jQuery('#marker_places_direct li').each(function(){
	        	if(jQuery(this).attr('class') == 'geo_not_set'){
	        		return;
	        	}
	        	if(jQuery(this).attr('geo_code')){
	        		var code = jQuery(this).attr('geo_code').split(",");
	        		var latetude = parseFloat(code[0]);
	        		var longetude = parseFloat(code[1]);
	        		var accuracy = parseInt(code[2]);
	        		var zoom = parseInt(code[3]);
	        		if(zoom > 1){
	        			zoom = zoom - 1;
	        		}
	        		map.setCenter(new GLatLng(latetude,longetude), zoom);
	        		set = true;
	        		//a geo code is found so now break the loop
	        		return false;
	        	}
	        });
        }
        if(!set){
	        //default location in case none of the list items has a geocode and no center geo code was found
	        map.setCenter(new GLatLng(53.330873,-3.867187), 5);
        }
        //initilize map state
        map_state = new MyMap();
               
        //checks to see if there are any saved markers and load them into the map
        var saved_markers = jQuery('#saved_markers li');
        if(saved_markers.length > 0){
        	//alert('loading saved markers');
        	saved_markers.each(function(){
        		var place_id = jQuery(this).attr('place_id');
        		var icon = parseInt(trim(jQuery(this).html()," ").replace('icon_',''));
        		//console.log(place_id);
        		//console.log(icon);
        		
        		var place = jQuery('#place_marker_' + place_id);
        		var geocode = place.attr('geo_code').split(',');
        		var type = place.attr('type');
        		var name = jQuery('.name',place).html();
        		var place_point = new Point(new GLatLng(geocode[0],geocode[1]));
        		//console.log(marker_point);
        		var seo_tag = place.attr('seo_tag');
    			var intro = place.attr('intro');
    			if(intro == undefined){
    				intro = null;
    			}
    			//seo_images
    			var seo_images = new Array();
    			jQuery('.seo_image',place).each(function(){
    				var seo_image_id = jQuery(this).attr('id');
    				var last_underscore = seo_image_id.lastIndexOf('_');
    				seo_image_id = parseInt(seo_image_id.substr(last_underscore+1));
    				var name = jQuery(this).attr('image_name');
    				var url = jQuery(this).attr('image_url');
    				var height = jQuery(this).attr('height');
    				var width = jQuery(this).attr('width');
    				var caption = jQuery(this).attr('caption');
    				var seo_image = new SeoImage(seo_image_id,name,url,height,width,caption);
    				seo_images.push(seo_image);
    			});
    			//console.log(seo_images);
    			var place_marker = new Marker(place_id,place_point,icon,name,intro,seo_images,seo_tag);
    			//console.log(place_marker);
    			var marker_id = map_state.addMarker(place_marker);
          //addActionToPerform("addMarker",place_marker,null,null,null);
        	});
        }
        
        //checks to see if there are any saved random markers and load them into the map
        var saved_random_markers = jQuery('#saved_random_markers li');
        if(saved_random_markers.length > 0){
        	//alert('loading saved markers');
        	saved_random_markers.each(function(){
        		var geo_code = jQuery(this).attr('geo_code');
        		var lat = geo_code.substr(0,geo_code.indexOf(","));
        		var length = geo_code.length - geo_code.indexOf(",");
        		var lng = geo_code.substr(geo_code.indexOf(",")+1,length);
        		var title = jQuery(this).attr('title');
        		var body = jQuery(this).attr('body');
        		var icon = trim(jQuery(this).html()," ");
        		var icon_substlength = icon.length - (icon.indexOf("_")+1);
        		var icon_type = icon.substr(icon.indexOf("_")+1 , icon_substlength);
        		//alert('icon_type :'+ icon_type + "@@");
        		
        		var point = new GLatLng(parseFloat(lat), parseFloat(lng));
        		var marker_id = map_state.addRandomMarker(point,parseInt(icon_type),title,body);
            //addActionToPerform("addRandomMarker",point,parseInt(icon_type),title,body);
        	});
        }
        
        //checks to see if there are any saved quick sequenced markers and load them into the map
        var saved_quick_sequenced_markers = jQuery('#saved_quick_sequenced_markers li');
        if(saved_quick_sequenced_markers.length > 0){
        	//alert('loading saved markers');
        	saved_quick_sequenced_markers.each(function(){        		
        		var geo_code = jQuery(this).html();
        		var lat = geo_code.substr(0,geo_code.indexOf(","));
        		var length = geo_code.length - geo_code.indexOf(",");
        		var lng_num = geo_code.substr(geo_code.indexOf(",")+1,length);
        		var lng = lng_num.substr(0,lng_num.indexOf(","));
        		var lng_num_length = lng_num.length - lng_num.indexOf(",");
        		var num = lng_num.substr(lng_num.indexOf(",")+1,lng_num_length);
        		var place_id = parseInt(jQuery(this).attr('place_id'));
        		var icon_type = jQuery(this).attr('icon_type');
        		var quick_sequence_point = new Point(new GLatLng(lat,lng));        		
        		var place = jQuery('#place_marker_' + place_id);
        		var name = jQuery('.name',place).html();
    			var seo_tag = place.attr('seo_tag');
    			var intro = place.attr('intro');
    			if(intro == undefined){
    				intro = null;
    			}
    			//seo_images
    			var seo_images = new Array();
    			jQuery('.seo_image',place).each(function(){
    				var seo_image_id = jQuery(this).attr('id');
    				var last_underscore = seo_image_id.lastIndexOf('_');
    				seo_image_id = parseInt(seo_image_id.substr(last_underscore+1));
    				var name = jQuery(this).attr('image_name');
    				var url = jQuery(this).attr('image_url');
    				var height = jQuery(this).attr('height');
    				var width = jQuery(this).attr('width');
    				var caption = jQuery(this).attr('caption');
    				var seo_image = new SeoImage(seo_image_id,name,url,height,width,caption);
    				seo_images.push(seo_image);
    			});    			
        		var quick_sequence_marker = new Marker(place_id,quick_sequence_point,icon_type,name,intro,seo_images,seo_tag);
        		quick_sequence_marker.number = num;
        		//console.log(quick_sequence_marker);
        		map_state.addQuickSequenceMarker(quick_sequence_marker);
            //addActionToPerform("addQuickSequenceMarker",quick_sequence_marker,null,null,null);
        	});
        }
        
        //saved line color
        var saved_color = null;
        //check if there exists a saved quick lines and populate the map with the saved map data
        var saved_quick_lines = jQuery('#saved_quick_lines li');
        if(saved_quick_lines.length > 0){
        	var previous_color = null;
        	var sequenced = false;
        	var gdir_lines = false;
        	saved_quick_lines.each(function(){
        		
        		var start_place_id = jQuery(this).attr('start_place_id');
        		var end_place_id = jQuery(this).attr('end_place_id');
        		//console.log('loading saved lines : '+ start_place_id + ' -- ' + end_place_id);
        		var start_geo_code = jQuery('#place_marker_' + start_place_id).attr('geo_code').split(",");
        		var start_latetude = parseFloat(start_geo_code[0]);
        		var start_longetude = parseFloat(start_geo_code[1]);
        		var start_accuracy = parseInt(start_geo_code[2]);
        		var start_zoom = parseInt(start_geo_code[3]);
        		
        		var start_point = new Point(new GLatLng(start_latetude, start_longetude));
        		var start_place_li = jQuery('#place_marker_' + start_place_id);
        		var start_place_name = jQuery('.name',start_place_li).html();
        		
        		var end_geo_code = jQuery('#place_marker_' + end_place_id).attr('geo_code').split(",");
        		var end_latetude = parseFloat(end_geo_code[0]);
        		var end_longetude = parseFloat(end_geo_code[1]);
        		var end_accuracy = parseInt(end_geo_code[2]);
        		var end_zoom = parseInt(end_geo_code[3]);
        		
        		var end_point = new Point(new GLatLng(end_latetude, end_longetude));
        		var end_place_name = jQuery('.name',jQuery('#place_marker_' + end_place_id)).html();        		
        		
        		var line_color = jQuery(this).attr('color');
        		saved_color = line_color;
        		var line_type = trim(jQuery(this).html()," ");
        		
        		var start_place = new Place(start_place_id,start_point,start_place_name);
        		var end_place = new Place(end_place_id,end_point,end_place_name);        		
        		//console.log('adding line');
        		var line = new Line(start_place, end_place, line_color, line_type);
        		//console.log(line);
//            	var line_index = map_state.addQuickLine(line);
            	addActionToPerform("addQuickLine",line,null,null,null);
        	});  	
        	
        	//check if there exists a saved quick lines and populate the map with the saved map data
            var saved_random_marker_lines = jQuery('#saved_random_marker_lines li');
            if(saved_random_marker_lines.length > 0){
            	saved_random_marker_lines.each(function(){
            		//alert('loading saved lines');
            		var start_place_id = jQuery(this).attr('start_place_id');
            		//console.log(start_place_id);
            		var end_marker_geocode = jQuery(this).attr('end_marker_geocode').split(',');
            		
            		var start_geo_code = jQuery('#place_marker_' + start_place_id).attr('geo_code').split(",");
            		var start_latetude = parseFloat(start_geo_code[0]);
            		var start_longetude = parseFloat(start_geo_code[1]);
            		var start_accuracy = parseInt(start_geo_code[2]);
            		var start_zoom = parseInt(start_geo_code[3]);
            		
            		var start_point = new Point(new GLatLng(start_latetude, start_longetude));
            		var start_place_li = jQuery('#place_marker_' + start_place_id);
            		var start_place_name = jQuery('.name',start_place_li).html();            		
            		
            		var end_latetude = parseFloat(end_marker_geocode[0]);
            		var end_longetude = parseFloat(end_marker_geocode[1]);
            		
            		
            		var line_color = jQuery(this).attr('color');
            		
            		var line_type = trim(jQuery(this).html()," ");
            		
            		var start_place = new Place(start_place_id,start_point,start_place_name);
            		//var end_place = new Place(end_place_id,end_point,end_place_name);
            		//now locate the marker
            		var all_rndmarkers = map_state.getRandomMarkers();
            		for(var i=0;i < all_rndmarkers.length;i++){
            			if(all_rndmarkers[i].getLatLng().lat() == end_latetude && all_rndmarkers[i].getLatLng().lng() == end_longetude){
            				//console.log('found marker : ' + i);
            				var rnd_mrk_line = new RndMarkerLine(start_place,all_rndmarkers[i],line_color,line_type);
//            				var line_index = map_state.addRndMarkerLine(rnd_mrk_line);
			            	addActionToPerform("addRndMarkerLine",rnd_mrk_line,null,null,null);
            			}
            		}
            		
            	});
            }
        	
        }

		if(number_of_actions > 0)
		{
			// Start performing of scheduled actions
			performAction();
		}
    }else{
    	alert('Error: Web browser is incompatible with Google Maps');
    }
	return true;
}

function streetview(){
	map_state.streetview();
}

function hide_streetview(){
	map_state.hide_streetview();
}

SeoImage.prototype.constructor = SeoImage;
function SeoImage(id,n,u,h,w,c)
{
	this.image_id = id;
	this.name=n;
	this.url=u;
	this.height = h;
	this.width = w;
	this.caption = c;
}
//abstract class
MapItem.prototype.constructor = MapItem;
function MapItem()
{
	//abstract class
}
//Points class inherets from MapItem
Point.prototype = new MapItem();
Point.prototype.baseClass = MapItem.prototype.constructor;
Point.prototype.constructor = Point;
function Point( p )
{
    this.geocode = p;
}
Point.prototype.getGeoCode = function()
{
	return this.geocode;
};
Point.prototype.setGeoCode = function(p)
{
	var geo_code = new GLatLng(p.lat(),p.lng());
	this.geocode = geo_code;
};
//Place class inherets from MapItem
Place.prototype = new MapItem();
Place.prototype.baseClass = MapItem.prototype.constructor;
Place.prototype.constructor = Place;
function Place( p_id,p,n)
{
	this.id = p_id;
	this.point = p;
	this.name = n;
}
Place.prototype.getID = function()
{
	return this.id;
};
Place.prototype.getPoint = function()
{
	return this.point;
};
Place.prototype.getName = function()
{
	return this.name;
};
//Marker class inherets from MapItem
Marker.prototype = new MapItem();
Marker.prototype.baseClass = MapItem.prototype.constructor;
Marker.prototype.constructor = Marker;
function Marker( pos_id,p,icn,n,intr,s_i,s_tag )
{
	if(pos_id == null){
    	alert('Error: Missing marker id');
    }
	if(p == null){
    	alert('Error: Missing marker position');
    }
	if(icn == null){
    	alert('Error: Invalid icon type');
    }
	this.id = pos_id;
	this.point = p;
    this.icon = parseInt(icn);
    this.name = n;
    this.intro = intr;
    this.seo_images = s_i;
    this.seo_tag = s_tag;
}
Marker.prototype.getID = function()
{
	return this.id;
};
Marker.prototype.getPoint = function()
{
	return this.point;
};
Marker.prototype.getIcon = function()
{
	return this.icon;
};
Marker.prototype.getName = function()
{
	return this.name;
};
Marker.prototype.getIntro = function()
{
	return this.intro;
};
Marker.prototype.getSeoImages = function()
{
	return this.seo_images;
};
Marker.prototype.getSeoTag = function()
{
	return this.seo_tag;
};

//Lines class inherets from MapItem
Line.prototype = new MapItem();
Line.prototype.baseClass = MapItem.prototype.constructor;
Line.prototype.constructor = Line;
function Line( p1, p2, c, t )
{
    this.start_place = p1;
    this.end_place = p2;
    this.color = c;
    this.type = t;
}
Line.prototype.getPlace = function(index)
{
	if(index >= 0 && index < 2){
		if(index == 0){
			return this.start_place;
		}else{
			return this.end_place;
		}
	}else{
		alert('Error: Invalid line index');
	}
};
Line.prototype.getColor = function()
{
    return this.color;
};
Line.prototype.getType = function()
{
    return this.type;
};
Line.prototype.setColor = function(c)
{
    this.color = c;
};
Line.prototype.setType = function(t)
{
    this.type = t;
};
//RndMarkerLines class inherets from MapItem
RndMarkerLine.prototype = new MapItem();
RndMarkerLine.prototype.baseClass = MapItem.prototype.constructor;
RndMarkerLine.prototype.constructor = RndMarkerLine;
function RndMarkerLine( p1, p2, c, t )
{
    this.start_place = p1;
    this.end_marker = p2;
    this.color = c;
    this.type = t;
}
//this is how this is diffrerent from normal line
RndMarkerLine.prototype.getPlace = function(index)
{
	if(index >= 0 && index < 2){
		if(index == 0){
			return this.start_place;
		}else{
			return this.end_marker;
		}
	}else{
		alert('Error: Invalid line index');
	}
};
RndMarkerLine.prototype.getColor = function()
{
    return this.color;
};
RndMarkerLine.prototype.getType = function()
{
    return this.type;
};
RndMarkerLine.prototype.setColor = function(c)
{
    this.color = c;
};
RndMarkerLine.prototype.setType = function(t)
{
    this.type = t;
};


var polylines = [];
var rndmrk_polylines = [];
var quick_polylines = [];
var g_markers = [];
var g_markers_sequenced = [];
var g_markers_quick_sequenced = [];
//streetview
var svOverlay = null;
var myPano = null;   
var panoClient = null;
var streetview_clickListener = null;

function MyMap(){
	this.lines = [];
	this.directions = [];
	this.rndmrk_lines = [];
	this.rndmrk_directions = [];
	this.quick_lines = [];
	this.quick_directions = [];
	this.markers = [];
	this.random_markers = [];
	this.marker_listeners = [];
	this.sequenced_markers = [];
	this.quick_sequenced_markers = [];
	
	//add quick line to map, returns line index in array
	this.addQuickLine = function(l){
		this.quick_lines.push(l);
		//console.log('add quick line');
		//console.log(l);
		var line_index = parseInt(this.quick_lines.length-1);
		var line_points = new Array();
		line_points.push(l.start_place.getPoint().getGeoCode());
		line_points.push(l.end_place.getPoint().getGeoCode());
		this.quick_lines[line_index].line_id = line_index;
		var line_type = l.type;
		if(line_type == 'gdirections' || line_type == 'gdirections_sequenced'){
			this.quick_directions[line_index] = new GDirections();
			this.quick_directions[line_index].color = l.color;
			this.quick_directions[line_index].line_id = parseInt(this.quick_lines.length-1);			
			GEvent.addListener(this.quick_directions[line_index], "load", onQuickGDirectionsLoad);
			GEvent.addListener(this.quick_directions[line_index], "error", quickHandleErrors);
			this.quick_directions[line_index].loadFromWaypoints(line_points,{getPolyline:true});
		}else if(l.type == 'gpolyline' || line_type == 'gpolyline_sequenced'){
			var polyline = new GPolyline(line_points, l.color, 3,1);
			quick_polylines[line_index] = polyline;
			map.addOverlay(quick_polylines[line_index]);
			removeAction(); performAction(); // perform next action immediatelly
		}else if(l.type == 'gpolyline_arrow' || line_type == 'gpolyline_arrow_sequenced'){			
			var arrow_line = new BDCCArrowedPolyline(line_points,l.color,3,0.8,null,1,7,l.color,2,1.0);
			quick_polylines[line_index] = arrow_line;
			map.addOverlay(quick_polylines[line_index]);
			removeAction(); performAction(); // perform next action immediatelly
		}
		return this.quick_lines.length - 1;
	};
	//add line to map, returns line index in array
	this.addRndMarkerLine = function(l){
		this.rndmrk_lines.push(l);
		var line_index = parseInt(this.rndmrk_lines.length-1);
		var line_points = new Array();
		var start_point = l.start_place.getPoint().getGeoCode();
		var end_point = l.end_marker.getLatLng();
		line_points.push(start_point);
	    line_points.push(end_point);
	    
	    var line_type = l.type;
	    if(line_type == 'gdirections'){
	    	this.rndmrk_directions[line_index] = new GDirections();
	    	this.rndmrk_directions[line_index].color = l.color;
	    	this.rndmrk_directions[line_index].line_id = parseInt(this.rndmrk_lines.length-1);	    	
			GEvent.addListener(this.rndmrk_directions[line_index], "load", onRndMrkGDirectionsLoad);
	        GEvent.addListener(this.rndmrk_directions[line_index], "error", handleRndMrkErrors);
	        this.rndmrk_directions[line_index].loadFromWaypoints(line_points,{getPolyline:true});
		}else if(l.type == 'gpolyline'){
			var polyline = new GPolyline(line_points, l.color, 3,1);
			rndmrk_polylines[line_index] = polyline;
			map.addOverlay(rndmrk_polylines[line_index]);
		}
		return this.rndmrk_lines.length - 1;
	};
	
	//add marker to map, returns line index in array
	this.addMarker = function(m){
		//alert(this.current_server_url);
		this.markers.push(m);
		//default google icon		
		if(m.getIcon() == 0){
			var g_icon = new GIcon(G_DEFAULT_ICON);
			markerOptions = { icon:g_icon };
			var point =  m.getPoint();
			var latlng = point.getGeoCode();
			var marker = new GMarker(latlng, markerOptions);
			GEvent.addListener(marker, "click", function() {
				var current_server_url = 'http://' + jQuery('#cur_server_url').val();
				var seo_page_url = current_server_url + '/' + m.getSeoTag();
				//alert(seo_page_url);
				var info_window_html = '<div class="marker_popup"><b>' + m.getName() + '</b><br />View all <a href="' + seo_page_url + '">' + m.getName() + '</a> holidays<br /><table><tr>';
				var marker_images = m.getSeoImages();
				if(marker_images.length > 0){
					//console.log(marker_images);
					info_window_html += '<td width="135" valign="top"><div id="marker_images">';
					/*for(var i = 0;i < marker_images.length;i++){*/
					//only show first image
						info_window_html += '<img alt="' + marker_images[0].caption + '" ';
						info_window_html += 'src="' + marker_images[0].url + '" ';
						//image is added half original size
						info_window_html += 'width="' + marker_images[0].width / 2 + '" ';
						info_window_html += 'height="' + marker_images[0].height / 2 + '" />';
					/*}*/
					info_window_html += '</div></td>';
				}
				if(m.getIntro() != null){
					if(m.getIntro().length == 302 || m.getIntro().length == 303 ){
						info_window_html += '<td valign="top" width="240" height="140"><div id="marker_intro">' + m.getIntro() + '<a href="'+ seo_page_url + '"> more</a></div></td></tr></table>';
					}else{
						info_window_html += '<td valign="top" width="240" height="140"><div id="marker_intro">' + m.getIntro() + '</div></td></tr></table>';
					}
				}				
				info_window_html += '</div>';
				//alert(info_window_html);
	            marker.openInfoWindowHtml(info_window_html,{ maxWidth: 400 });
	        });
			g_markers.push(marker);		
			map.addOverlay(g_markers[g_markers.length-1]);
		}else{
			//set up custom icon
			var image_name = "/content-styles/images/gmap/icons/icon_" + m.getIcon() + ".png";
			var image_shadow_name = "/content-styles/images/gmap/icons/icon_" + m.getIcon() + "_shadow.png";
			//alert(image_name);
			//alert(image_shadow_name);
			var cus_icon = new GIcon(G_DEFAULT_ICON);
			cus_icon.image = image_name;
			cus_icon.shadow = image_shadow_name;
			cus_icon.iconSize = new GSize(20, 27);
			cus_icon.shadowSize = new GSize(34, 27);
			cus_icon.iconAnchor = new GPoint(0, 27);
			markerOptions = { icon:cus_icon };
			//add marker to map
			var point =  m.getPoint();
			var latlng = point.getGeoCode();
			var marker = new GMarker(latlng, markerOptions);
			GEvent.addListener(marker, "click", function() {
				var current_server_url = 'http://' + jQuery('#cur_server_url').val();
				var seo_page_url = current_server_url + '/' + m.getSeoTag();
				//alert(seo_page_url);
				var info_window_html = '<div class="marker_popup"><b>' + m.getName() + '</b><br />View all <a href="'+ seo_page_url + '">' + m.getName() + '</a> holidays<br /><table><tr>';
				var marker_images = m.getSeoImages();
				if(marker_images.length > 0){
					//console.log(marker_images);
					info_window_html += '<td width="135" valign="top"><div id="marker_images">';
					/*for(var i = 0;i < marker_images.length;i++){*/
					//only show first image
						info_window_html += '<img alt="' + marker_images[0].caption + '" ';
						info_window_html += 'src="' + marker_images[0].url + '" ';
						//image is added half original size
						info_window_html += 'width="' + marker_images[0].width / 2 + '" ';
						info_window_html += 'height="' + marker_images[0].height / 2 + '" />';
					/*}*/
					info_window_html += '</div></td>';
				}
				if(m.getIntro() != null){
					if(m.getIntro().length == 302 || m.getIntro().length == 303 ){
						info_window_html += '<td valign="top" width="240" height="140"><div id="marker_intro">' + m.getIntro() + '<a href="'+ seo_page_url + '"> more</a></div></td></tr></table>';
					}else{
						info_window_html += '<td valign="top" width="240" height="140"><div id="marker_intro">' + m.getIntro() + '</div></td></tr></table>';
					}
				}				
				info_window_html += '</div>';
				//alert(info_window_html);
	            marker.openInfoWindowHtml(info_window_html,{ maxWidth: 400 });
	        });
			g_markers.push(marker);		
			map.addOverlay(g_markers[g_markers.length-1]);
		}
		
		return this.markers.length - 1;
	};
	
	//adds a marker to any location the user decides to click on the map
	this.addRandomMarker = function(point,icon_type,title,body){
		
		var g_icon = new GIcon(G_DEFAULT_ICON);
		if(icon_type > 0){
			var image_name = "/content-styles/images/gmap/icons/icon_" + icon_type + ".png";
			var image_shadow_name = "/content-styles/images/gmap/icons/icon_" + icon_type + "_shadow.png";
			//alert(image_name);
			g_icon.image = image_name;
			g_icon.shadow = image_shadow_name;
			g_icon.iconSize = new GSize(20, 27);
			g_icon.shadowSize = new GSize(34, 27);
			g_icon.iconAnchor = new GPoint(0, 27);
			g_icon.infoWindowAnchor = new GPoint(10.0, 17.0);
		}
		markerOptions = { icon:g_icon };
	    var marker = new GMarker(point, markerOptions);
	    if(title){
	    	marker.title_text = title;
	    }else{
	    	marker.title_text = '';
	    }
	    if(body){
	    	marker.body_text = body;
	    }else{
	    	marker.body_text = '';
	    }
	    //alert(point + ' -- ' + icon_type + ' -- ' + title + ' -- ' + body + ' -- ' + trigger_click);
	    marker.id = parseInt(this.random_markers.length);
	    marker.icon_type = icon_type;
	    var marker_listener = GEvent.addListener(marker, 'click', function() {
	    	//alert(this.title_text);
			//alert(this.body_text);
			var popup_container = jQuery('<div></div>');
	    	//now add the preview to the info window
	    	var preview = jQuery('<div id="marker_text_preview"></div>');	    	
	    	var preview_title = jQuery('<h3>'+this.title_text+'</h3>');
	    	preview_title.appendTo(preview);
	    	preview.append('<br />');
	    	var preview_body = jQuery('<div class="rnd_mrkerbody">'+this.body_text+'</div>');
	    	preview_body.appendTo(preview);
	    	preview.appendTo(popup_container);
	    	//alert(popup_container.html());
	    	this.openInfoWindow(popup_container.html());
	    });	   
	    this.random_markers.push(marker);
	    this.marker_listeners.push(marker_listener);
	    map.addOverlay(this.random_markers[this.random_markers.length-1]);
	   
	    return this.random_markers.length-1;
	};
	
	//adds a sequence marker to the map
	this.addQuickSequenceMarker = function(m){
		//alert(this.current_server_url);
		this.quick_sequenced_markers.push(m);
		var icon_number = m.number;
		//set up custom 
		//rewrite rule in .htaccess file to generate the sequenced markers /marker-generator/icon-3-23.png goes to /marker-generator/numbered_marker.php??image=custom_icons/icon_3_sequenced.png&text=23
		var image_name = "/marker-generator/icon-"+m.getIcon()+"-" + parseInt(icon_number)+".png";
		var image_shadow_name = "/marker-generator/custom_icons/icon_" + m.getIcon() + "_seq_shadow.png";
		var cus_icon = new GIcon(G_DEFAULT_ICON);
		cus_icon.image = image_name;
		cus_icon.shadow = image_shadow_name;
		cus_icon.iconSize = new GSize(35, 41);
		cus_icon.shadowSize = new GSize(56, 41);
		cus_icon.iconAnchor = new GPoint(0, 41);
		markerOptions = { icon:cus_icon };
		//add marker to map
		var point =  m.getPoint();
		var latlng = point.getGeoCode();
		var marker = new GMarker(latlng, markerOptions);
		marker.number = icon_number;
		GEvent.addListener(marker, "click", function() {
			var current_server_url = 'http://' + jQuery('#cur_server_url').val();
			var seo_page_url = current_server_url + '/' + m.getSeoTag();
			var info_window_html = '<div class="marker_popup"><b>' + m.getName() + '</b><br />View all <a href="'+ seo_page_url + '">' + m.getName() + '</a> holidays<br /><table><tr>';
			var marker_images = m.getSeoImages();
			if(marker_images.length > 0){
				//console.log(marker_images);
				info_window_html += '<td width="135" valign="top"><div id="marker_images">';
				/*for(var i = 0;i < marker_images.length;i++){*/
				//only show first image
					info_window_html += '<img alt="' + marker_images[0].caption + '" ';
					info_window_html += 'src="' + marker_images[0].url + '" ';
					//image is added half original size
					info_window_html += 'width="' + marker_images[0].width / 2 + '" ';
					info_window_html += 'height="' + marker_images[0].height / 2 + '" />';
				/*}*/
				info_window_html += '</div></td>';
			}
			if(m.getIntro() != null){
				if(m.getIntro().length == 302 || m.getIntro().length == 303 ){
					info_window_html += '<td valign="top" width="240" height="140"><div id="marker_intro">' + m.getIntro() + '<a href="'+ seo_page_url + '"> more</a></div></td></tr></table>';
				}else{
					info_window_html += '<td valign="top" width="240" height="140"><div id="marker_intro">' + m.getIntro() + '</div></td></tr></table>';
				}
			}				
			info_window_html += '</div>';
			//alert(info_window_html);
            marker.openInfoWindowHtml(info_window_html,{ maxWidth: 400 });
        });
		g_markers_quick_sequenced.push(marker);		
		map.addOverlay(g_markers_quick_sequenced[g_markers_quick_sequenced.length-1]);
		
		return this.quick_sequenced_markers.length - 1;
	};
	
	this.getQuickLines = function(){
		return this.quick_lines;
	};
	this.getRndMrkLines = function(){
		return this.rndmrk_lines;
	};	
	this.getMarkers = function(){
		return this.markers;
	};
	this.getRandomMarkers = function(){
		return this.random_markers;
	};
	this.getQuickSequencedMarkers = function(){
		return this.quick_sequenced_markers;
	};
		
	//@parms marker_id
	this.quickSequencedMarkersClear = function(){
		for(var i=0;i<this.quick_sequenced_markers.length;i++){
			map.removeOverlay(this.quick_sequenced_markers[i]);
			map_state.sequenced_marker_listeners.splice(i,1);
			map_state.sequenced_markers.splice(i,1);
		}
		
	};
	
	this.streetview = function(){
		panoClient = new GStreetviewClient();
		myPano = new GStreetviewPanorama(document.getElementById("pano"));
		GEvent.addListener(myPano, "error", handleNoFlash);
		svOverlay = new GStreetviewOverlay();
        map.addOverlay(svOverlay);
        alert('Now click on a road with a blue overlay.');
        streetview_clickListener = GEvent.addListener(map,"click", function(overlay,latlng) {        	
        	panoClient.getNearestPanorama(latlng,onResponse);            
        });
		/*myPOV = {yaw:0,pitch:5};
		fenwayPark = new GLatLng(37.808979,-122.477164);
		myPano.setLocationAndPOV(fenwayPark, myPOV);*/
	};
	
	this.hide_streetview = function(){
		jQuery('#map').show();
    	jQuery('#pano').hide();
    	jQuery('#show_streetviews_btn').show();
    	jQuery('#hide_streetviews_btn').css('display','none');
	};
}

var NO_NEARBY_PANO = 600;
var FLASH_UNAVAILABLE = 603;

function handleNoFlash(errorCode) {
	map.removeOverlay(svOverlay);	
    if (errorCode == FLASH_UNAVAILABLE) {
    	alert("Error: Flash doesn't appear to be supported by your browser");
    	jQuery('#map').show();
    	jQuery('#pano').hide();
    	jQuery('#show_streetviews_btn').show();
    	jQuery('#hide_streetviews_btn').css('display','none');
    	return;
    }else if(errorCode == NO_NEARBY_PANO){
    	alert("No nearby panorama. Try new search or location.");    	
        return;
    }
    GEvent.removeListener(streetview_clickListener);
}

function onResponse(response) {
	map.removeOverlay(svOverlay);	
    if (response.code != 200) {
    	alert('No nearby panorama. Try new search or location.');
    } else if (response.code == 200) {
    	var latlng = new GLatLng(response.Location.lat, response.Location.lng);
    	myPano.setLocationAndPOV(latlng);
    	jQuery('#map').hide();
    	jQuery('#pano').show();
    	jQuery('#show_streetviews_btn').hide();
    	jQuery('#hide_streetviews_btn').css('display','block');
    }
    GEvent.removeListener(streetview_clickListener);
}


function onRndMrkGDirectionsLoad(){
	removeAction(); scheduleAction(); // perform next action with delay
	var polyline = this.getPolyline();
	//alert(polyline);
	polyline.setStrokeStyle({color:this.color,weight:3,opacity:1.0});
	rndmrk_polylines[parseInt(this.line_id)] = polyline;
	map.addOverlay(rndmrk_polylines[parseInt(this.line_id)]);	
	//add selected line to the map legend
	//map_state.addLineToLegend(parseInt(this.line_id));
}

function onQuickGDirectionsLoad(){
	removeAction(); scheduleAction(); // perform next action with delay
	var polyline = this.getPolyline();
	polyline.setStrokeStyle({color:this.color,weight:3,opacity:1.0});
	quick_polylines[parseInt(this.line_id)] = polyline;
	map.addOverlay(quick_polylines[parseInt(this.line_id)]);
}

function handleRndMrkErrors(){
	//alert('hierso moet die this.lines['+parseInt(this.line_id)+'] array fix : ');
	map_state.rndmrk_lines.splice(this.line_id,1);
	map_state.rndmrk_directions.splice(this.line_id,1);
	//empty legend
	
	/*console.log('map_state.rndmrk_lines');
	console.log(map_state.rndmrk_lines);
	console.log('map_state.rndmrk_directions');
	console.log(map_state.rndmrk_directions);*/
	if (this.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + this.getStatus().code);
   else if (this.getStatus().code == G_GEO_SERVER_ERROR)
     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + this.getStatus().code);
   
   else if (this.getStatus().code == G_GEO_MISSING_QUERY)
     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + this.getStatus().code);

//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//	     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
     
   else if (this.getStatus().code == G_GEO_BAD_KEY)
     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + this.getStatus().code);

   else if (this.getStatus().code == G_GEO_BAD_REQUEST)
     alert("A directions request could not be successfully parsed.\n Error code: " + this.getStatus().code);
   else if(this.getStatus().code == G_GEO_UNKNOWN_DIRECTIONS)
	   alert("Sorry, Google directions does not exist between the two locations.");
   else if(this.getStatus().code == G_GEO_TOO_MANY_QUERIES)
   {
		action_success = false;

		// Increasing delay because current delay is still probably too short for Google
		alert("Error: Google maps error received, the current delay (" + current_delay + "ms) is too short.");
		current_delay = current_delay * current_step_delay;
		scheduleAction(); // retry action with delay
   }
   else alert("An unknown error occurred." + this.getStatus().code);
}

function quickHandleErrors(){
	/*console.log('handle error');
	console.log(this.line_id);
	console.log(load_status.events);*/
	//console.log('quick error on line : ' + this.line_id);	
	if (this.getStatus().code == G_GEO_UNKNOWN_ADDRESS){
     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + this.getStatus().code);
	}else if (this.getStatus().code == G_GEO_SERVER_ERROR){
     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + this.getStatus().code);
	}else if (this.getStatus().code == G_GEO_MISSING_QUERY){
     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + this.getStatus().code);
//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//	     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
     
	}else if (this.getStatus().code == G_GEO_BAD_KEY){
     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + this.getStatus().code);
     
	}else if (this.getStatus().code == G_GEO_BAD_REQUEST){
     alert("A directions request could not be successfully parsed.\n Error code: " + this.getStatus().code);
	}else if(this.getStatus().code == G_GEO_UNKNOWN_DIRECTIONS){
		/*console.log('closed_route : ' + closed_route);
		console.log('this.line_id : ' + this.line_id);
		console.log('map_state.quick_lines.length : ' + map_state.quick_lines.length);*/
		/* Michael - closed_route variable doesn't make sense here as it's not defined anywhere, commented out */
		if(/*closed_route &&*/ this.line_id == map_state.quick_lines.length-1){
			//dont display the message when closed route gets changed from gdirections to polyline
		}else{
			alert("Sorry, Google directions does not exist between the two locations, a polyline will be drawn instead.");
		}	   
	}else if (this.getStatus().code == G_GEO_TOO_MANY_QUERIES){
		action_success = false;

		// Increasing delay because current delay is still probably too short for Google
		alert("Error: Google maps error received, the current delay (" + current_delay + "ms) is too short.");
		current_delay = current_delay * current_step_delay;
		scheduleAction(); // retry action with delay
	}else {
		alert("An unknown error occurred." + this.getStatus().code);
	}
}

//trim functions
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function switchTab(referer){
    if (readCookie('goback') == "true" && referer.match('call-back-book')){
            changeTab('prices');
        }
}


	function changeTab(objname) {
		jQuery(".product_tabs").hide();
		//jQuery("#similar-tours").hide();
		jQuery("#" + objname).show();
		if(objname == 'highlights')
		{
			if (jQuery("#highlights .product_main .right_colomb .clr").length == 0) {
				jQuery("#highlights .product_main .right_colomb").append('<div class="clr"></div>');
			}
			if (jQuery("#highlights .product_main .right_colomb .side_google_map_box").length != 0) {
				jQuery(".download-itinerary").insertAfter("#highlights .product_main .right_colomb .side_google_map_box");
			}
			else {
				jQuery(".download-itinerary").prependTo("#highlights .product_main .right_colomb");
			}
			jQuery(".download-itinerary").show();
			jQuery("#call-me-back-small").appendTo("#highlights .product_main .right_colomb");
			jQuery("#call-me-back-small").show();
			jQuery("#blogs").appendTo("#highlights .product_main .right_colomb");
			jQuery("#blogs").show();
		}
		if(objname == 'prices')
		{
			if (jQuery("#prices .product_main .right_colomb").length == 0) {
				jQuery("#prices .product_main").prepend('<div class="right_colomb"></div>');
			}
			jQuery(".download-itinerary").prependTo("#prices .product_main .right_colomb");
			jQuery(".download-itinerary").show();
			if (jQuery("#prices .product_main .right_colomb #call-me-back-small").length == 0) {
				jQuery("#call-me-back-small").appendTo("#prices .product_main .right_colomb");
				jQuery("#call-me-back-small").show();
				jQuery("#similar-tours").appendTo("#prices .product_main .right_colomb");
				jQuery("#similar-tours").show();
				jQuery("#blogs").appendTo("#prices .product_main .right_colomb");
				jQuery("#blogs").show();
			}
			/*
			if(jQuery("#call-me-back-small").hasClass("moved_up") || jQuery("#call-me-back-small").hasClass("moved_up_more")){
				//do nothing
			}else{	
				if(jQuery('.interactive_link').attr('title') != null){
						jQuery("#call-me-back-small").addClass("moved_up_more");
						jQuery("#similar-tours").addClass("moved_up_more");
				}else{
					jQuery("#call-me-back-small").addClass("moved_up");
					jQuery("#similar-tours").addClass("moved_up");
				}
				jQuery("#similar-tours").show();
			}
			*/
		}
		if(objname == 'itinery'){
			if (jQuery("#itinery .product_main .right_colomb #call-me-back-small").length == 0) {
				if (jQuery("#itinery .product_main .right_colomb .clr").length == 0) {
					jQuery("#itinery .product_main .right_colomb").append('<div class="clr"></div>');
				}
				if (jQuery("#itinery .product_main .right_colomb .side_google_map_box").length != 0) {
					jQuery(".download-itinerary").insertAfter("#itinery .product_main .right_colomb .side_google_map_box");
				}
				else {
					jQuery(".download-itinerary").prependTo("#itinery .product_main .right_colomb");
				}
				jQuery(".download-itinerary").show();
				jQuery("#call-me-back-small").appendTo("#itinery .product_main .right_colomb");
				jQuery("#call-me-back-small").show();
				
				/*if(jQuery("#similar-tours").hasClass("moved_up_more")){
					jQuery("#similar-tours").removeClass("moved_up_more");
				} 
				if(jQuery("#similar-tours").hasClass("moved_up")){
					jQuery("#similar-tours").removeClass("moved_up");
				}*/
				jQuery("#similar-tours").appendTo("#itinery .product_main .right_colomb");
				jQuery("#similar-tours").show();
				jQuery("#blogs").appendTo("#itinery .product_main .right_colomb");
				jQuery("#blogs").show();
			}
		}
		if(objname == 'accomm')
		{
			if (jQuery("#accomm .product_main .right_colomb .clr").length == 0) {
				jQuery("#accomm .product_main .right_colomb").append('<div class="clr"></div>');
			}
			if (jQuery("#accomm .product_main .right_colomb .side_google_map_box").length != 0) {
				jQuery(".download-itinerary").insertAfter("#accomm .product_main .right_colomb .side_google_map_box");
			}
			else {
				jQuery(".download-itinerary").prependTo("#accomm .product_main .right_colomb");
			}
			jQuery(".download-itinerary").show();
			jQuery("#call-me-back-small").appendTo("#accomm .product_main .right_colomb");
			jQuery("#call-me-back-small").show();
			jQuery("#blogs").appendTo("#accomm .product_main .right_colomb");
			jQuery("#blogs").show();
		}
		if((objname == 'excursions') || (objname == 'customer_reviews'))
		{
			if (jQuery("#"+objname+" .product_main .right_colomb .side_google_map_box").length != 0) {
				jQuery(".download-itinerary").insertAfter("#"+objname+" .product_main .right_colomb .side_google_map_box");
			}
			else {
				jQuery(".download-itinerary").prependTo("#"+objname+" .product_main .right_colomb");
			}
			jQuery(".download-itinerary").show();
		}
	}

