// Jquery script for rating 
$(document).ready(function() {

    $("[id^=rating_]").hover(function() {


        rid = $(this).attr("id").split("_")[1];
        $("#rating_"+rid).children("[class^=star_]").children('img').hover(function() {

            $("#rating_"+rid).children("[class^=star_]").children('img').removeClass("hover");

            /* The hovered item number */
            var hovered = $(this).parent().attr("class").split("_")[1];
    
            while(hovered > 0) {
                $("#rating_"+rid).children(".star_"+hovered).children('img').addClass("hover");
                hovered--;
            }

        });
    });

    $("[id^=rating_]").children("[class^=star_]").click(function() {        
        var current_star = $(this).attr("class").split("_")[1];
        var rid = $(this).parent().attr("id").split("_")[1];
        $('.star_rating').html('(Rated <strong>'+ current_star +'</strong> Stars)');
        $('#rating_'+rid).load('send.php', {rating: current_star, id: rid});
        
    });
});

$(document).ready(function(){
    $("#footer-right li:last-child").css("border-right","none");                       
})

function hovering(id){
    document.getElementById(id).src = 'images/btn_hover.png';
}

function normal_state(id){
    document.getElementById(id).src = 'images/go_btn.png';
}


$(document).ready(function(){        
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

    if(sPage=='index.php' || sPage == '')
    {
        var color         = $.cookie("color");
        var aTag         = $.cookie("a_color");
        var bColor         = $.cookie("b_color");
        var bgImage     = $.cookie("bg");
        var logoBG         = $.cookie("logo");
        var logoSml     = $.cookie("logoSml");
        var loginIcon     = $.cookie('loginIcon');
        
        var bgHeight     = $.cookie("bg_h");
        var bgWidth     = $.cookie("bg_w");
        
                
        if(bgImage){
            myPath = "images/bg_img/large/" + bgImage;
            myUrl = "url("+ myPath +")";
            $("body").css("background-image",myUrl);
            
            if(bgImage == '024.jpg'){
                $("#top a").css('color','#000000');
            }else{
                $("#top a").css('color','#ffffff');
            }
            
            $("#footer-menu li a").css("color",'#' + aTag);
            $('#top .login a').not('.member').css('background-image','url('+ loginIcon +')');
            $('#f-wrapper #footer-right ul li').css('border-right','1px solid #' + bColor);
            $('#f-wrapper #footer-right ul li:last-child').css('border-right','none');
            $('#n-logo a img').attr('src',logoBG);
            $('#footer-left img').attr('src',logoSml);
            
        }else{
            $("body").css("background-image",'none');
            
            if(bgWidth != null){
                $("body").css("width",bgWidth+'px');    
                
            }
            
            if(bgHeight != null){
                $("body").css("height",bgHeight+'px');    
            }
            
            $("#top a").css("color",'#62676D');
            $('#n-logo a img').attr('src','images/nixxie_logo_png.png');
            $('#footer-left img').attr('src','images/img_nixxie_logo_footer.png');
            $("body").css("background-image",'none');
            
            if(color != null){
                $("body").css("background-color",'#'+color);
                $("body").css("overflow",'hidden');
            }
        }
    }//
})

// script to set as homepage

function setHomepage()
{
 if(document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
          document.body.setHomePage(this.location);
    }
    else if (window.sidebar)
    {
        if(window.netscape)
        {
             try
             {  
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
             }  
             catch(e)  
             {  
                tb_show("Set as homepage - Not available","includes/js_message.php?height=200&width=300");
             }
        } 
        
       var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
       prefs.setCharPref('browser.startup.homepage','http://www.asp.net/130.aspx');
   }
   else
   {
        tb_show("Set as homepage - Not available","includes/js_message.php?height=200&width=300");
   }
}

//function bookmark

function bookmark() {
    title = "Nixxie Search Engine";
    url = this.location;
    if (window.sidebar) {
        // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    } else if( document.all ) {
        // IE Favorite
        window.external.AddFavorite( url, title);
    }
    else if(window.opera && window.print) {
        var b = document.getElementById('book');
        b.setAttribute('href',url);
        b.setAttribute('title',title);
        b.setAttribute('rel','sidebar');

        
    }
    else{
        tb_show("Bookmark Page - Not available","includes/js_message.php?height=100&width=300");    
    }
}

function bookmark_human() {
    title = "Nixxie Search Engine";
    host=this.location.host;
    pre_url = this.location.pathname;
    url="http://"+host+pre_url ;
    if (window.sidebar) {
        // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    } else if( document.all ) {
        // IE Favorite
        window.external.AddFavorite( url, title);
    }
    else if(window.opera && window.print) {
        var b = document.getElementById('book');
        b.setAttribute('href',url);
        b.setAttribute('title',title);
        b.setAttribute('rel','sidebar');

        
    }
    else{
        tb_show("Bookmark Page - Not available","includes/js_message.php?height=100&width=300");    
    }
}

