jQuery(document).ready(function(){
    jQuery('.sidebar-item').find('object').wrap('<div class="video_class"></div>') ;
    
    if(jQuery('.commentlist > li').size()){
        jQuery('.commentlist > li').each(function(x){
            if(x % 2 == 0){
                jQuery(this).addClass('comContent').addClass('comm_1')
            } 
            else{
                jQuery(this).addClass('comContent').addClass('comm_2')
            }   
        })
    }
    
    if(jQuery('#fw_tabs_tabs_surround_1').size()){
        jQuery('#fw_tabs_tabs_surround_1').wrap('<div class="sidebar-item"></div>')
    }
    /*----------------------------------- survey --------------------------------------*/
    if(jQuery('#surverSub').size()){
        jQuery('#surverSub').click(function(){
            /*------------------- captcha check -----------------*/
            checkCaptcha = false; 
            jQuery.post('session.php',{},
            function(data){
                if(jQuery('#secure').val()){
                    if(jQuery('#secure').val() == data){
                        checkCaptcha = true;
                    }
                    else{
                        jQuery('#secure').css({
                            background:'red'
                        })
                    }
                }      
            })             
            

            checkForm = true;
            jQuery('.required').each(function(){                 
                if(!jQuery(this).val()){
                    checkForm = false;
                    jQuery(this).css({
                        background:'red'
                    }) 
                }
            })
            .focus(function(){
                jQuery(this).css({
                    background:'white' 
                })
            })
            /*---------- check form ------------*/
            if(checkForm && checkCaptcha)
                jQuery('#formSurvey').submit();
        })
        
        jQuery('.q2').click(function(){
            if(jQuery(this).val() == 'no'){
                jQuery('.trClass').removeClass('hideMe');
            }
            else{
                jQuery('.trClass').addClass('hideMe');
            }
        })
        jQuery('.q3').click(function(){
            if(jQuery(this).val() == 'no'){
                jQuery('.trQ4').addClass('hideMe');
            }
            else{
                jQuery('.trQ4').removeClass('hideMe');
            }   
        })        
    }
    /*--------------- gallery --------------*/
    if(jQuery('#gallery-1').size()){
        checkNum = true;
        picPerView = 0
        jQuery('#gallery-1 > *').each(function(x){
            if(jQuery(this)[0].tagName == 'br' || jQuery(this)[0].tagName == 'BR' || jQuery(this)[0].tagName == 'p' || jQuery(this)[0].tagName == 'P' && checkNum){
                picPerView = x;
                checkNum = false;            
            }
        }) 

        picCount = 3 * picPerView;
        wrapCount = 0;
        if(jQuery('#gallery-1 > dl').size() > picCount){
            
            wrapCount = Math.ceil(jQuery('#gallery-1 > dl').size() / picCount);
            jQuery('#gallery-1').append('<div id="picWrapper">');
            for(i=1; i<=wrapCount; i++){
                                        
                jQuery('#picWrapper').append('<div class="picContent" id="wrap'+i+'"></div>');
            }                
        
        /*------------------- get initial pic number --------------------*/
                           
            tagDlWidth = Math.floor(jQuery('#gallery-1').width() / picPerView) ;
            jQuery('.gallery-item').css({
                width: tagDlWidth-2+'px'
            })
            
            jQuery('#gallery-1').css({
                position: 'relative',
                overflow: 'hidden',
                height: '544px'
            })
            
            jQuery('#picWrapper').css({
                width: jQuery('#gallery-1').width() * wrapCount+'px',
                position: 'absolute'
            })
            jQuery('.picContent').css({
                width: jQuery('#gallery-1').width()+'px'
            })
            
            wrapId = 1
            dev = Math.ceil(picCount / picPerView);
            
            pic = picCount+dev;
            jQuery('#gallery-1 > *').each(function(x){  
                    
                if(x < pic){
                    if(jQuery(this)[0].tagName != 'DIV' && jQuery(this)[0].tagName != 'div')
                        jQuery('#wrap'+wrapId).append(jQuery(this));
                }           
                else{
                    wrapId += 1;
                    pic += picCount+dev;
                    if(jQuery(this)[0].tagName != 'DIV' && jQuery(this)[0].tagName != 'div')
                        jQuery('#wrap'+wrapId).append(jQuery(this));
                }
            })
            jQuery('#gallery-1').append('<div id="nxtPrv"><span class="picButton">next</span> <span class="picButton">prev</span><br style="clear:both" ></div>')
       
       
            clickMe = true;
            jQuery('.picButton').click(function(){            
                task = jQuery(this).html();
                pos = jQuery('#picWrapper').position().left;
                galWid = jQuery('#gallery-1').width();  
             
                if(clickMe){
                    clickMe = false;
                    switch(task){
                        case 'next':
                            if(Math.abs(pos - galWid) < jQuery('#gallery-1').width() * wrapCount){
                                jQuery('#picWrapper').animate({
                                    left: pos - galWid+'px'
                                },function(){
                                    clickMe = true;
                                })
                            }
                            else{
                                clickMe = true;    
                            }
                        break;
                        case 'prev':  
                            if(pos + galWid <= 0){
                                jQuery('#picWrapper').animate({
                                    left: pos + galWid+'px'
                                },function(){
                                    clickMe = true;        
                                })
                            }
                            else{
                                clickMe = true;
                            }
                        break;
                    }
                }                 
            })
        }
    }
    
    /*----------------------- right click ---------------------*/
    
    var menu1 = [ 
         {'Home':function(menuItem,menu) 
            { window.location = 'index.php' } 
         },
         $.contextMenu.separator, 
         {'Refresh':function(menuItem,menu)
            { window.location = window.location }
         },
         $.contextMenu.separator, 
         {'About':function(menuItem,menu)
            { alert("Site Maintained and Owned by Justin Yong"); }
         }  
    ];     

    //$(document).contextMenu(menu1,{theme:'vista'}); 
    
    /*------------------ page hidden ------------------*/ 
    if($('#nav').size()){
        $('#nav').show();
        $('#pixopoint_menu1 > ul').find('span').each(function(){
            $(this).parent().parent().detach(); 
        })        
    }
    
    /*--------------- landing page survey ----------------*/
    if($('#lpSub').size()){
        $('#lpSub').click(function(){
            checkForm = true;
            jQuery('.required').each(function(){                 
                if(!jQuery(this).val()){
                    checkForm = false;
                    jQuery(this).css({
                        background:'red'
                    }) 
                }
            })
            .focus(function(){
                jQuery(this).css({
                    background:'white',
                    border: '2px ridge PowderBlue ' 
                })
            })  
            if(checkForm){
                $('#LPage').submit();
            }      
        })
    }
    
    /*----------------- dropdown -------------------*/
    $('#suckerfishnav').append('<br class="clear">')
    $('#suckerfishnav li').each(function(x){
        if(x == 0){
            $(this).css({
                marginRight: '4px'
            })
        }    
    })
    $('#suckerfishnav > li > ul').hide().css({
        background : '#E0E1EF',
        border : '3px solid #3389EC',
        height: 'auto'
    })
    $('#suckerfishnav > li > ul > li').hover(
        function(){
            $(this).find('a').addClass('liHover') 
            $(this).addClass('liHover') 
        },
        function(){
            $(this).find('a').removeClass('liHover') 
            $(this).removeClass('liHover') 
        }
    )
    liHeight = $('.current_page_item > a').innerHeight()

    $('#suckerfishnav > li').hover(
        function(){
            if($(this).find('ul').size()){
                pos = $(this).position();        
                $(this).find('ul').css({
                    top : '336px',
                    left : pos.left + 'px',
                    position : 'absolute'
                })
                .slideDown('fast')
                .addClass('selUl')
                  
                $(this).find('ul').find('a').css({
                    background : '#E0E1EF',
                    color : '#604417'
                })
                
            }
        },
        function(){
             $(this).find('ul').slideUp('fast')
             
               
        }
    )
    
    $.post('thumb/Thumb.php');
    
    /*----------------- Google compliant page ------------------*/

    if($('#LPmore').size()){
        $('#LPmore').click(function(){
            if($(this).hasClass('off')){
                $('#LPmoreContent').slideDown();
                $(this).removeClass('off').addClass('on');
            }
            else{
                $('#LPmoreContent').slideUp();
                $(this).removeClass('on').addClass('off');                
            }
        })
    }	
})