var headline_counter = 0;
var video_counter = 0;
var photo_counter = 0;
function populateIndex(){
	//headline
	for (var i = 0; i < totHeadlineCarousel; i++)		cp.call('/ajax/myajaxphp.php','populate_headline_carousel',return_data_populateIndexHeadline, i);

	//once headline done it will call videos, once video done it will call photos
}

function activateHeadline(){
	jQuery('#headline').jcarousel({
		wrap: 'circular',
		visible: 3,
		itemVisibleInCallback: {onBeforeAnimation: headline_itemVisibleInCallback},
		itemVisibleOutCallback: {onAfterAnimation: headline_itemVisibleOutCallback}
	});

	for (var i = 0; i < totVideoCarousel; i++)	cp.call('/ajax/myajaxphp.php','populate_video_carousel',return_data_populateIndexVideoCarousel, i);

}

function return_data_populateIndexHeadline(restul){
	var title			=	restul.getElementsByTagName('title').item(0).firstChild.data;
	var VID				=	restul.getElementsByTagName('VID').item(0).firstChild.data;
	var lien 			=	restul.getElementsByTagName('videoLink').item(0).firstChild.data;
	var position	=	restul.getElementsByTagName('position').item(0).firstChild.data;

	window.headline_itemList[position] = "<a href=\"" + lien + "\" target=\"_self\"><img src='images/box1/big_" + VID + ".jpg' alt=\"blah " + title + "\" border='0' /></a>"

	headline_counter++;
	if (headline_counter == totHeadlineCarousel) activateHeadline();

}

function return_data_populateIndexVideoCarousel(restul){
	var title			=	restul.getElementsByTagName('title').item(0).firstChild.data;
	var VID				=	restul.getElementsByTagName('VID').item(0).firstChild.data;
	var lien 			=	restul.getElementsByTagName('videoLink').item(0).firstChild.data;
	var position	=	restul.getElementsByTagName('position').item(0).firstChild.data;

	window.mycarousel_itemList[position] = "<a href='" + lien + "' target='_self' onMouseover='ddrivetip(\"" + title + "\",\"#e3e3e3\", 150)' onMouseout=\"hideddrivetip()\" ><img src='/thumb/1_" + VID + ".jpg' alt=\"" + title + "\" border=\"0\" /></a>"
	video_counter++;
	if (video_counter == totVideoCarousel) activateVideoCarousel();
}

function activateVideoCarousel(){
	jQuery('#mycarousel').jcarousel({
		wrap: 'circular',
		visible: 6,
		scroll: 6,
		itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
		itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
	});
	
	for (var i = 0; i < totPhotoCarousel; i++)		cp.call('/ajax/myajaxphp.php','populate_photo_carousel',return_data_populateIndexPhotoCarousel, i);
}

function return_data_populateIndexPhotoCarousel(restul){
	var title			=	restul.getElementsByTagName('title').item(0).firstChild.data;
	var img				=	restul.getElementsByTagName('img').item(0).firstChild.data;
	var lien 			=	restul.getElementsByTagName('link').item(0).firstChild.data;
	var position	=	restul.getElementsByTagName('position').item(0).firstChild.data;

	window.photo_itemList[position] = "<a href='" + lien + "' target='_self' onMouseover='ddrivetip(\"" + title + "\",\"#e3e3e3\", 150)' onMouseout=\"hideddrivetip()\" ><img src='" + img + "' border='0' /></a>"

	photo_counter++;
	if (photo_counter == totPhotoCarousel) activatePhotoCarousel();
}

function activatePhotoCarousel(){
	jQuery('#photo').jcarousel({
		wrap: 'circular',
		scroll:5,
		visible: 5,
		itemVisibleInCallback: {onBeforeAnimation: photo_itemVisibleInCallback},
		itemVisibleOutCallback: {onAfterAnimation: photo_itemVisibleOutCallback}
	});
}


