var dataArray = new Array();
var carasoulArray = new Array();
var carousel;
var dataObj;
var spotlightObj;          
var initVal = 0;
var containerWidth = 210;
(function () {
        // Get the image link from within its (parent) container.
        function getImage(parent) {
            var el = parent.firstChild;
                    
            while (el) { // walk through till as long as there's an element
                if (el.nodeName.toUpperCase() == "IMG") { // found an image
					return el.src.replace("/featured/", "/featured/preview/");
                }
                el = el.nextSibling;
            }            
            return "";
        }

		               
        YAHOO.util.Event.onDOMReady(function (ev) {
            var el, item,
                spotlight   = YAHOO.util.Dom.get("spotlight"),
                carousel    =  new YAHOO.widget.Carousel("carousel-container", {animation: { speed: 0.5 } });
                initVal = 0;
            carousel.render(); // get ready for rendering the widget
            carousel.show();   // display the widget
            // display the first selected item in the spotlight
            item = carousel.getElementForItem(carousel.get("selectedItem"));
            if (item) {
                spotlight.innerHTML = "<img src=\"" + getImage(item) + "\" width=\"272\" height=\"326\">";
            }                       
            carousel.on("itemSelected", function (index) {
                // item has the reference to the Carousel's item
                item = carousel.getElementForItem(index);
                if (item) {
						dataArray[0] = carasoulArray[index][0];
						dataArray[1] = carasoulArray[index][1];
						dataArray[2] = carasoulArray[index][2];
						showWrapper();
						setLoading('spotlight');
						dataObj = "<img src=\""+getImage(item)+"\" width=\"272\" height=\"326\">";
						spotlightObj = spotlight;
						var an=new YAHOO.util.Anim(spotlightObj , {opacity: {to: .5} },0.5);
						an.onComplete.subscribe(showImage);
						an.animate();
                }
            });
        });
    })();

function showImage()// display the preview image
{
	spotlightObj.innerHTML = dataObj;
	new YAHOO.util.Anim(spotlightObj , {opacity: {to: 1} },0.5).animate();
	removeLoading();
	setTimeout("setWrapper();",1000);
}
function setLoading(obj)// set loading display
{
	obj = document.getElementById(obj);
	var region = YAHOO.util.Dom.getRegion('spotlight');
	var objHeight = obj.offsetHeight;
	var objWidth = obj.offsetWidth;
	loadingObj = document.getElementById('loadingObj');
	if(!loadingObj)
	{
		loadingObj = document.createElement("div");
		loadingObj.id = 'loadingObj';
		loadingObj.innerHTML = '<img src="images/loader.gif" />';
		document.body.appendChild(loadingObj);
	}
	loadingObj.style.display = 'block';
	loadingObj.style.position = 'absolute';
	loadingObj.style.top = parseInt(region.top-20)+(objHeight/2)+'px';
	loadingObj.style.left = parseInt(region.left-10)+(objWidth/2)+'px';
}

function removeLoading()// remove the loading object
{
	document.getElementById('loadingObj').style.display = 'none';
}

function preloadImg(src)// preload image
{
	var dummy = new Image();
	dummy.src = src;
}

function showWrapper()// animate the images carousel wrapper 
{
	new YAHOO.util.Anim('spotlight-wrapper' , {bottom: {to: -100} },0.5).animate();
}

function setWrapper()// write the images carousel wrapper and animate
{
	new YAHOO.util.Anim('spotlight-wrapper' , {bottom: {to: 0} },0.5).animate();
	document.getElementById('spotlight-wrapper').innerHTML = '<a href="work.php?Cat='+dataArray[2]+'">'+dataArray[0]+' </a><span>'+dataArray[1]+'</span>';
}

function initCarasoul()// function for initilize the images carousel
{
	carasoulArray = eval('('+responsArray[0]+')');
	if(carasoulArray.length>0)
	{
		setLayout();
		dataArray[0] = carasoulArray[0][0];
		dataArray[1] = carasoulArray[0][1];
		dataArray[2] = carasoulArray[0][2];
		initVal = 1;
	}
}

