﻿var lastimg = 1;
 var contshow = 1;
 
 
     function contdisp(dispimg)  // Common function to display image on click ..This is the soul Function of code.  
     { 
;
         if(dispimg != lastimg)
         { 
           // Jquery code lines to fade in and fadeout images.
          $('#gal'+lastimg+'').fadeOut(800, function () {
          });
          $('#gal'+dispimg+'').fadeIn(800, function () {
          });
          document.getElementById("thumb"+dispimg).className='select';
          document.getElementById("thumb"+lastimg).className='noselect';    
          document.getElementById("thumb"+dispimg).className='select';
          document.getElementById("thumb"+lastimg).className='noselect';          
        
        
          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();
     } 
     
     
     
     function nextimg() // Function used for next image click
     { 
     
         $('#lastimg').click(function() {
          contshow = 2;
          runimg();
        });
     
     
        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 () {
                });          
                
                document.getElementById("thumb"+( 1)).className='select';
                document.getElementById("thumb"+lastimg).className='noselect';                
                
                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 () {
                        });                        
                        
                        document.getElementById("thumb"+(lastimg + 1)).className='select';
                        document.getElementById("thumb"+lastimg).className='noselect';                        
                        document.getElementById("thumb"+(lastimg + 1)).className='select';
                        document.getElementById("thumb"+lastimg).className='noselect';                        
                        
                    
                        lastimg= lastimg + 1;
                            
                } 
                
                else
                {}
     }
    
    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();
        }); 
        
        if(lastimg == 1)
        { 
                                        
            document.getElementById("thumb"+(id-1)).className='select';
            document.getElementById("thumb"+lastimg).className='noselect';
            // 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)
        {  
        
        document.getElementById("thumb"+(lastimg - 1)).className='select';
        document.getElementById("thumb"+lastimg).className='noselect';
            
            $('#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 () {
            });
            
            document.getElementById("thumb"+(lastimg - 1)).className='select';
            document.getElementById("thumb"+lastimg).className='noselect';
            lastimg= lastimg - 1;
        } 
        else
        {
            
        }
    }
     
    function contdisp1()  // THis function is right now Not use ful.. But can be used to go last and first images
    { 
        if((id-1)!= lastimg)
        {  
            
            document.getElementById("thumb"+(id-1)).className='select';
            document.getElementById("thumb"+lastimg).className='noselect';
            // 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 () {
            });
            document.getElementById("thumb"+(id-1)).className='select';
            document.getElementById("thumb"+lastimg).className='noselect';
            lastimg=id-1;
        } 
        if(lastimg == (id-1))
        {}
    }
     var id = 1;
     var id2 = 1;
     var galid=0;
     var zindexvar=370;
     var contlink ="#";
         $(document).ready(function(){
            $.ajax({
                type: "GET",
                url: "/static/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).animate({opacity: 1.0},1000);
//                            $('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 = "";
                            alert(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('<a href="'+contlink+'" target="_self"><img src="http://www.wppionline.com'+titlela+'" style="z-index:'+galid+';border:5px solid #000000" width="600" height="281" /></a>').appendTo('#slider1');
                            $('<a class="select" href="javascript:contdisp('+id+')" id="thumb'+id+'">'+id+'</a>').html('<img src="/static/structural_images/blank.gif" />').appendTo('#paginate-slider1');
                            }
                            else
                            {
                            $('<div class="contentdiv" id="gal'+id+'" style="display:none;z-index:'+zindexvar+'"></div>').html('<a href="'+contlink+'" target="_self"><img src="http://www.wppionline.com'+titlela+'" style="z-index:'+galid+';border:5px solid #000000"  width="600" height="281" /></a>').appendTo('#slider1');
                            $('<a class="noselect" href="javascript:contdisp('+id+')" id="thumb'+id+'">'+id+'</a>').html('<img src="/static/structural_images/blank.gif" />').appendTo('#paginate-slider1');
                            }
                            id=id+1;
                        }
                        });
                        });
                        });
                        });
                    });
                }
            });
        });
        
    
function defrun()
{ 
    if(contshow==1)
    {
            setInterval( "defrun1()", 4000 );
    }
    
    else if(contshow==2)
    {       
            contshow=1; 
            setInterval( "defrun1()", 0 );
    }
    else
    { }
}
function defrun1()
{  //alert(contshow)
        if(contshow!=0)
        {
               setTimeout("nextimg()",100 );
        }
}
