﻿var aStrImgBlog = new Array();
var aStrImgForTest = new Array("img_blog.jpg","img_ask.jpg","img_clip.jpg","img_toddle.jpg","img_vdo.jpg");// TODO: BlogAlbum for test

function ChangImgAlbum(strDirection)
{
	var iSize=parseInt($('#BlogAlbum .image img').size());
	var iActive = parseInt($("#BlogAlbum .image img.active").attr("ref"));
	
	//old
	$("#imgBlog"+iActive).addClass("hide");	
	$("#imgBlog"+iActive).removeClass("active");	

	switch (strDirection.toLowerCase()) {
	   case "left": iActive -= 1; break;
	   case "right": iActive += 1; break;
	   default: iActive  -= 1; break;
	}

	if(iActive > iSize) iActive =1;
	else if (iActive == 0) iActive = iSize;

	//new
	$("#imgBlog"+iActive).addClass("active");	
	$("#imgBlog"+iActive).removeClass("hide");	
}

function AddImgAlbum(aStrImg)
{
	var strTagImg = "";
	
	if(aStrImg == null || aStrImg.length == 0) return 0;
	for (var iNumber=0;iNumber<=aStrImg.length-1;iNumber++)
	{
	  strTagImg = '<img id="imgBlog'+(iNumber+1)+'" src="/images/'+aStrImg[iNumber]+'" alt="imgBlog" ref="'+(iNumber+1)+'"/>';
	  $("#BlogAlbum .image").append(strTagImg);
	  if(iNumber==0) $("#imgBlog1").addClass("active");
	  else $("#imgBlog"+(iNumber+1)).addClass("hide");
	  
	}
}

function getSlider(month) {

    $.ajax({
        type: "GET",
        url: "/ajaxhandler/showslidebar_home/?&age=" + month,
        success: function(oResultData) {
        	console.log(oResultData);
            $("span[id$=lbToddlerWorld]").fadeOut(100);
            $("span[id$=lbToddlerWorld]").html(oResultData);
            $("span[id$=lbToddlerWorld]").fadeIn(300);
            $('span[id$=lbToddlerWorld] a:first').css('background', 'url(/images/bg_toddle_row_hover.jpg)');

            $('span[id$=lbToddlerWorld] > a:not(:first)').mouseover(function() {
                $('span[id$=lbToddlerWorld] > a:first').css('background', '');
            });
            
            /*$.each($('span[id$=lbToddlerWorld] a'), function(index, obj){
            	var url = getFullUrl($(obj).attr('href'), false);
	            $('<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?url='+ url + '&text=Tweet&count=horizontal" style="width:130px; height:21px;"></iframe>').appendTo($(obj));
	            $('<iframe src="http://www.facebook.com/plugins/like.php?href='+ url + '&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>').appendTo($(obj));
            });*/
        }
    });
}
/*
$(document).ready(function() {

    var arrNum = [12, 18, 24, 30, 36];
    var ranNum = Math.floor(Math.random() * 5 + 1);
    var ranArr = arrNum.slice(ranNum - 1, ranNum);
	
    if ($.cookie('MMBToddlerSliderAge'))
        ranArr = $.cookie('MMBToddlerSliderAge');
			
    //getSlider(ranArr);
    $('.toddle_world_bottom .age span').html(ranArr.toString());

    //UC Todder's world
    $("#slider").slider({
        value: ranArr,
        min: 12,
        max: 36,
        step: 1,
        stop: function(event, ui) {
            getSlider(ui.value);
            $.cookie('MMBToddlerSliderAge', ui.value);
            $('.toddle_world_bottom .age span').html(ui.value);
            //$("#amount").val('$' + ui.value);
        }
    });

    //$("#amount").val('$' + $("#slider").slider("value"));
    //UC MommyAlbum
    AddImgAlbum(aStrImgForTest);

    $("#btAlbumLeft").click(function() { ChangImgAlbum("left"); });
    $("#btAlbumRight").click(function() { ChangImgAlbum("right"); });

});*/


function getSlider2(month) {
    $('#divMonth span.number').html(month.toString());
    $.ajax({
        type: "GET",
        url: "/ajaxhandler/showslidebar_home/?&age=" + month,
        success: function(oResultData) {
            var ret = eval('(' + oResultData + ')');

            $.each(ret.data, function(idx, obj) {
                if (obj.Type == 1) {
                	changeSliderData('divPhysical', obj);
                } else if (obj.Type == 2) {
                	changeSliderData('divIntellectual', obj);
                } else if (obj.Type == 3) {
                	changeSliderData('divSocial', obj);
                } else if (obj.Type == 4) {
                	changeSliderData('divEmotional', obj);
                }
            });

            /*$.each($('span[id$=lbToddlerWorld] a'), function(index, obj){
            var url = getFullUrl($(obj).attr('href'), false);
            $('<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?url='+ url + '&text=Tweet&count=horizontal" style="width:130px; height:21px;"></iframe>').appendTo($(obj));
            $('<iframe src="http://www.facebook.com/plugins/like.php?href='+ url + '&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>').appendTo($(obj));
            });*/
        }
    });
}

