$(function(){
$.ajax({
		type: "GET",
		url: "Aupair_Carousel.xml",
		dataType: "xml",
		success: function(xml) {
		title=[];
		imglink=[];
		desc=[];
		videoid=[];
		videotitle=[];
		videoat=[];
		$(xml).find('item').each(function(){
		title.push($(this).find('title').text());
		imglink.push($(this).find('image_link').text());
		desc.push($(this).find('description').text());
		if($(this).find('video').text()==1){videoid.push($(this).find('id').text());};
		if($(this).find('video').text()==1){videotitle.push($(this).find('title').text());};
		if($(this).find('video').text()==1){videoat.push($(this).find('videoat').text());};	
											  });
		
		
		
		loadmagniImage = new Image();
		loadmagniImage.src="Images/magni.gif";
		
		$("#carouselwrapper").css("display", "block");
		
		$(".nextarrow").hover(function(){
		$(this).attr("src","Images/nextover.gif");	
		}, function(){$(this).attr("src","Images/next.gif")});
		
		$(".previousarrow").hover(function(){
		$(this).attr("src","Images/previousover.gif");	
		}, function(){$(this).attr("src","Images/previous.gif")});
		
		$("div.aupairtitle").css({"opacity":"0.5", "background-color":"#FFFFCC"})
		
		ThisAupair = 0;
		isMouseOver = false;
		var t;
		ThisVideo = 0;
		
		$("div.aupairtitle").html(title[ThisAupair]);
		$("#aupairtitleonpage").html(title[ThisAupair].substr(0,20));
		$("div.aupairimglink").html('<img src="'+imglink[ThisAupair]+'" border=\"0\" class=\"nannyImage\ width=\"157\" height=\"180\"  >');
		$("div.aupairdesc").html(desc[ThisAupair]);
		$("#aupairdesconpage").html(desc[ThisAupair].substr(0,40)+"...");
		$("#carouselwrapper").find("img.nannyImage").css({"height":"102px","width":"120px"});
		
		$("#videoT").html("<span>"+videotitle[ThisVideo]+"</span>");
		$("#videoP").html("<img height='102' width='120' src='http://www.aupair.ws/AAImages/"+videoid[ThisVideo]+".jpg' class='nannyImage' border='0' style='margin-left:0.7em' />");
		$("#playvideo").live("click", function(){
		content= videoat[ThisVideo];								
		$.cursorMessage(content, {hideTimeout:0});
		elx= (screen.width/2) - 250;
		ely= (screen.height/2) - 150;
		$.cursorMessage(content, {hideTimeout:0}, elx, ely);								
		$("#cursorMessageDiv").css("width","40em");									
											});
		
		
		$("img.pauseplay").live("click",function(){
		isMouseOver = true;	
		clearTimeout(t); 
		$(this).attr("src","Images/play.gif");
		$(this).removeAttr("onmouseover");
		$(this).removeAttr("onmouseout");
		$(this).mouseover(function(){$(this).attr("src", "Images/playover.gif")});
		$(this).mouseout(function(){$(this).attr("src", "Images/play.gif")});		
		$(this).attr("title","continue");
		$(this).attr("class","playpause");	
		
											});
		
		$("img.playpause").live("click", function(){
		isMouseOver = false;	
		$(this).attr("src","Images/pause.gif");
		$(this).mouseover(function(){$(this).attr("src", "Images/pauseover.gif")});
		$(this).mouseout(function(){$(this).attr("src", "Images/pause.gif")});
		$(this).attr("title","pause");
		$(this).attr("class","pauseplay");	
		NextAupair();		
											});		
		

		$("span.prevaupair").live("click", function(){															
		ThisAupair= ThisAupair-2;
		isMouseOver = true;	
		clearTimeout(t);
		ShowAupair(ThisAupair);
															});
		
		
		$("span.nextaupair").live("click", function(){															
		ThisAupair++
		isMouseOver = true;	
		clearTimeout(t);
		ShowAupair(ThisAupair);
															});
		
		$("span.nextvideo").live("click", function(){
		if (ThisVideo>=videoid.length-1) ThisVideo=0;
		ThisVideo=ThisVideo + 1;
		$("#videoT").html("<span>"+videotitle[ThisVideo]+"</span>");
		$("#videoP").html("<img height='102' width='120' src='http://www.aupair.ws/AAImages/"+videoid[ThisVideo]+".jpg' class='nannyImage' border='0' style='margin-left:0.7em' />");
															});
		
		$("span.prevvideo").live("click", function(){															
		if (ThisVideo!=0) {ThisVideo=ThisVideo -1;}
		$("#videoT").html("<span>"+videotitle[ThisVideo]+"</span>");
		$("#videoP").html("<img height='102' width='120' src='http://www.aupair.ws/AAImages/"+videoid[ThisVideo]+".jpg' class='nannyImage' border='0' style='margin-left:0.7em' />");													
															});
		
		setTimeout (NextAupair, 4000);
		
		function NextAupair() {
  		ThisAupair++;
  		if (ThisAupair>=title.length) ThisAupair = 0; 
  		if(isMouseOver==false){
		ShowAupair(ThisAupair);
  		t=setTimeout (NextAupair, 4000);
		}
		 					}
		function ShowAupair(ThisAupair){
		$("div.aupairtitle").html(title[ThisAupair]);
		$("#aupairtitleonpage").html(title[ThisAupair].substr(0,20));
		$("div.aupairimglink").html('<img src="'+imglink[ThisAupair]+'" border=\"0\" class=\"nannyImage\">');
		$("div.aupairdesc").html(desc[ThisAupair]);
		$("#aupairdesconpage").html(desc[ThisAupair].substr(0,40)+"...");
		$("#carouselwrapper").find("img.nannyImage").css({"height":"102px","width":"120px"});
		LoadNext();			
			}
		
		function LoadNext()  { // Loads next picture for faster operation.
		NextImage = new Image();
		NextPic = ThisAupair+ 1;
    	if (NextPic>=title.length) NextPic = 0;
    	NextImage.src = imglink[NextPic]; 
						}
						
		
		
		
		
								}
		})


//Families

$.ajax({
		type: "GET",
		url: "Family_Carousel.xml",
		dataType: "xml",
		success: function(xml) {
		ftitle=[];
		fimglink=[];
		fdesc=[];
		$(xml).find('item').each(function(){
		strtitle=$(this).find('title').text();
		strtitle=strtitle.replace(RegExp([0-9],"g"), "");
		ftitle.push(strtitle);
		fimglink.push($(this).find('image_link').text());
		fdesc.push($(this).find('description').text());
		//for more keywords on page
		//$("#availablefamilies").html(fdesc.toString().substr(100, 1500).replace(/aupair/g, 'au pair'));
											  });
		
		$("#carouselwrapperfamily").css("display", "block");		
				
		$("div.familytitle").css({"opacity":"0.5", "background-color":"#FFFFCC"})
		
		ThisFamily = 0;
		isfamilyMouseOver = false;
		var tf;
		
		$("div.familytitle").html(ftitle[ThisFamily]);
		$("#familytitleonpage").html(ftitle[ThisFamily].substr(0,20));
		$("div.familyimglink").html('<img src="'+fimglink[ThisFamily]+'" border=\"0\" class=\"nannyImage\" style=\"max-width:40em;max-height:40em\" >');
		$("div.familydesc").html(fdesc[ThisFamily]);
		$("#familydesconpage").html(fdesc[ThisFamily].substr(0,40)+"...");
		$("#carouselwrapperfamily").find("img.nannyImage").css({"height":"102px","width":"120px"});
		
	$("img.familypauseplay").live("click",function(){
		isfamilyMouseOver = true;	
		clearTimeout(tf); 
		$(this).attr("src","Images/play.gif");
		$(this).removeAttr("onmouseover");
		$(this).removeAttr("onmouseout");
		$(this).mouseover(function(){$(this).attr("src", "Images/playover.gif")});
		$(this).mouseout(function(){$(this).attr("src", "Images/play.gif")});		
		$(this).attr("title","continue");
		$(this).attr("class","familyplaypause");	
		
											});
		
		$("img.familyplaypause").live("click", function(){
		isfamilyMouseOver = false;	
		$(this).attr("src","Images/pause.gif");
		$(this).mouseover(function(){$(this).attr("src", "Images/pauseover.gif")});
		$(this).mouseout(function(){$(this).attr("src", "Images/pause.gif")});
		$(this).attr("title","pause");
		$(this).attr("class","familypauseplay");	
		NextFamily();		
											});	
		
		$("span.prevfamily").live("click", function(){															
		ThisFamily =ThisFamily-2;
		isfamilyMouseOver = true;	
		clearTimeout(tf);
		ShowFamily(ThisFamily);
															});
		
		$("span.nextfamily").live("click", function(){															
		ThisFamily++
		isfamilyMouseOver = true;	
		clearTimeout(tf);
		ShowFamily(ThisFamily);
															});
		
		
		setTimeout (NextFamily, 4000);
		
		function NextFamily() {
  		ThisFamily++;
  		if (ThisFamily>=ftitle.length) ThisFamily = 0; 
  		if(isfamilyMouseOver==false){
		ShowFamily(ThisFamily);
  		tf=setTimeout (NextFamily, 4000);
		}
		 					}
		function ShowFamily(ThisFamily){
		$("div.familytitle").html(ftitle[ThisFamily]);
		$("#familytitleonpage").html(ftitle[ThisFamily].substr(0,20));
		$("div.familyimglink").html('<img src="'+fimglink[ThisFamily]+'" border=\"0\" class=\"nannyImage\" style=\"max-width:18em;max-height:18em\">');
		$("div.familydesc").html(fdesc[ThisFamily]);
		$("#familydesconpage").html(fdesc[ThisFamily].substr(0,40)+"...");
		$("#carouselwrapperfamily").find("img.nannyImage").css({"height":"102px","width":"120px"});
		LoadNextFamily();			
			}
		
		function LoadNextFamily()  { // Loads next picture for faster operation.
		NextImage = new Image();
		NextPic = ThisFamily+ 1;
    	if (NextPic>=ftitle.length) NextPic = 0;
    	NextImage.src = fimglink[NextPic]; 
						}
						
						
		
		
								}
		})
})