/*	{section name=i loop=$rotation_top }
		{assign var=looprecord value=$smarty.section.i.index}
		{if $rotation_top[i].url_key eq ""}
			{assign var=videoLink value=$rotation_top[i].link}
		{else}
			{assign var=videoLink value=$baseurl|cat:'/videos/'|cat:$rotation_top[i].url_key}
		{/if}
		mycarousel_itemList[{$looprecord}] = "<a href='{$videoLink}' target='_self' onMouseover='ddrivetip(\"{$rotation_top[i].title|escape}\",\"#e3e3e3\", 150)' onMouseout=\"hideddrivetip()\" ><img src='/thumb/1_{$rotation_top[i].VID}.jpg' alt=\"{$rotation_top[i].title}\" border=\"0\" /></a>"
	{/section}
	
var headline_itemList = new Array()
	{section name=i loop=$rotation_headline }
		{assign var=looprecord value=$smarty.section.i.index}
		{if $rotation_headline[i].url_key eq ""}
			{assign var=videoLink value=$rotation_headline[i].link}
		{else}
			{assign var=videoLink value=$baseurl|cat:'/videos/'|cat:$rotation_headline[i].url_key}
		{/if}
		headline_itemList[{$looprecord}] = "<a href=\"{$videoLink}\" target=\"_self\"><img src='{$imgurl}/box1/big_{$rotation_headline[i].VID}.jpg' alt=\"{$rotation_headline[i].title}\" border='0' /></a>"
	{/section}
	
var photo_itemList = new Array()
	{section name=i loop=$rotPhoto }
		{assign var=looprecord value=$smarty.section.i.index}
		photo_itemList[{$looprecord}] = "<a href='{$baseurl}/photos/{$rotPhoto[i].url_key}' target='_self' onMouseover='ddrivetip(\"{$rotPhoto[i].titre|escape}\",\"#e3e3e3\", 150)' onMouseout=\"hideddrivetip()\" ><img src='{$baseurl}/galerie/{$rotPhoto[i].dir}/{$rotPhoto[i].thumbnail}' border='0' /></a>"
	{/section}
*/



/*	start=1;
	function fxOnload(){
		alert('this is on load');
	}


	function show_recent(direction, total)
	{
		if(direction=="right")
			start = start + 4;
		else if(direction=="left")
			start = start - 4;

		if(start >= 13)
			start = 1;
		else if(start <= 0)
			start = 9;

		if(start == 1 && total>0)
		{
			document.getElementById('recent1').style.display = "block";
			document.getElementById('recent2').style.display = "none";
			document.getElementById('recent3').style.display = "none";
			if(total<4) last = total; else last = 4;
			document.getElementById('recent_total').innerHTML = "[1-"+last+" of "+total+"]";
		}
		if(start == 5 && total>4)
		{
				document.getElementById('recent1').style.display = "none";
				document.getElementById('recent2').style.display = "block";
				document.getElementById('recent3').style.display = "none";
				if(total<8) last = total; else last = 8;
				document.getElementById('recent_total').innerHTML = "[5-"+last+" of "+total+"]";
		}
		if(start == 9 && total>8)
		{
				document.getElementById('recent1').style.display = "none";
				document.getElementById('recent2').style.display = "none";
				document.getElementById('recent3').style.display = "block";
				if(total<12) last = total; else last = 12;
				document.getElementById('recent_total').innerHTML = "[9-"+last+" of "+total+"]";
		}
		return;
}






        function createNewList()
        {
                var name = prompt("Enter a name for a new contact group.", "");
                if(name)
                        document.location.href="friends.php?add_list="+name;
        }
        function doAction(action)
        {
                if(action)
                {

                        document.getElementById('action_name').value = action;
                        document.friendsForm.submit();

                }
        }
        function invite_mem_addall()
        {
                var x=document.getElementById("myfriends");
                var y=document.getElementById("invitefriends");
                var i;
                i= x.options.length;
                if(i!=0)
                {
                        y.options.length=i;
                        for(var j=0;j<i;j++)
                        {
                                y.options[j]=new Option(x.options[j].text,x.options[j].value);
                        }
                        for(j=0;j<i;j++)
                        {
                                x.remove(0);
                        }
                }

        }
        function invite_mem_add()
        {
                var x=document.getElementById("myfriends");
                var y=document.getElementById("invitefriends");
                var i;
                i = x.selectedIndex;
                if(i>=0)
                {
                        y.options[y.options.length]=new Option(x.options[i].text,x.options[i].value);
                        x.remove(x.selectedIndex);
                }
        }
        function invite_mem_removeall()
        {
                var x=document.getElementById("invitefriends");
                var y=document.getElementById("myfriends");
                var i;
                i= x.options.length;
                if(i!=0)
                {
                        y.options.length=i;
                        for(var j=0;j<i;j++)
                        {
                                y.options[j]=new Option(x.options[j].text,x.options[j].value);

                        }
                        for(j=0;j<i;j++)
                        {
                                x.remove(0);

                        }
                }
        }







        function invite_mem_remove()
        {
                var x=document.getElementById("invitefriends");
                var y=document.getElementById("myfriends");
                var i;
                i = x.selectedIndex;
                if(i>=0)
                {
                        y.options[y.options.length]=new Option(x.options[i].text,x.options[i].value);
                        x.remove(x.selectedIndex);
                }
        }

        function invite_mem_send()
        {
                var i,out;
                var x=document.getElementById("invitefriends");
                for(i=0; i<x.options.length; i++)
                {
                        out = out + "<input type=hidden name=flist[] value="+x.options[i].text+" >";
                }
                document.getElementById('friends_div').innerHTML=out;
                document.fform.submit();
        }

        function approve_post(id,idHlinkAprove)
        {                
		alert("This posting will approved. Refresh the page.");
		var y="apostform"+id;
		var x = document.getElementById(y);
                return x.submit();


        }
*/
