﻿var lastimg = 1;
 var contshow = 1;
 
 
     function contdisp(dispimg)  // Common function to display image on click ..This is the soul Function of code.  
     { 
;
         $('div.outercont').addClass('fading').fadeOut(200).animate({borderLeftWidth: "1px"},200);
         if(dispimg != lastimg)
         { 
        //alert("contdisp")
           // Jquery code lines to fade in and fadeout images.
          $('#gal'+lastimg+'').fadeOut(800, function () {
          });
          $('#gal'+dispimg+'').fadeIn(800, function () {
          });
          document.getElementById("conthead_"+lastimg).style.display='none';
          document.getElementById("contp_"+lastimg).style.display='none';    
          
           $('div.outercont').addClass('fading').fadeOut().slideDown('slow');                                                
         $('div.outercont.fading').css('filter', 'alpha(opacity=40)'); 
         $('#conthead_'+dispimg).show();
         $('#contp_'+dispimg).show();
          lastimg=dispimg; 
          }
          
         if(lastimg == 1) // In Case of we are displaying very first image
         {}     
         if(lastimg == (id-1)) // In Case of we are displaying very last image
         {}
          contshow = 2;
          runimg();
         $('div.outercont.fading').hide();
     } 
     
     
     
     function nextimg() // Function used for next image click
     { 
     
         $('#lastimg').click(function() {
          contshow = 2;
          runimg();
        });
     
        $('div.outercont').addClass('fading').fadeOut(200);
     
        if(lastimg == (id-1))
            { 
             // Jquery code lines to fade in and fadeout images.
                $('#gal'+lastimg+'').fadeOut(800, function () {         
                });
                $('#gal'+(1)+'').fadeIn(800, function () {        
                });
                $('#gal'+lastimg+'').fadeOut(800, function () {
                });
                $('#gal'+(1)+'').fadeIn(800, function () {
                });      
                $('#gal'+lastimg+'').fadeOut(800, function () {
                });
                $('#gal'+(1)+'').fadeIn(800, function () {
                });          
                
                $('div.outercont').addClass('fading').slideDown('slow').animate({opacity: 1.0}, 3000);                                                
                document.getElementById("conthead_"+lastimg).style.display='none';    
                document.getElementById("contp_"+lastimg).style.display='none';    
                $('#conthead_'+(1)).fadeIn(800);
                $('#contp_'+(1)).fadeIn(800);
                lastimg = 1;
                }
                         
                else if((id-1) != lastimg)
                {  
                         // Jquery code lines to fade in and fadeout images.
                        
                        $('#gal'+lastimg+'').fadeOut(800, function () {
                        });
                        $('#gal'+(lastimg + 1)+'').fadeIn(800, function () {
                        });
                        $('#gal'+lastimg+'').fadeOut(800, function () {
                        });
                        $('#gal'+(lastimg + 1)+'').fadeIn(800, function () {
                        });      
                        $('#gal'+lastimg+'').fadeOut(800, function () {
                        });
                        $('#gal'+(lastimg + 1)+'').fadeIn(800, function () {
                        });                        
                        
                        $('div.outercont').addClass('fading').slideDown('slow');                                            
                        document.getElementById("conthead_"+lastimg).style.display='none';    
                        $('#conthead_'+(lastimg + 1)+'').fadeIn(800);
                        document.getElementById("contp_"+lastimg).style.display='none';    
                        $('#contp_'+(lastimg + 1)+'').fadeIn(800);                    
                        lastimg= lastimg + 1;
                            
                } 
                
                else
                {}
                 $('div.outercont.fading').hide();        
     }
    
    function runimg() // Function used for previous image click
    { 
         if(contshow ==1)
         {  
             document.getElementById("runimg").className='runimg';
            contshow = 0;
         }
            
         else if(contshow ==0)
         {
             document.getElementById("runimg").className='stopimg';
            nextimg();
            contshow = 2;
            //alert("2")
         } 
         else if(contshow ==2)
         {
             document.getElementById("runimg").className='runimg';
            contshow = 0;
         }
         else{
             }
        
    } 
    function previmg() // Function used for previous image click
    { 
        $('#firstimg').click(function() {
        
          contshow = 2;
          runimg();
        }); 
        
        $('div.outercont').addClass('fading').fadeOut(200).animate({borderLeftWidth: "1px"},1000);         
        if(lastimg == 1)
        { 
            $('div.outercont.fading').slideDown('slow').animate({borderLeftWidth: "1px"},1000);                                        
            $('#conthead_'+(id-1)).fadeIn(800).animate({borderLeftWidth: "1px"},1000);
            $('#contp_'+(id-1)).fadeIn(800);
            document.getElementById("conthead_"+lastimg).style.display='none';                        
            document.getElementById("contp_"+lastimg).style.display='none';                        
            // Jquery code lines to fade in and fadeout images.
            $('#gal'+lastimg+'').fadeOut(800, function () {
            });
            $('#gal'+(id-1)+'').fadeIn(800, function () {
            });
            $('#gal'+lastimg+'').fadeOut(800, function () {
            });
            $('#gal'+(id-1)+'').fadeIn(800, function () {
            });      
            $('#gal'+lastimg+'').fadeOut(800, function () {
            });
            $('#gal'+(id-1)+'').fadeIn(800, function () {
            });
            lastimg= (id-1);
        }
        else if( lastimg!= 1)
        {  
        $('div.outercont.fading').slideDown('slow').animate({borderLeftWidth: "1px"},1000);                                                
        $('#conthead_'+(lastimg - 1)).fadeIn(800).animate({borderLeftWidth: "1px"},1000);
        $('#contp_'+(lastimg - 1)).fadeIn(800);
        document.getElementById("conthead_"+lastimg).style.display='none';    
        document.getElementById("contp_"+lastimg).style.display='none';                                    
            $('#gal'+lastimg+'').fadeOut(800, function () {
            });
            $('#gal'+(lastimg - 1)+'').fadeIn(800, function () {
            });
            $('#gal'+lastimg+'').fadeOut(800, function () {
            });
            $('#gal'+(lastimg - 1)+'').fadeIn(800, function () {
            });      
            $('#gal'+lastimg+'').fadeOut(800, function () {
            });
            $('#gal'+(lastimg - 1)+'').fadeIn(800, function () {
            });
            
            lastimg= lastimg - 1;
        } 
        else
        {
            
        }
         $('div.outercont.fading').hide();
    }
     
    function contdisp1()  // THis function is right now Not use ful.. But can be used to go last and first images
    { 
     $('div.outercont').addClass('fading').fadeOut('slow');
        if((id-1)!= lastimg)
        {  
            
            $('div.outercont.fading').slideDown('slow');                                                
            
            $('#conthead_'+(id-1)).fadeIn(800);
            document.getElementById("conthead_"+lastimg).style.display='none';    
            // Jquery code lines to fade in and fadeout images.
            $('#gal'+lastimg+'').fadeOut(800, function () {
            });
            $('#gal'+(id-1)+'').fadeIn(800, function () {
            });
            $('#gal'+lastimg+'').fadeOut(800, function () {
            });
            $('#gal'+(id-1)+'').fadeIn(800, function () {
            });      
            $('#gal'+lastimg+'').fadeOut(800, function () {
            });
            $('#gal'+(id-1)+'').fadeIn(800, function () {
            });
            lastimg=id-1;
        } 
        if(lastimg == (id-1))
        {}
    }
     var id = 1;
     var id2 = 1;
     var galid=0;
     var zindexvar=370;
     var contlink ="#";
     var visited = false;
         $(document).ready(function(){
            $.ajax({
                type: "GET",
                url: "/hospitalitydesign/mediakit/mediakit-rotator.xml",
                dataType: "xml",
                success: function(xml) {
                    $(xml).find('SEARCH_RESULTS').each(function(){
    
                    //alert(1)
                     $(this).find('CLOB').each(function(){
                     
                    //alert(2) 
                        $(this).find('ARTICLE').each(function(){
                        var conthead = $(this).find('HEADLINE').text();    
                        var contdetail = $(this).find('ABSTRACT').text();
                        contlink = $(this).find('DISPLAY_URL').text();  
                
                        
                        if(id2==1)
                        {            
                            $('div.outercont').addClass('fading').fadeOut(200).slideDown(1000).animate({borderLeftWidth: "1px"},2000);
                            $('<span class="yllow-cntnt" id="conthead_'+id+'"></span>').html('<a href="'+contlink+'" target="_self">'+conthead+'</a>').appendTo('#conthead').text();
                            $('<p id="contp_'+id+'"></p>').html(contdetail).appendTo('#contdetail').text();
                            id2++;
                        }
                        else
                        {        
                            $('<span class="yllow-cntnt" id="conthead_'+id+'" style="display:none"></span>').html('<a href="'+contlink+'" target="_self">'+conthead+'</a>').appendTo('#conthead').html();
                            $('<p id="contp_'+id+'" style="display:none"></p>').html(contdetail).appendTo('#contdetail').html();    
                            id2++;
                        }
                        });    

                      $(this).find('ARTICLE_EXTRA').each(function(){
                    //alert(3)
                       $(this).find('PHOTOS').each(function(){ 
                    //alert(4)
                       $(this).find('PHOTO').each(function(){
                    //alert(5)
                        var title = $(this).find('SMALL_PHOTO_LINK').text();
                        var titlela = $(this).find('LARGE_PHOTO_LINK').text();
                        var photocap = $(this).find('PHOTO_NAME').text();
                        
                        if ($(this).find('PHOTO_NAME').text() == "()") {
                            photocap = "";
                            
                            }
                        
                         
                        if(id < 19)
                        {
                            galid=galid+id;
                            zindexvar= zindexvar+id; 
                        
                            if(galid==1 )
                            {
                            $('<div class="contentdiv" id="gal'+id+'" style="display:block;z-index:'+zindexvar+'"></div>').html('<img src="http://www.hospitalitydesign.com'+titlela+'" style="z-index:'+galid+';" width="660" height="300" />').appendTo('#slider1');
                            }
                            else
                            {
                            $('<div class="contentdiv" id="gal'+id+'" style="display:none;z-index:'+zindexvar+'"></div>').html('<img src="http://www.hospitalitydesign.com'+titlela+'" style="z-index:'+galid+';"  width="660" height="300" />').appendTo('#slider1');
                            }
                            id=id+1;
                        }
                        });
                        });
                        });
                        });
                    });
                }
            });
        });
        
    
function defrun()
{ 
    if(contshow==1)
    {
            setInterval( "defrun1()", 5000 );
    }
    
    else if(contshow==2)
    {       
            contshow=1; 
            setInterval( "defrun1()", 0 );
    }
    else
    { }
}
function defrun1()
{  //alert(contshow)
        if(contshow!=0)
        {
               setTimeout("nextimg()",100 );
        }
}
