$j(function(){var timer=7*1000,clicked,play;$j.ajax({type:"GET",url:xmlUrl,dataType:"xml",success:function(xml){var lastOccur=xmlUrl.lastIndexOf('=');var len=xmlUrl.length;var start=parseInt(xmlUrl.substring(lastOccur+1));var titleList=[],descList=[],hrefList=[],photoList=[],videoList=[],videoListmp4=[],shareTitleList=[],shareIconList=[],shareUrlList=[],counter=0;$j('banner',xml).each(function(){var item=$j(this);titleList.push($j('title',item).text());descList.push($j('description',item).text());hrefList.push($j('href',item).text());photoList.push($j('photo',item).text());videoList.push($j('video url',item).text());videoListmp4.push($j('video urlmp4',item).text());$j('#slideshow').append('<img src="'+photoList[counter]+'" alt="img-'+(counter+1)+'" />');$j('.paging ul').append('<li><a href="#" rel="'+(counter+1)+'"></a></li>');$j('.vidbox').append('<video rel="'+(counter+1)+'" id="vid'+(counter+1)+'" class="vids" controls="controls" height="315" width="600" src="'+videoListmp4[counter]+'"><source src="'+videoList[counter]+'" type="video/ogg"></source><source src="'+videoListmp4[counter]+'" type="video/mp4"></source></video>');counter++});shareCounter=0;$j('icon',xml).each(function(){var icon=$j(this);shareTitleList.push($j('title',icon).text());shareIconList.push($j('image',icon).text());shareUrlList.push($j('share_url',icon).text());$j('.share div:nth-child(3) .links').append('<a href="'+shareUrlList[shareCounter]+'"><span class="single_share"><img src="'+shareIconList[shareCounter]+'" alt="share" /><span class="title">'+shareTitleList[shareCounter]+'</span></span></a>');shareCounter++;});activateFirst(titleList,descList,hrefList,start);if(titleList.size()>1){rotateSwitch(titleList,descList,hrefList,videoList,shareTitleList,shareIconList,shareUrlList);}$j(".paging a").click(function(){$active=$j(this);clicked=$active.attr('rel');clearInterval(play);rotate(titleList,descList,hrefList,videoList);if(titleList.size()>1){rotateSwitch(titleList,descList,hrefList,videoList);}return false;});},error:function(XMLHttpRequest,textStatus,errorThrown){}});rotate=function(title,desc,href,video,shareTitle,shareIcon,shareUrl){var curImgNum=$active.attr("rel");var nextImgNum=$active.parent().next().children('a').length?$active.parent().next().children('a').attr("rel"):1;var captioncounter=clicked?clicked-1:curImgNum-1;$j('.playLrg').hide();modalControl(title,desc,href,video,captioncounter);$j(".paging a").removeClass('active');$j(".paging a").parent().removeClass('active');var parent=$active.parent();$active.addClass('active');parent.addClass('active');var curImg=$j('#slideshow img.active-image').length===0?$j('#slideshow img:last'):$j('#slideshow img.active-image');var nextImg;if(clicked){nextImg=$j('#slideshow img:nth-child('+clicked+')')}else{nextImg=curImg.next().length?curImg.next():$j('#slideshow img:first');}
curImg.addClass('last-active').removeClass('active-image');nextImg.css({opacity:0.0}).addClass('active-image').animate({opacity:1.0},500,function(){curImg.removeClass('active-image last-active');});captionLoad(title[captioncounter],desc[captioncounter],href[captioncounter]);var playBtn=function(vidNum){vidNum=vidNum+1;if(video[captioncounter]){$j('.playLrg').show().live('click',function(){clearInterval(play);$j('.vidbox').show();$j('.vidbox').show().css('height','315px');$j('.vidbox #vid'+vidNum).show().css('height','315px');});}};playBtn(captioncounter);$j('.share div:nth-child(3) h2').text(title[captioncounter]);$j('.pause div:last-child h2').text(title[captioncounter]);$j('.pause div:last-child h2').append('<a href="'+href[captioncounter]+'" class="follow_link">Learn More<span class="arrow">></span></a>');clicked=null;}
rotateSwitch=function(title,desc,href,video,shareTitle,shareIcon,shareUrl){play=setInterval(function(){$active=$j('.paging a.active').parent().next().children('a');if($active.length===0){$active=$j('.paging li:first a');}
rotate(title,desc,href,video,shareTitle,shareIcon,shareUrl);},timer);};activateFirst=function(titleList,descList,hrefList,start){var target='_self';$j("#slideshow img:eq("+start+")").addClass("active-image");$j(".paging a:eq("+start+")").addClass("active");$j(".paging li:eq("+start+")").addClass("active");if(hrefList[start].indexOf('www.')>=0||hrefList[start].indexOf('http://')>=0){target='_blank';}
captionTitle=$j('.boxcaption div:last-child h1').html('<a style="color: #FFFFFF;" target="'+target+'" href="'+hrefList[start]+'">'+titleList[start]+'</a>');captionDesc=$j('.boxcaption div:last-child span').html(descList[start]);$j('.boxcaption').stop().animate({height:$j('.boxcaption div:last-child').height()+50+'px'},100,'swing');$j('#slideshow').css('display','none').stop().delay(500).fadeIn(300);};captionLoad=function(title,desc,href){var target='_self';if(href.indexOf('www.')>=0||href.indexOf('http://')>=0){target='_blank';}
$j('.boxcaption div:last-child h1').css('opacity',0).css('display','block').animate({opacity:1},'slow').html('<a style="color: #FFFFFF;" target="'+target+'" href="'+href+'">'+title+'</a>');$j('.boxcaption div:last-child span').css('opacity',0).css('display','block').animate({opacity:1},'slow').html(desc);var contHeight=$j('.boxcaption div:last-child').height()+50+'px';$j('.boxcaption').stop().animate({height:contHeight},100,'swing');};modalControl=function(title,desc,href,video,vidnum){var curVidNum=vidnum+1;$j('.share a.close').bind('click',function(){$j('.share').hide();$j('.pause').show();});$j('.pause a.close').bind('click',function(){$j('.pause').hide();document.getElementById('vid'+curVidNum).play();});$j('.pause .links a:first-child').bind('click',function(){$j('.pause').hide();document.getElementById('vid'+curVidNum).play();});$j('.pause .links a:nth-child(2)').bind('click',function(){$j('.pause').hide();$j('.vidbox').css('height','0px');if(titleList.size()>1){rotateSwitch(title,desc,href,video);}document.getElementById('vid'+curVidNum).load();});$j('.pause .links a:nth-child(3)').bind('click',function(){$j('.pause').hide();$j('.share').show();});onPause=function(){document.getElementById('vid'+curVidNum).pause();$j('.vidbox video').hide();$j('.pause').show();};onPlay=function(){$j('.vidbox video').show();$j('.pause').hide();};onEnded=function(){$j('.vidbox video').hide();$j('.pause').show();};$j('video').attr({'onpause':'onPause()','onended':'onEnded()','onplay':'onPlay()'})};});