function setLayout()// Function for fix the layout of thumb images
{
var visibleItem = 12;
var hAlign = 75;
var wAlign = 70;
var k = 1;
var j = -3;
var carouselObj = document.getElementById('carousel');
var liNodes = document.getElementById('carousel').getElementsByTagName('li');
for(i=0;i<liNodes.length;i++)
	{
		if(i>2 && i<33)
		{
				if(i<12)
				{	
					if(i<6)
						k = 1;
					else
						k = 2;
						liNodes[i].style.top = hAlign*k+'px';
						if(i<9)
						liNodes[i].style.left = wAlign*k*j+'px';
				}
				if(i>=12 && i<24)
				{
					if(i<15)
						k = -1;
					else
						k = 1;
					if(i>17 && i<21)
						k = -1;
					if(i<15 || i>20)
						liNodes[i].style.top = hAlign*k+'px';
					else 
						liNodes[i].style.left = wAlign*k*j+'px';
				}
				if(i>=24)
				{
					if(i<30)
						k = -2
						else
						k = -1;
					liNodes[i].style.top = hAlign*k+'px';
					if(i>26)
						liNodes[i].style.left = wAlign*k*j+'px';
				}
		}
			if(i<13)
		{
			preloadImg(liNodes[i].getElementsByTagName("img")[0].src.replace("/featured/","/featured/preview/"));
			preloadImg(liNodes[i].getElementsByTagName("img")[0].src);
		}
	}
}
function loadImages()// function for load images
{
	var liNodes = document.getElementById('carousel').getElementsByTagName('li');
	for(i=12;i<liNodes.length;i++)
	{
		preloadImg(liNodes[i].getElementsByTagName("img")[0].src);
		preloadImg(liNodes[i].getElementsByTagName("img")[0].src.replace("/featured/","/featured/preview/"));
	}	
}

initCarasoul();// call the function for initilize the images  carousel

(function () {
        var testimonial_carousel;
                
        YAHOO.util.Event.onDOMReady(function (ev) {
             testimonial_carousel    = new YAHOO.widget.Carousel('testimonial-container', {
                        animation: { speed: 0.5 }
                });
       		containerWidth = 265;
            testimonial_carousel.render(); // get ready for rendering the widget
            testimonial_carousel.show();   // display the widget


			 testimonial_carousel.on("itemSelected", function (index) {
                // item has the reference to the Carousel's item
             //   item = testimonial_carousel.getElementForItem(index);
              //  if (item) {
					testimonialData[0] = testimonialArray[index][0];
					testimonialData[1] = testimonialArray[index][1];
					var an=new YAHOO.util.Anim('testimonial-detail' , {opacity: {to: 0.3} },0.5);
						an.onComplete.subscribe(writeTestimonialDetails);
						an.animate();
               // }
            });
        });
    })();

var testimonialArray = new Array();/// Array for store testimonial content data
var testimonialData = new Array();/// Array for store only writable data
function initTestimonial()
{
	testimonialArray = eval('('+responsArray[1]+')');
if(testimonialArray.length>0)
	{
		testimonialData[0] = testimonialArray[0][0];
		testimonialData[1] = testimonialArray[0][1];
		writeTestimonialDetails();
	}
}

function writeTestimonialDetails()//// Write the testimonial data from array
{
		document.getElementById('testimonial-detail').innerHTML =testimonialData[0]+'<span>'+testimonialData[1]+' </span>';	
		new YAHOO.util.Anim('testimonial-detail' , {opacity: {to: 1} },0.5).animate();
}
initTestimonial();// call the function for initilize the testimonial carousel
	window.onload = function ()
	{
		document.getElementById('carousel').style.display = 'block';
		document.getElementById('testimonial-container').getElementsByTagName('ol')[0].style.display = 'block';
		setWrapper();//  Dsiplay the wrapper content for preview image
		setTimeout("loadImages();",1000);// Load images of next pages.
	}
