// JavaScript Document
function ishome(){
	return endsWith(location.href,"home.htm") || endsWith(location.href,".net/") || endsWith(location.href,".com/") || endsWith(location.href,".com.my/") ||endsWith(location.href,"101.103/" ||endswith(location.href,"/~medilink/"));
}

function endsWith(testString, endingString){
      if(endingString.length > testString.length) return false;
      return testString.indexOf(endingString)==(testString.length-endingString.length);
}


jQuery.fn.blindToggle = function(speed, easing, callback) {

  var h = this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom'));

  return this.animate({marginTop: parseInt(this.css('marginTop')) <0 ? 0 : -h}, speed, easing, callback);  

};

jQuery.fn.idle = function(time){
	var i = $(this);
	i.queue(function(){
		setTimeout(function(){
			i.dequeue();
		}, time);
	});
};


$(function(){
	$('#videoloading').fadeOut();
	}
	);
$(function() {
		   
   $('.serviceroll').hover( function(){
									 var dir="images/stories/service-rollover/";
	var id=$(this).attr('id');

	  $('#serviceImage').attr('src',dir+id+".jpg")
   },
   function(){
      
   });

});
var curvideo="#divvideo1";
var previousA=$('#video1');
function setCurrent(c){
	curvideo=c;
}
// $(function() {
	// $('#video1').addClass('selected');	   
   // $('a.video').click( function(){
   // if ('#div'+id==curvideo) return;
	// var dir="#div";
	
	// $('a.video').removeClass('selected');
	// $(this).addClass('selected');
	
	// var id=$(this).attr('id');
	
	// $(curvideo+"").slideToggle(
		// function(){
			// $('#div'+id+ '').slideToggle();
		// }
	// );
	// //alert('hid '+curvideo);

	
// //	alert('showing'+'#div'+id+ '');
	  
	  // setCurrent('#div'+id+ '');
	  // $('#videoloading').fadeIn(
		// function(){    
			// window.setTimeout(
				// function(){
					// $('#videoloading').fadeOut();
				// }, 4000);
			// }
		// );


   // },
   // function(){
      
   // });

// });


		   


$(function() {
		   
   $('.hoverbtn').hover( function(){
									 
	var src=$(this).attr('src');
	src=src.replace(/.png/,"_h.png");
	  $(this).attr('src',src)
   },
   function(){
      var src=$(this).attr('src');
		src=src.replace(/_h/,"");
	  $(this).attr('src',src)
   });

});



$(function() {

	$('#div-0').tabs({ fxFade: true });
	$('#div-1').tabs({ fxFade: true });
	$('#div-2').tabs({ fxFade: true });
	$('#div-3').tabs({ fxFade: true });
	$('#div-4').tabs({ fxFade: true });
	$('#div-5').tabs({ fxFade: true });

});

$(document).ready(function(){
$('.accordion h2').click(function(ev){
var el = $(ev.target).next(".accordionPanel");
var els= $('.accordionPanel'); /*get a reference to all products*/
/*close all open accordion panels*/
for (i=0;i<els.length;i++){
if ($(els[i]).css("display")=="block") {
$(els[i]).slideToggle("slow");
}
}
/*slide the selected product open*/
el.slideToggle("slow");
});
});

var els= $('.accordionPanel');
$('#firstoffice').slideToggle("slow");

function doMove(m) {

     $('html, body').animate({scrollTop:0}, 'slow', function(){if(m)displayMap();});
}