function changeSliderData(divId, obj){

	//$('#'+ divId).fadeOut(100);
    $('#toddlerWorldBox #'+ divId +' div.data_image a img').attr('src', obj.Image);
    $('#toddlerWorldBox #'+ divId +' div.data_image a').attr('href', obj.URL);
    $('#toddlerWorldBox #'+ divId +' p.data_title a').attr('href', obj.URL);
    $('#toddlerWorldBox #'+ divId +' p.data_text a').attr('href', obj.URL);
    $('#toddlerWorldBox #'+ divId +' p.data_text a').html(obj.Title);
    var articleurl = encodeURIComponent(getFullUrl(obj.URL));

    var fbhtml = '<iframe src="http://www.facebook.com/plugins/like.php?href=' + articleurl + '&amp;layout=button_count&amp;show_faces=false&amp;width=80&amp;action=like&amp;font&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:80px; height:21px;" allowTransparency="true"></iframe>';
    var twhtml = '<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?url=' + articleurl +'&counturl=' + articleurl + '&text=' + obj.Title + '&count=horizontal" style="width:100px; height:21px;"></iframe>';
    
    $('#toddlerWorldBox #'+ divId +' p.data_social').html(twhtml + fbhtml);
    
	$('#toddlerWorldBox #'+ divId +' p.data_title').find('span.new').remove();
    if (obj.IsNew) {
        $('<span class="new">New</span>').appendTo($('#toddlerWorldBox #'+ divId +' p.data_title'));
    }
	//$('#'+ divId).fadeIn(100);
}

$(document).ready(function() {

    var arrNum = [12, 18, 24, 30, 36];
    var ranNum = Math.floor(Math.random() * 5 + 1);
    var ranArr = arrNum.slice(ranNum - 1, ranNum);
	
    if ($.cookie('MMBToddlerSliderAge'))
        ranArr = $.cookie('MMBToddlerSliderAge');
			
    getSlider2(ranArr);
    $('.toddle_world_bottom .age span').html(ranArr.toString());

    //UC Todder's world
    $("#slider").slider({
        value: ranArr,
        min: 12,
        max: 36,
        step: 1,
        stop: function(event, ui) {
            getSlider2(ui.value);
            $.cookie('MMBToddlerSliderAge', ui.value);
            $('#divMonth span.number').html(ui.value);
            //$("#amount").val('$' + ui.value);
        }
    });

    //$("#amount").val('$' + $("#slider").slider("value"));
    //UC MommyAlbum
    //AddImgAlbum(aStrImgForTest);

    //$("#btAlbumLeft").click(function() { ChangImgAlbum("left"); });
    //$("#btAlbumRight").click(function() { ChangImgAlbum("right"); });
});


//////////////For interactive games
$(document).ready(function() {	

	//////////////////Fash Card Popup
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
		
		$('html, body').animate({
			scrollTop: $("#container").offset().top
		}, 1000);
	
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
		swfobject.embedSWF("/Flash/flashcardspreloader.swf", "main", "755", "500", "9.0.0");
	
	});

	//////////////////Development Tracker Popup	
	$('a[name=modal2]').click(function(e) {
	
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
		
		$('html, body').animate({
		scrollTop: $("#container").offset().top
		}, 1000);
	
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 		
		swfobject.embedSWF("/Flash/developmenttrackerpreloader.swf", "main", "755", "500", "9.0.0");
	});

	//if close button is clicked
	$('.window .layer_close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask').hide();
		$('.window').hide();
		swfobject.embedSWF("/Flash/clearGame.swf", "main", "755", "500", "9.0.0");

	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
		swfobject.embedSWF("/Flash/clearGame.swf", "main", "755", "500", "9.0.0");

	});	
});


///////////////Ask the Expert Popup
$(document).ready(function(){
	$("#askExpertPopup").click(function(){
		var AskTheExpertInquiryHtml = "";
		$.ajax({
			type: "POST",
			async:false,
			url: "/Nestle_Features/AskTheExpert/AskTheExpertInquiry.aspx",
			success: function(data){
			  	AskTheExpertInquiryHtml = data;
			}
		});
    	$.fn.jmodal({
			width:546,
	    	height:700,
			title: "Ask Your Question",
      		content: AskTheExpertInquiryHtml,
			buttonText: { ok: "Send", cancel: "Close" }, 
      		okEvent: function(data, args) {},
      		cancelEvent: function(data, args) {}     
	    });
    	ValidateAskAQuestion();
   		$("#AskTheExpertInquiry1_BtnSendQuestion").click(function(){$("#AskYourQuestion").submit();return false;});
   		$("#AskTheExpertInquiry1_BtnCloseQuestion").click(function(){$(".jmodal-opts .btn_cancel").trigger("click"); return false;});         
	});// end onclick	
});

//////////////Facebook footer
// Gaj - remove this then use css expresion hack (css/mmby3/style_ie6_home.css)
/*$(document).ready(function(){
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$(".facebook-footer").css('position','fixed' );
	   		$(".facebook-footer").css('top',$(window).height()-78+$(window).scrollTop() );
			$(".facebook-footer").css('position','absolute' );
	 
	   $(window).scroll(function() {
	   	if($(window).height()-78+$(window).scrollTop()<=$("#container").outerHeight()-70)
	   	{
	   		$(".facebook-footer").css('position','fixed' );
	   		$(".facebook-footer").css('top',$(window).height()-78+$(window).scrollTop() );
			$(".facebook-footer").css('position','absolute' );
	    }
	   });
	   $(window).resize(function() {
	   		$(".facebook-footer").css('position','fixed' );
	   		$(".facebook-footer").css('top',$(window).height()-78+$(window).scrollTop() );
			$(".facebook-footer").css('position','absolute' );
	   });
	}
});*/
///// oohb: Toggle Sound ON/OFF visible
$(document).ready(function() {
	$('ul.jp-controls').attr('style','visibility:visible;');
});
////