function jump_to_menu(page){
    var myOption = document.getElementById('jump');
    
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

    location.href = sPage + '?page='+ page +'&current_page=' + myOption.value;
}

function filter_by(id){
    var myOption = document.getElementById(id);
    
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

    location.href = sPage + '?page=reviews&status=' + myOption.value;
}


function checkall(){

        for(i=0;i < document.post_form['reviews[]'].length;i++){
            if(document.post_form.check_all.checked == true)
                document.post_form['reviews[]'][i].checked = 'checked';
            else
                document.post_form['reviews[]'][i].checked = false;
        }
}


jQuery(document).ready(function(){
                                
    jQuery("#bottom_search").click(function(){
        
        var keyword = jQuery("#the_keyword").val();
        var sPath = window.location.pathname;
        var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
        
        if(sPage=="search.php")
        mode="web";
        else if(sPage=="search_image.php")
        mode="image";
        else if(sPage=="search_human.php")
        mode="human";
        else 
        mode="web";
        if(keyword !="")
        location.href = sPage + '?keyword='+keyword+'&search='+mode ;                                     
                                             
                                             
                                             });
    
    //function to implement
    jQuery("#sub-buttons a").each(function(i){
                                         
                                     
            $(this).bind("click",function() {
                        
                        
                deselect_home(i)
                $(this).css("background-image","url(images/tab_over_1.png)");    
                mylink=$(this).html();
                
                if(mylink=="Web")
                {
                $("#mainform").attr("action","search.php");
                $('input[name="search"]').val('web');
                }
                //answers
                else  if(mylink=="Answers")
                {
                    var myVal = $('#searchdata').val();
					 var domain = $('input[name="domain"]').val();
                    if(myVal == ''){
						
						if(domain=='http://dev.nixxie-search.com/')
						{
						  document.location = "http://answersdev.nixxie.com";	
						}
						else
                        document.location = "http://answers.nixxie.com";
                        return false;
                    }else{
                        if(domain=='http://dev.nixxie-search.com/')
						{
						  
						   $("#mainform").attr("action","http://answersdev.nixxie.com/askquery.php?keyword="+myVal+"&search=nse");
						}
						else
                        $("#mainform").attr("action","http://answers.nixxie.com/askquery.php?keyword="+myVal+"&search=nse");
                    }
                $('input[name="search"]').val('nse');
                }
                
                 else  if(mylink=="Shopping")
                {
                    var myVal = $('#searchdata').val();
					 var domain = $('input[name="domain"]').val();
                    if(myVal == ''){
                        if(domain=='http://dev.nixxie-search.com/')
			    document.location = "http://shoppingdev.nixxie.com/";	
			else
                            document.location = "http://shopping.nixxie.com/";
                        return false;
                    }else{
                        if(domain=='http://dev.nixxie-search.com/')
						document.location = "http://shoppingdev.nixxie.com/"+myVal+"/co-ca-3.html";						
						else
						document.location = "http://shopping.nixxie.com/"+myVal+"/co-ca-3.html";                    
						}
					return false;
                }
                else if(mylink=="Human")
                {
                
                $("#mainform").attr("action","search_human.php");
                $('input[name="search"]').val('human');
                
                }
                else 
                {
                
                $("#mainform").attr("action","search.php");
                $('input[name="search"]').val('web');
                }
            
                $("#mainform").submit();                          
     });
    
    
    
})
    //landing pages button section
    //landing pages button section
    jQuery(".menu_container a").each(function(i){
                                         
                                     
            $(".menu_container a").bind("click",function() {
                        
                        
                deselect_tab(i)
                $(this).css("background-image","url(images/tab_on_1.png)");    
                mylink=$(this).html();
                if(mylink=="Web")
                {
                    $("#mainform").attr("action","search.php");
                    $('input[name="search"]').val('web');
                }
                else if(mylink=="Blog")
                {
                
                $("#mainform").attr("action","search_blog.php");
                $('input[name="search"]').val('blogs');
                }
                else if(mylink=="Human")
                {
                
                $("#mainform").attr("action","search_human.php");
                $('input[name="search"]').val('human');
                
                }
                else 
                {
                
                $("#mainform").attr("action","search.php");
                    $('input[name="search"]').val('web');
                }
            
                $("#mainform").submit();                                                   
         }); 
    });
});

function deselect_tab(i){
    jQuery(".menu_container a").each(function(j){
    if(i!=j)        
    $(this).css("background-image","url(images/tab_off_1.png)").removeClass('selected');
    
                                          
     });
}

function deselect(i){
    jQuery(".menu_container a").each(function(j){
    if(i!=j)        
    $(this).css("background-image","url(images/tab_off_1.png)");
                                          
     });
    
    
    

    
}
function deselect_home(i){
    
    jQuery("#sub-buttons a").each(function(j){
                                  
    if(i!=j)        
    $(this).css("background-image","url(images/tab_off_1.png)").removeClass('selected');
                                          
     });
    
    
    

    
}