$(document).ready(function() {
   
    $('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });

});

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$.preloadImages(
"templates/medilink_dby/images/medilink_video_rollover_button.png",
"templates/medilink_dby/images/services_darker_box.png",
"templates/medilink_dby/images/point_selected.png",
"images/stories/service-rollover/serv1a.jpg",
"images/stories/service-rollover/serv2a.jpg",
"images/stories/service-rollover/serv3a.jpg",
"images/stories/service-rollover/serv4a.jpg",
"images/stories/service-rollover/serv5a.jpg",
"images/stories/service-rollover/serv6a.jpg",
"images/stories/service-rollover/serv7a.jpg",
"templates/medilink_dby/images/medilink_map.png",
"/templates/medilink_dby/images/medilink_map_images/medilink_map_close_button.png"
  );


var display_elements;
var len;
var leftArray = new Array();

function showButtons(y){
	if (y==0){
		$("#qtdown").css("visibility","hidden");
		$("#qttop").css("visibility","hidden");
		$("#qtup").css("visibility","visible");
		$("#qtlast").css("visibility","visible");		
	}
	
	if (y<=-1662){

		$("#qtup").css("visibility","hidden");
		$("#qtlast").css("visibility","hidden");
		$("#qtdown").css("visibility","visible");
		$("#qttop").css("visibility","visible");		
	}
	
	if (y>-1662 && y < 0) {
		$("#qtup").css("visibility","visible");
		$("#qtlast").css("visibility","visible");
		$("#qtdown").css("visibility","visible");
		$("#qttop").css("visibility","visible");
	}
}
$(document).ready(function() {

	$("#qtup").click(function() {	//On hover...
		var targetPos=$("#qtcontent").css("margin-top").replace("px","")-277;
		if (targetPos<=-1939) {return};
		$("#qtcontent").animate({
			marginTop: targetPos //Find the <span> tag and move it up 40 pixels
		}, 350
		);showButtons(targetPos);
	});

	$("#qtdown").click(function() {	//On hover...
		var targetPos=parseInt($("#qtcontent").css("margin-top").replace("px",""))+277;
		if (targetPos==277) {return};
		$("#qtcontent").animate({
			marginTop: targetPos //Find the <span> tag and move it up 40 pixels
		}, 350
		);showButtons(targetPos);
	});

	$("#qttop").click(function() {	//On hover...
		$("#qtcontent").animate({
			marginTop: 0 //Find the <span> tag and move it up 40 pixels
		}, 350
		);showButtons(0);
		
	});

	$("#qtlast").click(function() {	//On hover...
		$("#qtcontent").animate({
			marginTop: -1662 //Find the <span> tag and move it up 40 pixels
		}, 350
		);showButtons(-1662);
		
	});
	$("#maintabbar li a").addClass("links");
	display_elements = $('.links');
	len = display_elements.length;
	for (var i = 0; i < len-1; i++) {
        leftArray[i]=$(display_elements[i]).offset().left; // no callback
    }
	$('.countrytab').animate({opacity: 0});
	$('#contactbg').animate({opacity: 0});
	$('.mappointL').click(function(){
		$('.countrytab').animate({opacity: 1.0,marginLeft: '0px'});$('#contactbg').animate({opacity: 1.0});
		toggleLinks();
	});
	$('.mappointR').click(function(){
		$('.countrytab').animate({opacity: 1.0,marginLeft: '0px'});$('#contactbg').animate({opacity: 1.0});
		toggleLinks();
	});
	$('#chooseagain').click(function(){
		$('.countrytab').animate({opacity: 0,marginLeft: '-5000px'});$('#contactbg').animate({opacity: 0});
		toggleLinks(); return false;
	});
	$('#changeholder li').each(
			function(i){
				$(this).appendTo('ul#maintabbar');
	});
	
});
function getMinus(){
if(m1==-1) {m1=m1*-1;return '+=1000';}
else {m1=m1*-1;return '-=1000';}
}
var m1=1;
function toggleLinks(){
    var xx=getMinus();
    
    animateIt(0);
    
     // last element - attach callback
}

function animateIt(i){
	var xx=getMinus();
	$(display_elements[i]).animate(
	{left: xx}, 50, function(){i++; if (i < len)animateIt(i); else $('#chooseagain').slideToggle(50)}
	);
	
}

